Monday, 9 November 2015

Employee Leave History Details in ABAP-HR

Employee Leave History Details in HR-ABAP

*USING /SDF/CMO_DATETIME_DIFFERENCE

REPORT  ZHR_D213_TIME.

TABLES PERNR.

DATA DAYS TYPE P.

TYPE-POOLS: SLIS.

DATA: ZES TYPE PC2B6 OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF ITAB OCCURS 0,
        D1(5)   TYPE C,
        D1P(10) TYPE C,
        D2(5)   TYPE C,
        D2P(10) TYPE C,
        D3(5)   TYPE C,
        D3P(10) TYPE C,
        D4(5)   TYPE C,
        D4P(10) TYPE C,
        D5(5)   TYPE C,
        D5P(10) TYPE C,
        D6(5)   TYPE C,
        D6P(10) TYPE C,
        D7(5)   TYPE C,
        D7P(10) TYPE C,
        D8(5)   TYPE C,
        D8P(10) TYPE C,
        D9(5)   TYPE C,
        D9P(10) TYPE C,
        D10(5)   TYPE C,
        D10P(10) TYPE C,
        D11(5)   TYPE C,
        D11P(10) TYPE C,
        D12(5)   TYPE C,
        D12P(10) TYPE C,
        D13(5)   TYPE C,
        D13P(10) TYPE C,
        D14(5)   TYPE C,
        D14P(10) TYPE C,
        D15(5)   TYPE C,
        D15P(10) TYPE C,
        D16(5)   TYPE C,
        D16P(10) TYPE C,
        D17(5)   TYPE C,
        D17P(10) TYPE C,
        D18(5)   TYPE C,
        D18P(10) TYPE C,
        D19(5)   TYPE C,
        D19P(10) TYPE C,
        D20(5)   TYPE C,
        D20P(10) TYPE C,
        D21(5)   TYPE C,
        D21P(10) TYPE C,
        D22(5)   TYPE C,
        D22P(10) TYPE C,
        D23(5)   TYPE C,
        D23P(10) TYPE C,
        D24(5)   TYPE C,
        D24P(10) TYPE C,
        D25(5)   TYPE C,
        D25P(10) TYPE C,
        D26(5)   TYPE C,
        D26P(10) TYPE C,
        D27(5)   TYPE C,
        D27P(10) TYPE C,
        D28(5)   TYPE C,
        D28P(10) TYPE C,
        D29(5)   TYPE C,
        D29P(10) TYPE C,
        D30(5)   TYPE C,
        D30P(10) TYPE C,
        D31(5)   TYPE C,
        D31P(10) TYPE C,
      END OF ITAB.

DATA: VAR(400) TYPE C,
      VAR3 TYPE STRING,
      VAR2 TYPE STRING,
      VAR4 TYPE STRING.

DATA: NUM TYPE I,
     NUM1 TYPE I.

DATA IT_FIELD TYPE SLIS_T_FIELDCAT_ALV.
DATA WA_FIELD TYPE SLIS_FIELDCAT_ALV.

DATA I_PNPPABRP TYPE I.

START-OF-SELECTION.

GET PERNR.

  CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
    EXPORTING
      DATE1                  = PN-BEGDA
      TIME1                  = '000000'
      DATE2                  = PN-ENDDA
      TIME2                  = '000000'
 IMPORTING
     DATEDIFF               = DAYS
