ABAP – Getting last day of a month

To get the last day of a month we can use the functional module RP_LAST_DAY_OF_MONTHS.

DATA: V_DATE LIKE SY-DATUM.

CALL FUNCTION ‘RP_LAST_DAY_OF_MONTHS’
EXPORTING
DAY_IN                  = sy-datum
IMPORTING
LAST_DAY_OF_MONTH       = V_DATE
EXCEPTIONS
DAY_IN_NO_DATE          = 1
OTHERS                  = 2
.
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: ‘Last day is’, V_DATE+6(2).

 

Output will display the last day of the month.

If sy-datum is: 07- march -2013 then Output  is as follows:

Last day is 31

0 Comments

Leave A Reply