根据出生年月计算年龄

REPORT ZABAP1903_11_BASIC02.
data: y0(4) type n,
m0 type i,
d0 type i,
y1(4) type n,
m1 type i,
d1 type i,
age type i.
y0 = 1999.
m0 = 3.
d0 = 22.
y1 = 2019.
m1 = 3.
d1 = 27.
age = y1 - y0.

write:/ '出生日期是:',y0,m0,d0.
write:/ '今天是:' ,sy-datum.
write:/ '年龄:' , age.

write:/.
write:/.
"第二种方法
write:/ '第二种方法:'.
TYPE-POOLS: p99sg.
DATA:
begda type d,
years TYPE i.
begda = '19980825'.
DATA: month_tab TYPE STANDARD TABLE OF p99sg_month_tab_row.

CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
EXPORTING
begda = '19980825' "开始日期
endda = '20190328' "截止日期
IMPORTING
c_years = years . "返回年数

write:/'年龄:' , years.
write:/ '出生日期是:',begda.
write:/ '今天是:' ,sy-datum.

你可能感兴趣的:(根据出生年月计算年龄)