signed

QiShunwang

“诚信为本、客户至上”

【ABAP】计算年月函数

2021/6/24 19:14:02   来源:

根据起始年月与数字相加,计算所得年月

FUNCTION Z_TEST_MONTH_COUNT.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(P_MONTH) TYPE  CHAR6
*"     VALUE(COUNT) TYPE  INT4
*"  EXPORTING
*"     VALUE(END_MONTH) TYPE  CHAR6
*"----------------------------------------------------------------------
data : year_num type i.
data : month_num type i.
data : add_year type i.
data : start_month type i.

year_num = p_month+0(4).
month_num = p_month+4(2).
month_num = month_num + count.
start_month = month_num mod 12.

if start_month = 0.
  start_month = 12.
endif.
add_year = month_num div 12.

if start_month = 12.
  add_year = add_year - 1.
endif.
year_num = year_num + add_year.

write year_num to end_month+0(4).

if start_month LT 10.
  write '0' to end_month+4(1).
  write start_month to end_month+5(1).
else.
  write start_month to end_month+4(2).
endif.

ENDFUNCTION.