Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Checking for a leap year.

To check for a leap year we can write just write a very simple code.

parameters :  p_date like sy-datum.

data w_date like p_date.

w_date = p_date.

w_date+4(2) = '02'.

w_date+6(2) = '28'.

add 1 to w_date.

if w_date+4(2) = p_date+4(2).

  write 'Its a leap year'.

else.

  write 'Its not a leap year'.

endif.

once we add 1 to date which is 28th feb of the year. if its a leap year then the month remains the same only the day changes from 28 to 29. if its not a leap year then the date is 1st march, where the month is changed.

Isn't it this simple.

2nd way to achive the same result:

Paramters: W_date type sy-datum.

Perform Leap_Year_Check.

 **********FORM ROUTINE**********

Form Leap_Year_Check.

Data: w_date1 type sy-datum,

         w_int type i.

w_date+4(4) = '0201'.

w_date1 = w_date.

w_date1+4(2) = '03'.

w_i = w_date1 - w_date.

IF w_i = 29.

write: ' leap year'.

else,

 write: 'Not a  leap year'.

ENDFORM.

  • No labels