There are standard ways to determine the last date of a given month and year in ABAP, such as:
- Class / Method: CL_FITV_UTIL=>LAST_DAY_OF_MONTH
- Function Module: LAST_DAY_OF_MONTHS
See the sample code below:
DATA:
lv_month TYPE n LENGTH 2 VALUE '02',
lv_year TYPE n LENGTH 4 VALUE '2025'.
DATA:
lv_new_month TYPE n LENGTH 2,
lv_new_year TYPE n LENGTH 4,
lv_date TYPE d.
lv_new_month = lv_month + 1.
IF lv_new_month = 13.
lv_new_month = 1.
lv_new_year = lv_year + 1.
ELSE.
lv_new_year = lv_year.
ENDIF.
lv_date = |{ lv_new_year }{ lv_new_month }01|.
lv_date = lv_date - 1.
WRITE: / lv_date.