Monday, 26 March 2012

Payoll YTD report in ABAP HR

REPORT  ZHR_D220_AS03_YTD.

TABLES PERNR.

DATA IT_RGDIR TYPE PC261 OCCURS 0 WITH HEADER LINE.

PARAMETERS P_FILE TYPE STRING OBLIGATORY.

DATA  IT_RESULT TYPE PAYIN_RESULT.

DATA : WA_CRT TYPE PC208,
       WA_RT TYPE PC207,
       G_SEQNR TYPE PC261-SEQNR.

DATA: BEGIN OF ITAB OCCURS 0,
      PERNR TYPE PERNR-PERNR,
      GROSS TYPE PC208-BETRG,
      NETPAY TYPE PC207-BETRG,
      TAX TYPE PC207-BETRG,
      END OF ITAB.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  CALL METHOD CL_RSAN_UT_FILES=>F4
    EXPORTING
      I_APPLSERV              = SPACE
      I_TITLE                 = 'CHOOSE FILE PATH...'
      I_GUI_EXTENSION         = 'TXT'
      I_GUI_EXT_FILTER        = SPACE
*    I_GUI_INITIAL_DIRECTORY =
*    I_APPLSERV_LOGICAL      = 'X'
*    I_APPLSERV_AL11         = 'X'
*  IMPORTING
*    E_CANCELED              =
*    E_LOGICAL_FILE          =
*    E_AL11_CHOSEN           =
    CHANGING
      C_FILE_NAME             = P_FILE.

 START-OF-SELECTION.

GET PERNR.

  CALL FUNCTION 'CU_READ_RGDIR'
    EXPORTING
      PERSNR                   = PERNR-PERNR
*   BUFFER                   =
*   NO_AUTHORITY_CHECK       = ' '
* IMPORTING
*   MOLGA                    =
    TABLES
      IN_RGDIR                 = IT_RGDIR.

 *  CALL FUNCTION 'CD_READ_LAST'
*    EXPORTING
*      BEGIN_DATE      = PN-BEGDA
*      END_DATE        = PN-ENDDA
*    IMPORTING
*      OUT_SEQNR       = G_SEQNR
*    TABLES
*      RGDIR           = IT_RGDIR
*    EXCEPTIONS
*      NO_RECORD_FOUND = 1
*      OTHERS          = 2.
*  IF SY-SUBRC <> 0.
*    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*  ENDIF.


  LOOP AT IT_RGDIR WHERE FPPER EQ PN-PAPER.

  CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
    EXPORTING
*   CLUSTERID                          =
   EMPLOYEENUMBER                     = PERNR-PERNR
   SEQUENCENUMBER                     = IT_RGDIR-SEQNR
*   READ_ONLY_BUFFER                   = ' '
*   READ_ONLY_INTERNATIONAL            = ' '
*   ARC_GROUP                          = ' '
*   CHECK_READ_AUTHORITY               = 'X'
*   FILTER_CUMULATIONS                 = 'X'
*   CLIENT                             =
* IMPORTING
*   VERSION_NUMBER_PAYVN               =
*   VERSION_NUMBER_PCL2                =
    CHANGING
      PAYROLL_RESULT                     = IT_RESULT.

  ENDLOOP.

  LOOP AT IT_RESULT-INTER-CRT INTO WA_CRT WHERE CUMTY = 'Y'.



    CASE WA_CRT-LGART.

      WHEN '/101'.

        MOVE: PERNR-PERNR TO ITAB-PERNR,
              WA_CRT-BETRG TO ITAB-GROSS.

      WHEN '/460'.

        MOVE:  WA_CRT-BETRG TO ITAB-TAX.

    ENDCASE.

  ENDLOOP.

  LOOP AT IT_RESULT-INTER-RT INTO WA_RT.


    CASE WA_RT-LGART.

      WHEN '/560'.

        MOVE: WA_RT-BETRG TO ITAB-NETPAY.

    ENDCASE.

  ENDLOOP.

  APPEND ITAB.
  CLEAR ITAB.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
    EXPORTING
*    BIN_FILESIZE              =
      FILENAME                  = P_FILE
*    FILETYPE                  = 'ASC'
*    APPEND                    = SPACE
     WRITE_FIELD_SEPARATOR     = 'X'
*    HEADER                    = '00'
*    TRUNC_TRAILING_BLANKS     = SPACE
*    WK1_T_SIZE                = SPACE
*  IMPORTING
*    FILELENGTH                =
    CHANGING
      DATA_TAB                  = ITAB[].
         .