ABAP – Getting difference between the dates in days, weeks, years

To get the difference between two dates we can use the FM  HR_CALC_YEAR_MONTH_DAY.

 

DATA: l_years_out(2) type n,
l_months_out(2) type n,
l_days_out(2) type n.

CALL FUNCTION ‘HR_CALC_YEAR_MONTH_DAY’
EXPORTING
BEGDA            = ‘20130631’
ENDDA            = ‘20180705’
IMPORTING
YEARS_OUT        = l_years_out
MONTHS_OUT       = l_months_out
DAYS_OUT         = l_days_out
.

IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

write: l_years_out, l_months_out, l_days_out.

 

Output:

05 01 00

Means the difference between two dates is 5 years 0 months 4 days

0 Comments

Leave A Reply