直接上Example:
IF ip_loaddate_from IS INITIAL AND ip_loaddate_to IS INITIAL.
CONCATENATE sy-datum(6) ‘01’ INTO r_loaddate-low. ”获取当前月的第一天
CALL FUNCTION ‘BKK_GET_MONTH_LASTDAY’ ”获取当前月的最后一天
EXPORTING
i_date = sy-datum
IMPORTING
e_date = r_loaddate-high.
r_loaddate-sign = ‘I’.
r_loaddate-option = ‘BT’.
APPEND r_loaddate.
ENDIF.获取一个月的最后一天不需要自己写方法,可以直接调用了bkk_get_month_lastday这个function,这个function还处理好闰年闰月的问题,函数内容如下:
function bkk_get_month_lastday.“Determine Last Day of Month
*”----------------------------------------------------------------------
"“Lokale Schnittstelle:
*” IMPORTING
*" VALUE(I_DATE) LIKE SY-DATUM
*" EXPORTING
*" VALUE(E_DATE) LIKE SY-DATUM
*"----------------------------------------------------------------------
data: check_year_1 type p.
data: check_year_2 type p.e_date(4) = i_date(4).
e_date+4(2) = i_date+4(2).if i_date+4(2) = ‘01’
or i_date+4(2) = ‘03’
or i_date+4(2) = ‘05’
or i_date+4(2) = ‘07’
or i_date+4(2) = ‘08’
or i_date+4(2) = ‘10’
or i_date+4(2) = ‘12’.
e_date+6(2) = ‘31’. " 31 days per monthelseif i_date+4(2) = ‘04’
or i_date+4(2) = ‘06’
or i_date+4(2) = ‘09’
or i_date+4(2) = ‘11’.
e_date+6(2) = ‘30’. " 30 days per monthelseif i_date+4(2) = ‘02’. " 闰年的问题
e_date+6(2) = ‘28’.
check_year_1 = i_date(4) mod 4. " all 4 years is leap year
if check_year_1 = 0.
e_date+6(2) = ‘29’.
check_year_1 = i_date(4) mod 100." but not all 100 years
check_year_2 = i_date(4) mod 400." excluding all 400 years
if check_year_1 = 0
and check_year_2 <> 0.
e_date+6(2) = ‘28’.
endif.
endif.
endif.endfunction.