*   TIMEDIFF               =
*   EARLIEST               =
* EXCEPTIONS
*   INVALID_DATETIME       = 1
*   OTHERS                 = 2
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL FUNCTION 'HR_TIME_RESULTS_GET'
    EXPORTING
      GET_PERNR = PERNR-PERNR
      GET_PABRJ = PN-PABRJ
      GET_PABRP = PN-PABRP
    TABLES
      GET_ZES   = ZES.

  LOOP AT ZES WHERE ZTART = '0050' OR ZTART = '0020'.
    NUM1 = ZES-REDAY - NUM - 1.
    NUM = NUM + 1.
    IF ZES-REDAY NE NUM.
      DO NUM1 TIMES.
        VAR4 = NUM.
        IF NUM >= '23'.
         

    CONCATENATE VAR3  VAR4 'HOLIDAY' INTO VAR3 SEPARATED BY '@'.
        ELSE.
          CONCATENATE VAR VAR4 'HOLIDAY' INTO VAR SEPARATED BY '@'.
          CONDENSE VAR.
        ENDIF.
        NUM = NUM + 1.
      ENDDO.
    ENDIF.

    VAR2 = ZES-ANZHL.

    IF ZES-ZTART = '0020'.
      VAR2 = 'L'.
    ENDIF.

    IF ZES-REDAY >= '23'.
      CONCATENATE VAR3 ZES-REDAY VAR2 INTO VAR3 SEPARATED BY '@'.
    ELSE.
      CONCATENATE VAR ZES-REDAY VAR2 INTO VAR SEPARATED BY '@'.
      CONDENSE VAR.
    ENDIF.

    NUM = ZES-REDAY.
    CLEAR VAR2.
  ENDLOOP.

  CLEAR  ITAB.

  SPLIT VAR AT '@' INTO VAR2 ITAB-D1 ITAB-D1P ITAB-D2 ITAB-D2P
                             ITAB-D3 ITAB-D3P ITAB-D4 ITAB-D4P
                             ITAB-D5 ITAB-D5P ITAB-D6 ITAB-D6P
                             ITAB-D7 ITAB-D7P ITAB-D8 ITAB-D8P
                             ITAB-D9 ITAB-D9P ITAB-D10 ITAB-D10P
                             ITAB-D11 ITAB-D11P ITAB-D12 ITAB-D12P
                             ITAB-D13 ITAB-D13P ITAB-D14 ITAB-D14P
                             ITAB-D15 ITAB-D15P ITAB-D16 ITAB-D16P
                             ITAB-D17 ITAB-D17P ITAB-D18 ITAB-D18P
                             ITAB-D19 ITAB-D19P ITAB-D20 ITAB-D20P
                             ITAB-D21 ITAB-D21P ITAB-D22 ITAB-D22P.

  SPLIT VAR3 AT '@' INTO VAR3 ITAB-D23 ITAB-D23P ITAB-D24 ITAB-D24P
                               ITAB-D25 ITAB-D25P ITAB-D26 ITAB-D26P
                               ITAB-D27 ITAB-D27P ITAB-D28 ITAB-D28P
                               ITAB-D29 ITAB-D29P ITAB-D30 ITAB-D30P
                               ITAB-D31 ITAB-D31P.
  APPEND ITAB.

  DATA DD(4) TYPE C.
  DAYS = DAYS + 1.

DO DAYS TIMES.

  PERFORM FIELD USING DD 'DAY1'.
