Posted on Apr. 20, 2010 at 03.15 PM - Chennai, India
It's quite common that we need to extract data from the payroll result data, which is stored in a cluster table. How do we do that? There are several techniques to achieve this purpose:
a. Using HR macro
b. Using function module
c. Using logical database
And the technique explained in this blog is by using function module.
1. Get the country grouping of the employee, this step is especially required if the same SAP HR application is used to run payroll for employees in several countries.
* get the country grouping
CALL FUNCTION 'PYXX_GET_RELID_FROM_PERNR'
EXPORTING
employee = ip_pernr
IMPORTING
relid = lv_relid
molga = lv_molga
EXCEPTIONS
error_reading_infotype_0001 = 1
error_reading_molga = 2
error_reading_relid = 3
OTHERS = 4.
* Make sure the country grouping is Great Britain
CHECK lv_molga = '08' AND lv_relid = g_rg.
2. Every time, a payroll is run, a specific entries, like FOR PERIOD and IN PERIOD is created in a (internal) table called RGDIR. So in order to retrieve the payroll result correctly, we need to consult this table first.
* get payroll data
CALL FUNCTION 'CD_READ_RGDIR'
EXPORTING
persnr = ip_pernr
TABLES
in_rgdir = lt_rgdir
EXCEPTIONS
no_record_found = 1
OTHERS = 2.
3. Sometimes, due to certain circumstances, retroactive payroll can happen. One typical example to this would be, let's say the salary increment has to happen in January, but the management can ONLY come to a decision in February. Obviously the January payroll has to be rerun to be calculated based on the new basic salary, and this will create what we call as retroactive payroll. So to make sure that we always get the latest payroll run for a specific payroll period, function module CD_READ_LAST is used.
CHECK lt_rgdir IS NOT INITIAL.
CLEAR ls_rgdir-seqnr.
CALL FUNCTION 'CD_READ_LAST'
EXPORTING
begin_date = ip_fpbeg
end_date = ip_fpend
IMPORTING
out_seqnr = ls_rgdir-seqnr
TABLES
rgdir = lt_rgdir
EXCEPTIONS
NO_RECORD_FOUND = 1
OTHERS = 2
.
4. Once we get the right RGDIR entry, we can now fetch the data from the cluster table
CHECK ls_rgdir-seqnr IS NOT INITIAL.
* get payroll result
CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'
EXPORTING
clusterid = lv_relid
employeenumber = ip_pernr
sequencenumber = ls_rgdir-seqnr
CHANGING
payroll_result = ls_result
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.
Life is beautiful! Let's make it meaningful and colorful!