Program to read Payroll data

By Vamshidhar Naini, YASH Technologies

*& This is an Example Program to List the Payroll data( Reading RT table
* from cluster PCL2 ) Using the Function module
* ‘PYXX_READ_PAYROLL_RESULT’.
*&---------------------------------------------------------------------*
*& Program Name  : ZHR_LIST_RT
*& Application   : HR
*& Published at SAPTechnical.COM
*& Description   : Listing of Payroll Data
*&---------------------------------------------------------------------
REPORT  ZHR_LIST_RT.
TYPE-POOLS:slis.
TABLES:pa0001.
***********************************************************************
*              Types Declaration                                      *
***********************************************************************
TYPES: BEGIN OF ty_pa0001,
         pernr TYPE pa0001-pernr,
         begda TYPE pa0001-begda,
         orgeh TYPE pa0001-orgeh,
         ename TYPE pa0001-ename,
       END OF ty_pa0001.
TYPES: BEGIN OF ty_output,
        sno TYPE i,
        orgeh TYPE pa0001-orgeh,
        orgtx TYPE t527x-orgtx,
        pernr TYPE pa0001-pernr,
        ename TYPE pa0001-ename,
        lgart TYPE pa0008-lga01,
        betrg TYPE netwr,
       END OF ty_output.
***********************************************************************
*         Internal Tables Declaration                                 *
***********************************************************************
DATA i_pa0001 TYPE STANDARD TABLE OF ty_pa0001.
DATA: it_rgdir   TYPE STANDARD TABLE OF pc261.
DATA: i_rgdir    TYPE STANDARD TABLE OF pc261.
DATA i_output TYPE STANDARD TABLE OF ty_output.
*& Header structure declaration
DATA fs_pa0001 TYPE ty_pa0001.
DATA: fs_rgdir    TYPE pc261.
***********************************************************************
*              Variable Declaration                                   *
***********************************************************************
DATA:
  v_begda      TYPE begda,
  v_endda      TYPE endda,
  v_atext      TYPE t549t-atext,
  v_error      TYPE c.
DATA: v_mname(15).
DATA: v_mname2(20).
***********************************************************************
*              Constants Declaration                                  *
***********************************************************************
CONSTANTS:
 c_x TYPE c VALUE 'X'.
***********************************************************************
*              SELECTION SCREEN                                       *
***********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
PARAMETERS: p_abkrs TYPE pa0001-abkrs OBLIGATORY.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 01(20) text-t02 FOR FIELD p_month1.
SELECTION-SCREEN POSITION 33.
PARAMETER       : p_month1(2) TYPE n OBLIGATORY,
                : p_fyear1(4) TYPE n OBLIGATORY .
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
**********************************************************************
*               AT SELECTION-SCREEN ON FIELD                          *
***********************************************************************
AT SELECTION-SCREEN ON p_month1.
  IF p_month1 GT '12'.
    MESSAGE e531(0u) WITH 'Enter a Valid Period'.
  ENDIF.
AT SELECTION-SCREEN ON p_abkrs.
* Validating the Payroll Area.
  PERFORM validate_payroll_area.
***********************************************************************
*               START-OF-SELECTION EVENT                              *
***********************************************************************
START-OF-SELECTION.
* Getting the starting and ending date of the period.
  PERFORM get_period.
*& Select the Employees.
  PERFORM get_pernrs.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  get_pernrs
*&---------------------------------------------------------------------*
* This subroutine is used to get the amount to pay.
*----------------------------------------------------------------------*
* There are no interface parameters are there to pass
*----------------------------------------------------------------------*
FORM get_pernrs .
  FIELD-SYMBOLS:
      <payresult>     TYPE ANY,
      <lv_payresult>  TYPE h99_clst_s_payresult,
      <lv_versc>      TYPE pc202,
      <li_rt>         TYPE hrpay99_rt,
      <li_ddntk>      TYPE hrpay99_ddntk.
  DATA: lfs_rt         TYPE pc207.
  DATA: lfs_ddntk      TYPE pc23e.
  DATA: lv_relid      TYPE t500l-relid.
  DATA: lv_type       TYPE t52relid-typename.
  DATA: lv_typename   TYPE hrpclx_type.
  DATA: ref_payresult TYPE REF TO data.
  DATA: lv_molga      TYPE molga.
  DATA: lv_type_1     TYPE tadir-obj_name.
  DATA: lv_tadir      TYPE tadir-obj_name.
  DATA: lv_unpaid     TYPE ktsol.
  DATA: lv_paid       TYPE ktsol.
*& Reading all the Personnel Numbers
 SELECT pernr
         begda
         orgeh
         ename
   FROM pa0001
   INTO TABLE i_pa0001
   WHERE endda GE v_begda
     AND begda LE v_endda
     AND abkrs EQ p_abkrs.
  IF sy-subrc NE 0.
    MESSAGE s531(0u) WITH 'No active Employees found for the selection'.
    v_error = c_x.
    STOP.
  ENDIF.                               " IF sy-subrc NE 0.
  SORT i_pa0001 BY pernr begda DESCENDING.
  DELETE ADJACENT DUPLICATES FROM i_pa0001 COMPARING pernr.
  SORT i_pa0001 BY orgeh pernr.
  LOOP AT i_pa0001 INTO fs_pa0001.