CONCATENATE 'D' DAYS INTO DD.
ENDDO.
*  PERFORM FIELD USING 'D1' 'DAY1'.
*  PERFORM FIELD USING 'D1P' 'HOURS'.
*
*  PERFORM FIELD USING 'D2' 'DAY2'.
*  PERFORM FIELD USING 'D2P' 'HOURS'.
*
*  PERFORM FIELD USING 'D3' 'DAY3'.
*  PERFORM FIELD USING 'D3P' 'HOURS'.
*
*  PERFORM FIELD USING 'D4' 'DAY4'.
*  PERFORM FIELD USING 'D4P' 'HOURS'.
*
*  PERFORM FIELD USING 'D5' 'DAY5'.
*  PERFORM FIELD USING 'D5P' 'HOURS'.
*
*  PERFORM FIELD USING 'D6' 'DAY6'.
*  PERFORM FIELD USING 'D6P' 'HOURS'.
*
*  PERFORM FIELD USING 'D7' 'DAY7'.
*  PERFORM FIELD USING 'D7P' 'HOURS'.
*  IF DAYS GT '07'.
*
*    PERFORM FIELD USING 'D8' 'DAY8'.
*    PERFORM FIELD USING 'D8P' 'HOURS'.
*
*    PERFORM FIELD USING 'D9' 'DAY9'.
*    PERFORM FIELD USING 'D9P' 'HOURS'.
*
*    PERFORM FIELD USING 'D10' 'DAY10'.
*    PERFORM FIELD USING 'D10P' 'HOURS'.
*
*    PERFORM FIELD USING 'D11' 'DAY11'.
*    PERFORM FIELD USING 'D11P' 'HOURS'.
*
*    PERFORM FIELD USING 'D12' 'DAY12'.
*    PERFORM FIELD USING 'D12P' 'HOURS'.
*
*    PERFORM FIELD USING 'D13' 'DAY13'.
*    PERFORM FIELD USING 'D13P' 'HOURS'.
*
*    PERFORM FIELD USING 'D14' 'DAY14'.
*    PERFORM FIELD USING 'D14P' 'HOURS'.
*
*    PERFORM FIELD USING 'D15' 'DAY15'.
*    PERFORM FIELD USING 'D15P' 'HOURS'.
*
*    PERFORM FIELD USING 'D16' 'DAY16'.
*    PERFORM FIELD USING 'D16P' 'HOURS'.
*
*    PERFORM FIELD USING 'D17' 'DAY17'.
*    PERFORM FIELD USING 'D17P' 'HOURS'.
*
*    PERFORM FIELD USING 'D18' 'DAY18'.
*    PERFORM FIELD USING 'D18P' 'HOURS'.
*
*    PERFORM FIELD USING 'D19' 'DAY19'.
*    PERFORM FIELD USING 'D19P' 'HOURS'.
*
*    PERFORM FIELD USING 'D20' 'DAY20'.
*    PERFORM FIELD USING 'D20P' 'HOURS'.
*
*    PERFORM FIELD USING 'D21' 'DAY21'.
*    PERFORM FIELD USING 'D21P' 'HOURS'.
*
*    PERFORM FIELD USING 'D22' 'DAY22'.
*    PERFORM FIELD USING 'D22P' 'HOURS'.
*
*    PERFORM FIELD USING 'D23' 'DAY23'.
*    PERFORM FIELD USING 'D23P' 'HOURS'.
*
*    PERFORM FIELD USING 'D24' 'DAY24'.
*    PERFORM FIELD USING 'D24P' 'HOURS'.
*
*    PERFORM FIELD USING 'D25' 'DAY25'.
*    PERFORM FIELD USING 'D25P' 'HOURS'.
*
*    PERFORM FIELD USING 'D26' 'DAY26'.
*    PERFORM FIELD USING 'D26P' 'HOURS'.
*
*    PERFORM FIELD USING 'D27' 'DAY27'.
*    PERFORM FIELD USING 'D27P' 'HOURS'.
*
*    PERFORM FIELD USING 'D28' 'DAY28'.
*    PERFORM FIELD USING 'D28P' 'HOURS'.
*    IF DAYS GT '27'.
*      PERFORM FIELD USING 'D29' 'DAY29'.
*      PERFORM FIELD USING 'D29P' 'HOURS'.
*
*      PERFORM FIELD USING 'D30' 'DAY30'.
*      PERFORM FIELD USING 'D30P' 'HOURS'.
*
*      IF DAYS GT '29'.
*
*        PERFORM FIELD USING 'D31' 'DAY31'.
*        PERFORM FIELD USING 'D31P' 'HOURS'.
*
*      ENDIF.
*    ENDIF.
*  ENDIF.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
   EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME                  =
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
     IT_FIELDCAT                       = IT_FIELD
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 = 0
*   I_HTML_HEIGHT_END                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
    TABLES
      T_OUTTAB                          = ITAB
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
            .
  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
*  LOOP AT ITAB .
*    WRITE:/ ITAB-D1, ITAB-D1P, ITAB-D2, ITAB-D2P,
*                             ITAB-D3, ITAB-D3P, ITAB-D4, ITAB-D4P,
*                             ITAB-D5, ITAB-D5P, ITAB-D6, ITAB-D6P,
*                             ITAB-D7, ITAB-D7P, ITAB-D8, ITAB-D8P,
*                             ITAB-D9, ITAB-D9P, ITAB-D10, ITAB-D10P,
*                             ITAB-D11, ITAB-D11P, ITAB-D12, ITAB-D12P,
*                             ITAB-D13, ITAB-D13P, ITAB-D14, ITAB-D14P,
*                             ITAB-D15, ITAB-D15P, ITAB-D16, ITAB-D16P,
*                             ITAB-D17, ITAB-D17P, ITAB-D18, ITAB-D18P,
*                             ITAB-D19, ITAB-D19P, ITAB-D20, ITAB-D20P,
*                             ITAB-D21, ITAB-D21P, ITAB-D22, ITAB-D22P,
*                             ITAB-D23, ITAB-D23P, ITAB-D24, ITAB-D24P,
*                             ITAB-D25, ITAB-D25P, ITAB-D26, ITAB-D26P,
*                             ITAB-D27, ITAB-D27P, ITAB-D28, ITAB-D28P,
*                             ITAB-D29, ITAB-D29P, ITAB-D30, ITAB-D30P,
*                             ITAB-D31, ITAB-D31P.
*
*  ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FNAME      text
*      -->FDESC      text
*      -->TABNAME    text
*----------------------------------------------------------------------*

FORM FIELD USING FNAME
                 FDESC.

CONCATENATE 'DAY' DAYS INTO FDESC.

  WA_FIELD-FIELDNAME = FNAME.
  WA_FIELD-SELTEXT_L = FDESC.

  APPEND WA_FIELD TO IT_FIELD.
  CLEAR WA_FIELD.
ENDFORM.                    " FIELD