使用函式RP_CALC_DATE_IN_INTERVAL進行日期的年月日的加減

JackWu發表於2018-11-06

data LV_DATE type DATS.

** Add/Substract years to date
call function 'RP_CALC_DATE_IN_INTERVAL'
 exporting
  DATE = SY-DATUM
  DAYS = 0
  MONTHS = 0
  SIGNUM = '-' " to calculate previous date
  YEARS = 1
 importing
  CALC_DATE = LV_DATE.

WRITE: 'Today', SY-DATUM, /.
WRITE: 'Previous year', LV_DATE, /.

** Add/Substract months to date
call function 'RP_CALC_DATE_IN_INTERVAL'
 exporting
  DATE = SY-DATUM
  DAYS = 0
  MONTHS = 1
  SIGNUM = '+' " to calculate following date
  YEARS = 0
 importing
  CALC_DATE = LV_DATE.

WRITE: 'Today', SY-DATUM, /.
WRITE: 'Next month', LV_DATE, /.

** Add/Substract days to date
call function 'RP_CALC_DATE_IN_INTERVAL'
 exporting
  DATE = SY-DATUM
  DAYS = 7
  MONTHS = 1
  SIGNUM = '+' " to calculate next dates
  YEARS = 2
 importing
  CALC_DATE = LV_DATE.

WRITE: 'Today', SY-DATUM, /.
WRITE: 'Add 2 Years, 1 Month and 7 Days (or 1 week)', LV_DATE, /.

相關文章