Monday, June 3, 2013

ABAP Program to check for a holiday using factory calendar

REPORT Z_HOLIDAY.
 
* ABAP Program to check for holidays using the factory calendar
* include zday .
* substitute tdate = 'yyyymmdd'.
* tholiday_found   = 'X'   -> Holiday
TABLES THOCS.
 
DATA: BEGIN OF INT_THOCS OCCURS 100,
      THOCS LIKE THOCS.
DATA: END OF INT_THOCS.
 
DATA: TDAY(1),
*      TDATE LIKE SY-DATUM,
      THOLIDAY_ATTRIBUTES,
      THOLIDAY_FOUND(1).
 
PARAMETERS: P_DATE LIKE SY-DATUM DEFAULT SY-DATUM.
 
*&------- Selection ------------------------
START-OF-SELECTION.
 
  PERFORM HOLIDAY.
 
FORM HOLIDAY.
CALL FUNCTION 'HOLIDAY_CHECK_AND_GET_INFO'
     EXPORTING
          DATE                         = P_DATE
          HOLIDAY_CALENDAR_ID          = 'XX'
*         WITH_HOLIDAY_ATTRIBUTES      = ' '
     IMPORTING
          HOLIDAY_FOUND                = THOLIDAY_FOUND
     TABLES
          HOLIDAY_ATTRIBUTES           = INT_THOCS
     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.
 
CALL FUNCTION 'DATE_COMPUTE_DAY'
     EXPORTING
          DATE    = P_DATE
     IMPORTING
          DAY     = TDAY
     EXCEPTIONS
          OTHERS  = 1.
 
* For checking.
if tholiday_found = 'X'.
   write: /1 'Holiday ', P_DATE.
else.
   write: /1 'Not Holiday ', P_DATE.
endif.
 
case sy-subrc.
   when 0.
     write: /1 P_DATE, 'is', tday, 'day of the week.'.
   when others.
     write: /1 'Unknown day ', P_DATE.
endcase.
 
ENDFORM.


1 comment:

  1. SAP ABAP training is provided in CHENNAI.

    THE CREATING EXPERTS is one of the leading trainer in SAP who provides real time training

    http://thecreatingexperts.com/sap-abap-training-in-chennai/

    contact 8122241286

    ReplyDelete