Before jumping directly to the code, lets go into some basics. First, Time management data and Payroll data is stored in (data) clusters on the database and not directly in the transparent tables we are used to. The info about the clusters is stored in transparent table PCL2 as follows:
PCL2: Payroll cluster table
RELID (Relations ID) is the 2-character name of the cluster e.g.CU, RD (Payroll results-US), RX (Payroll results-International), B2(Time management results), ZL(Personal shift plan), PS(Generated schema), PT(Texts for generated schema), etc.
SRTFD stores the key for the table PCL2. SRTF2 is the sort field so as to store a duplicate key.
PGMID is the name of the program which carried out the last update on the cluster and CLUSTD stores the data.
The standard country-specific payroll programs (RPCALCn0 - n stands for country version) write the results to PCL2. An overview of the payroll results can be accessed from the cluster directory in cluster CU for a specified period. Every employee on the payroll has its records in the cluster directory. Its structure as follows:
PC261: Cluster directory
SEQNR denotes the running sequence numbers for payroll results with next payroll result against the next sequence number. FPPER stores the period for which payroll run was carried out and INPER stores in which period it was carried out. For retroactive accounting, you can carry out payroll run for the past period/s in the current period.
This cluster directory from the cluster CU is stored in a database table HRPY_RGDIR (Directory for Payroll results) redundantly so that Logical database PNP can access it for evaluating payroll results.
HRPY_RGDIR: Directory for Payroll results
There is another transparent table HRPY_WPBP which stores data from the table WPBP (Work Place / Basic Pay) of the cluster RX, redundantly for Logical database PNP again. The structure for the table in the cluster is represented by structure PC205.
HRPY_WPBP: Work place Basic pay
Let us now talk about evaluating payroll results. To help in accessing the payroll results, there are country-specific logical structures which are filled during evaluation process. Evaluation process may involve the use of Function modules or GET PAYROLL event of the PNP logical database. This logical structure is represented by PAYXY_RESULT, where XY represents the ISO code of the country which is stored in table T500L as follows:
![Pic5_T500L.jpg]()
T500L: Personnel country grouping
The table T500L above also displays the country specific cluster name in the PCL2 table. Coming back to logical structure PAYXX_RESULT, it is PAYUS_RESULT from the above table, shown below :
PAYUS_RESULT: Definition of payroll result
During run-time, Structure EVP holds the data from the directory of cluster CU. Structures INTER and NAT are deep structures and hold international and national component of the payroll. PAYUS_RESULT-INTER has further sub-structures/tables like VERSC (payroll status information), WPBP, RT(Results table), CRT(Cumulative Results table), etc.
Cluster CU has a table RGDIR which stores a row for each payroll run per employee. Standard report H99_DISPLAY_PAYRESULT can be used to display payroll results.
Following is a sample program for fetching payroll results using Function modules CU_READ_RGDIR and PYXX_READ_PAYROLL_RESULT. You can simply copy and paste the code from here and execute it and check the functionality. It throws an ALV output using class CL_SALV_TABLE. Debug it to understand the flow.
*&---------------------------------------------------------------------*
*& Report ZTEST
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest.
TABLES : pernr.
DATA : it_rgdir TYPE TABLE OF pc261 INITIAL SIZE 0,
wa_rgdir LIKE LINE OF it_rgdir,
it_rt TYPE payus_result-inter-rt,
wa_rt LIKE LINE OF it_rt,
wa_payrollresult TYPE payus_result,
v_molga TYPE molga.
DATA : BEGIN OF wa_out,
pernr TYPE pernr-pernr,
gross TYPE pc207-betrg, "Amount
net TYPE pc207-betrg,
END OF wa_out,
it_outtab LIKE TABLE OF wa_out.
START-OF-SELECTION.
GET pernr.
wa_out-pernr = pernr-pernr.
CALL FUNCTION 'CU_READ_RGDIR'
EXPORTING
persnr = pernr-pernr
IMPORTING
molga = v_molga "if required
TABLES
in_rgdir = it_rgdir
EXCEPTIONS
no_record_found = 1
OTHERS = 2.
IF sy-subrc = 0.
LOOP AT it_rgdir INTO wa_rgdir
WHERE fpbeg GE pn-begda AND
fpend LE pn-endda AND
srtza EQ 'A'. "Current result
CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
EXPORTING
clusterid = 'RU' "US
employeenumber = pernr-pernr
sequencenumber = wa_rgdir-seqnr
CHANGING
payroll_result = wa_payrollresult
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.
LOOP AT wa_payrollresult-inter-rt INTO wa_rt.
CASE wa_rt-lgart.
WHEN '/101'. " Gross
wa_out-gross = wa_out-gross + wa_rt-betrg.
WHEN '/560'. " Net
wa_out-net = wa_out-net + wa_rt-betrg.
ENDCASE.
APPEND wa_out TO it_outtab.
CLEAR wa_out.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDIF.
END-OF-SELECTION.
* ALV Output
DATA : r_alv TYPE REF TO cl_salv_table.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = if_salv_c_bool_sap=>false
* r_container =
* container_name =
IMPORTING
r_salv_table = r_alv
CHANGING
t_table = it_outtab.
CALL METHOD r_alv->display.
*&---------------------------------------------------------------------*