Calculate Leap Year in ABAP
How can I determine whether a
year is a leap year or not? (year 2004, 2008 etc.)
In ABAP it would be quite easy as
you can calculate with dates!
Code:
DATA: mydate TYPE d.
mydate = '20040301'.
mydate = mydate - 1.
IF mydate+6(2) = '29'.
WRITE 'A leap year'.
ELSE.
WRITE 'No leap year'.
ENDIF.
You see the function module ' LEAP_DAYS_BETWEEN_TWO_DATES'
or FIMA_LEAP_DAYS_BETWEEN_2_DATES.
This function module also using
the same logic.
see the code..below..
Code:
FUNCTION FIMA_LEAP_DAYS_BETWEEN_2_DATES.
*"-------*"
VALUE(I_DATUM_VON) LIKE VTBBEWE-DBERVON
*"
EXPORTING
*"
VALUE(E_TAGE)
*"----------------------------------------------------------------------
STATICS: JAHR
TYPE I,
TAGE_VON TYPE I,
TAGE_BIS TYPE I.
*___ Schalttage für das Datum-von
____________________________________*
IF I_DATUM_VON+4(2) <
CON_MARCH.
JAHR = I_DATUM_VON+0(4)
- 1.
ELSE.
JAHR = I_DATUM_VON+0(4).
ENDIF.
TAGE_VON = JAHR DIV 4 - JAHR
DIV 100 + JAHR DIV 400.
*___ Schalttage für das Datum-bis
____________________________________*
IF I_DATUM_BIS+4(2) <
CON_MARCH.
JAHR = I_DATUM_BIS+0(4)
- 1.
ELSE.
JAHR = I_DATUM_BIS+0(4).
ENDIF.
[b]
TAGE_BIS = JAHR DIV 4 -
JAHR DIV 100 + JAHR DIV 400.[/b]
*___ Schalttage zwischen Datum-von
und Datum-bis _____________________*
E_TAGE = TAGE_BIS - TAGE_VON.
ENDFUNCTION.
More Function Module
Functions /
SAP Script / ALV
Tables
Database Table
ABAP Books List
ABAP/4 Certification,
Programming, Smartforms, Sapscripts and Object Oriented Programming Books
Smart Forms
SAP Smartforms
ABAP Menu:
ABAP Example Hints
and Tips
Return to Index:-
SAP ABAP/4 Programming,
Basis Administration, Configuration Hints and Tips
(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies. The site www.gotothings.com is in no way affiliated with
SAP AG.
Any unauthorised copying or mirroring is prohibited.
|