We want to fill the two selection screen fields p_fromdate and p_todate with the first and last date of the previous month.
DATA:
l_monthn(2) TYPE n,
l_yearn(4) TYPE n.
* Find current month and year
MOVE sy-datum+4(2) TO l_monthn.
MOVE sy-datum+0(4) TO l_yearn.
* If current month > 1 subtract 1 from then month
IF l_monthn > 1.
l_monthn = l_monthn - 1.
ELSE.
l_monthn = 12.
l_yearn = l_yearn - 1.
ENDIF.
* First date of month
CONCATENATE l_yearn l_monthn '01' INTO p_fromdate.
* Last date of month
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = p_fromdate
IMPORTING
last_day_of_month = p_todate
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.