Mostly this problem arises since the months have variable end date and we need to know at runtime, whether last date is 31 or 30 or in case of Feb 28 or29!!
Here's what can be done:
Data : lv_date type DATS,
lv_lastday type DATS,
wf_date type DATS,
lv_month(2) type n.
wf_date = sy-datlo. "This is just for demo
*wf_date contains the date in the format 20071026
lv_month = wf_date+4(2) + 1.
concatenate wf_date+0(4) lv_month '01' into lv_date.
lv_lastday = lv_date - 1.
This method is better:
Use the function module FIMA_DATE_CREATE
data: lv_actual_date type sy-datum,
lv_end_of_month_date type sy-datum.
lv_actual_date = sy-datum.
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = lv_actual_date
* I_FLG_END_OF_MONTH = ' '
* I_YEARS = 0
* I_MONTHS = 0
* I_DAYS = 0
* I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = lv_end_of_month_date
.
With the other Exporting Parameters you can get the date of other years or months.
For example: I_YEARS = 2 => Input_Years = 2005 Output_Years = 2007
I_MONTHS = '-3' => Input_Month = 07 Output_Month = 04
No comments:
Post a Comment