Function modules: Date and Time

 

Get a date

Date calculations

Example: DATE_CREATE

CALL FUNCTION 'DATE_CREATE'
 EXPORTING
   anzahl_jahre  = 1
   anzahl_monate = 2
   anzahl_tage   = 3
   datum_ein     = '20010101'
 IMPORTING
   datum_aus     = l_new_date.
   Result:
   l_new_date = 20020304

Example: MONTH_PLUS_DETERMINE

data: new_date type d.

CALL FUNCTION 'MONTH_PLUS_DETERMINE'
EXPORTING
months = -5 " Negative to subtract from old date, positive to add

olddate = sy-datum
IMPORTING
NEWDATE = new_date.

write: / new_date.


Hollidays

Example: HOLIDAY_CHECK_AND_GET_INFO

data: ld_date                 like scal-datum  default sy-datum,
      lc_holiday_cal_id       like scal-hcalid default 'CA',
      ltab_holiday_attributes like thol occurs 0 with header line,
      lc_holiday_found        like scal-indicator.

CALL FUNCTION 'HOLIDAY_CHECK_AND_GET_INFO'
  EXPORTING
    date                               = ld_date
    holiday_calendar_id                = lc_holiday_cal_id
    WITH_HOLIDAY_ATTRIBUTES            = 'X'

  IMPORTING
    HOLIDAY_FOUND                      = lc_holiday_found
  tables
    holiday_attributes                 = ltab_holiday_attributes
  EXCEPTIONS
    CALENDAR_BUFFER_NOT_LOADABLE       = 1
    DATE_AFTER_RANGE                   = 2
    DATE_BEFORE_RANGE                  = 3
    DATE_INVALID                       = 4
    HOLIDAY_CALENDAR_ID_MISSING        = 5
    HOLIDAY_CALENDAR_NOT_FOUND         = 6
    OTHERS                             = 7.

if sy-subrc = 0 and

   lc_holiday_found = 'X'.
  write: / ld_date, 'is a holiday'.
else.
  write: / ld_date, 'is not a holiday, or there was an error calling the function'.
endif.

Checking dates

Converting dates

Function to return literal for month

he table you want to use is T247. You can also use the function MONTH_NAMES_GET. [ Monique Goodrich ,posted to SAP listserver]

You can also try table T015M. It has the month number in it's key.
[Walter Barr , posted to SAP listserver]

 

 

Formatting

 

Other

 

 

 

Converted from CHM to HTML with chm2web Standard 2.7 (unicode)