‎2004 Oct 29 1:37 PM
Is there any function modules which on passing YEAR as parmeter gives us whether it a leap year or not?
‎2004 Oct 29 2:03 PM
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.
‎2004 Oct 29 2:47 PM
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.
‎2004 Oct 29 4:54 PM
Hi,
You can use FM NUMBER_OF_DAYS_PER_MONTH_GET by passing '02' as month and YEAR.
Regards
Venkat
‎2004 Oct 31 6:19 PM
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
‎2004 Nov 01 2:58 PM
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.