Skip to Content

Unlike other modules data processing in SAP , HR module data processing is little bit different. Here the resultant data will be stroed in Clusters , which we can not access directly with normal select satments . One have to use the SAP provided methods only for data accessing. So I thaught the below program will help a little for HR ABAPers who are learning now.

Below is the program to retrieve an employee’s last run payroll results. For this program I used PNP LDB .

PROGRAM:-

Program Source Code

  

REPORT  ZR_CSD128.
** Pernr structure declaration for Selection screen.
TABLES PERNR. 

DATA: IT_RGDIR TYPE TABLE OF PC261,       ” Table for Cluster directory
       G_SEQNR TYPE PC261-SEQNR,             ” Vairable to store the sequence number.
       ST_PAYRESULT TYPE PAYIN_RESULT,    ” Deep structure type for importing Payroll results from the cluster
       WA_RT TYPE PC207.                               ” Work Area for Results table inside the deep structure of pay roll results table.

START-OF-SELECTION.

** Triggering of Get Event.
GET PERNR.

** Call the function module to import the cluster directory table for the an employee coming in Get pernr Event.

  CALL FUNCTION ‘CU_READ_RGDIR’
    EXPORTING
      PERSNR                   = PERNR-PERNR
*   BUFFER                   =
*   NO_AUTHORITY_CHECK       = ‘ ‘
* IMPORTING
*   MOLGA                    =
    TABLES
      IN_RGDIR                 = IT_RGDIR
EXCEPTIONS
   NO_RECORD_FOUND          = 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 the FM to get the latest run payroll results Sequnce number.

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 SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

** Once if you are ready with the Sequence number for a particular employee call the FM to import Payroll results into Deep structure ( ST_PAYRESULT).
  CALL FUNCTION ‘PYXX_READ_PAYROLL_RESULT’
    EXPORTING
*     CLUSTERID                          = ”
      EMPLOYEENUMBER                     = PERNR-PERNR
      SEQUENCENUMBER                     = G_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                     = ST_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 <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

** Loop the Results table inside Payresults deep structure for Net salary.

** RT table is meant for stroing Result data of the particular Payroll run.

  LOOP AT ST_PAYRESULT-INTER-RT INTO WA_RT WHERE lgart = ‘/560’.          ” /560 is the wage type for Net Salary.
    WRITE: / PERNR-PERNR, PERNR-ENAME, WA_RT-BETRG.
  ENDLOOP.

** End of Program.

And the Final output will be like as below.

Payroll results output.JPG

Regards,

Mayure.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply