Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Leap year

Former Member
0 Likes
969

Is there any function modules which on passing YEAR as parmeter gives us whether it a leap year or not?

5 REPLIES 5
Read only

Former Member
0 Likes
911

Hi Sachin,

FM DATE_CHECK_PLAUSIBILITY will check if a date is valid. You can either use this FM to check 28.02.xxxx for a given year, or copy the piece of coding which checks for a leap year.

Regards,

John.

Read only

0 Likes
911

I shall just correct that <b>28.02.XXXX</b> to <b>29.02.XXXX</b>, but that is a great tip, John.

Never occured to me, of using FM <b>DATE_CHECK_PLAUSIBILITY</b>, this way.

Regards,

Subramanian V.

Read only

0 Likes
911

Hi,

You can use FM NUMBER_OF_DAYS_PER_MONTH_GET by passing '02' as month and YEAR.

Regards

Venkat

Read only

Former Member
0 Likes
911

Hi Sachin,

I'm not sure if sap delivers such a function module but writing one yourself should be quite easy.

Posibility one: implement the correct algorithm

leap years are years which can be divided by 4 (e.g. 2004) but are no centuries (e.g. 1900). But years which can be devided by 400 are leap years although they are centuries (e.g. 2000 was a leap year).

Posibility two: try the following (bases on the fact that sap can calculates the leap years correct in the date datatype)

- define a function module

- importing parameter iv_year (NUMC 4)

- exporting parameter ef_leap_year (CHAR 1)

- coding

data:

lv_date like sy-datum value '00000228'.

lv_date(4) = iv_year. " set the year to the date

ADD 1 TO lv_date. " calculate the next day

IF lv_date+4(4) EQ '0229'. " get the MMDD part of date

ef_leap_year = 'X'. " yes it is a leap year

ELSE.

ef_leap_year = ''. " no it is not a leap year

ENDIF.

kind regards.

Roman

Read only

0 Likes
911

For this calculation you could generally simplify the equation to, is the year divisible by 4. Forward planning to the year 2100 is nonsense. And any date before 1st march 1900 is fixed and probably only useful for asset management.