*& Reading of the Payresult for all the Periods
    REFRESH:
      it_rgdir,
      i_rgdir.
    CLEAR:fs_rgdir.
    CALL FUNCTION 'CU_READ_RGDIR'
      EXPORTING
        persnr          = fs_pa0001-pernr
      TABLES
        in_rgdir        = it_rgdir
      EXCEPTIONS
        no_record_found = 1
        OTHERS          = 2.
    IF sy-subrc = 0.
      CALL FUNCTION 'PYXX_GET_RELID_FROM_PERNR'
        EXPORTING
          employee                    = fs_pa0001-pernr
        IMPORTING
          relid                       = lv_relid
          molga                       = lv_molga
        EXCEPTIONS
          error_reading_infotype_0001 = 1
          error_reading_molga         = 2
          error_reading_relid         = 3
          OTHERS                      = 4.
      IF sy-subrc NE 0.
      ENDIF.
      SELECT SINGLE typename
               FROM t52relid
               INTO lv_type
              WHERE relid EQ lv_relid
                AND tabname = 'PCL2'.
      IF sy-subrc NE 0.
        lv_relid = 'IN'.
        lv_type = 'PAYIN_RESULT'.
      ENDIF.
      lv_typename = lv_type.
     CREATE DATA ref_payresult TYPE (lv_typename).
      ASSIGN ref_payresult->* TO <payresult>.
*      SRTZA--Status Of records.
*      SRTZA = 'A' --Current Result.
      DELETE it_rgdir WHERE srtza NE 'A'.
* PAYTY --> Payment Type ( Regular or Bonus)
* PAYTY =  SPACE --'Regular Payroll'.
* PAYTY = 'B'   --> 'Bonus'.
      LOOP AT it_rgdir INTO fs_rgdir WHERE payty = ''
                                     AND fpbeg GE v_begda
                                     AND fpend LE v_endda.
        APPEND fs_rgdir TO i_rgdir.
      ENDLOOP.                       " LOOP AT it_rgdir
      SORT i_rgdir BY seqnr DESCENDING.
      CLEAR: lv_unpaid,lv_paid.
      LOOP AT i_rgdir INTO fs_rgdir.
        CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
          EXPORTING
            clusterid                    = lv_relid
            employeenumber               = fs_pa0001-pernr
            sequencenumber               = fs_rgdir-seqnr
          CHANGING
            payroll_result               = <payresult>
          EXCEPTIONS
            illegal_isocode_or_clusterid = 1
            error_generating_import      = 2
            import_mismatch_error        = 3
            subpool_dir_full             = 4
            no_read_authority            = 5
            no_record_found              = 6
            versions_do_not_match        = 7
            error_reading_archive        = 8
            error_reading_relid          = 9
            OTHERS                       = 10.
        IF sy-subrc EQ 0.
          ASSIGN COMPONENT 'INTER-RT' OF STRUCTURE <payresult> TO
<li_rt>.
          write /: fs_pa0001-pernr.
          skip 2.
          LOOP AT <li_rt> INTO lfs_rt.
           write:/ lfs_rt-lgart,30 lfs_rt-betrg.
          ENDLOOP.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "get_pernrs
*&---------------------------------------------------------------------*
*&      Form  get_period
*&---------------------------------------------------------------------*
* This subroutine is used to calculate the period range
*----------------------------------------------------------------------*
* There are no interface parameters are there to pass
*----------------------------------------------------------------------*
FORM get_period .
  SELECT SINGLE begda
                endda
           INTO (v_begda,
                 v_endda)
           FROM t549q
          WHERE permo = '01'
            AND pabrj = p_fyear1
            AND pabrp = p_month1.
  IF sy-subrc NE 0.
    MESSAGE s531(0u) WITH 'Error in Period calculation- table T549Q'.
    v_error = 'X'.
    STOP.
  ENDIF.
ENDFORM.                               " Get_period
*&---------------------------------------------------------------------*
*&      Form  validate_payroll_area
*&---------------------------------------------------------------------*
* This Subroutine is used to validate the payroll area
*----------------------------------------------------------------------*
* There are no Parameters to pass this subroutine
*----------------------------------------------------------------------*
FORM validate_payroll_area .
  DATA:    lv_abkrs TYPE t549a-abkrs.
  SELECT SINGLE abkrs                  " Payroll Area
           FROM t549a
           INTO lv_abkrs
          WHERE abkrs EQ p_abkrs.
  IF sy-subrc NE 0.
    MESSAGE e531(0u) WITH 'Enter a valid Payroll Area'.
  ENDIF.                               " IF sy-subrc NE 0.
ENDFORM.                               " Validate_payroll_area

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image