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:
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:
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:
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.
Attaching a sample program for fetching payroll results implementing the above concept and 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. All the Best !