Some Useful Function Modules involving Dates
REPORT.
*=============================================== *NUMBER_OF_DAYS_PER_MONTH_GET *This function module gives number of days in a given month of given year *=============================================== DATA DAY1 TYPE T009B-BUTAG. CALL FUNCTION 'NUMBER_OF_DAYS_PER_MONTH_GET' EXPORTING PAR_MONTH = '02' PAR_YEAR = '2012' IMPORTING PAR_DAYS = DAY1. "Datatypes of parameters must match each other WRITE DAY1.
*===================================================== *MONTHS_BETWEEN_TWO_DATES *This function module gives number of months between two given dates *===================================================== DATA MONTHS1 TYPE I. CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES' EXPORTING I_DATUM_BIS = '20170214' I_DATUM_VON = '20160214' IMPORTING E_MONATE = MONTHS1. WRITE MONTHS1.
*==================================================== *DATE_GET_WEEK *This function module gives WEEK number along with year for a given date *==================================================== DATA WEEKS1 TYPE SCAL-WEEK. CALL FUNCTION 'DATE_GET_WEEK' EXPORTING DATE = '20170222' IMPORTING WEEK = WEEKS1. WRITE WEEKS1.
*==================================================== *WEEK_GET_FIRST_DAY *This function module gives Monday Date of a given week number. *==================================================== DATA DATE1 TYPE SCAL-DATE. CALL FUNCTION 'WEEK_GET_FIRST_DAY' EXPORTING WEEK = '201708' "Week number should be preceded by year IMPORTING DATE = DATE1. WRITE:/ DATE1.
*===================================================== *BWSO_DATE_GET_FIRST_WEEKDAY *This function module gives first day of the week (Monday date) of the given date. *===================================================== DATA DATE2 TYPE DATS. CALL FUNCTION 'BWSO_DATE_GET_FIRST_WEEKDAY' EXPORTING DATE_IN = '20170214' IMPORTING DATE_OUT = DATE2. WRITE DATE2.
*===================================================== *DATE_CHECK_PLAUSIBILITY *This function module verifies whether the given date is Correct or Not *==================================================== CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY' EXPORTING DATE = '20170229' EXCEPTIONS PLAUSIBILITY_CHECK_FAILED = 1 OTHERS = 2. IF SY-SUBRC <> 0. "it will be 1 when exception is raised for WRONG dates MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ELSE. MESSAGE 'Valid date' TYPE 'S'. "S-Success, W-wrong, E-Error ENDIF.
*===================================================== *RH_GET_DATE_DAYNAME *This function module gives week day name for a given date *===================================================== DATA DAY_NAME TYPE HRVSCHED-DAYTXT. CALL FUNCTION 'RH_GET_DATE_DAYNAME' EXPORTING LANGU = SY-LANGU DATE = '20170223' IMPORTING DAYTXT = DAY_NAME. WRITE:/ DAY_NAME.
Comments
Post a Comment