Read Data from Cluster Fields in Tables PCL1 and PCL2 (Payroll)
The following article shows how to extract data from the SAP HCM tables PCL1 and PCL2.
The data can only be extracted using a custom function module and the BAPI extraction type. Data extraction via Table extraction type is not supported.
Custom Function Module Z_HR_CLUSTER_READ
Create the following custom function module in SAP:
- Use SAP transaction SE37 to create a remote enabled custom function module Z_HR_CLUSTER_READ.
-
Create the following parameters:
-
Copy and paste the following ABAP source code into the source code area of the function module.
ABAP source code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
FUNCTION Z_HR_CLUSTER_READ. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING " VALUE(PERNR) TYPE PC2B0-PERNR OPTIONAL *" VALUE(ACTIONID) TYPE CHAR2 DEFAULT 'P1' *" VALUE(STARTDATE) TYPE DATS OPTIONAL *" VALUE(ENDDATE) TYPE DATS OPTIONAL *" TABLES *" ERT STRUCTURE PC2B8 OPTIONAL *" ST STRUCTURE PC2B5 OPTIONAL *" CRT STRUCTURE PC208 OPTIONAL *"---------------------------------------------------------------------- DATA : BEGIN OF it_pcl1 OCCURS 0, srtfd TYPE pcl1-srtfd, END OF it_pcl1. DATA BEGIN OF b1_key. INCLUDE STRUCTURE pdc10. DATA END OF b1_key. IF actionid = 'P1'. SELECT srtfd FROM pcl1 INTO TABLE it_pcl1 WHERE relid EQ 'B1' AND srtfd EQ pernr AND srtf2 EQ 0. LOOP AT it_pcl1. MOVE it_pcl1-srtfd TO b1_key. IMPORT st ert FROM DATABASE pcl1(b1) ID b1_key. IF sy-subrc EQ 0. ENDIF. ENDLOOP. ENDIF. IF actionid = 'P2'. DATA : it_rgdir TYPE TABLE OF pc261 INITIAL SIZE 0, wa_rgdir LIKE LINE OF it_rgdir, it_crt TYPE pay99_result-inter-crt, wa_crt LIKE LINE OF it_crt, wa_payrollresult TYPE pay99_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. wa_out-pernr = PERNR. CALL FUNCTION 'CU_READ_RGDIR' EXPORTING persnr = PERNR IMPORTING molga = v_molga 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 startdate AND fpend LE enddate AND srtza EQ 'A'. "Current result CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT' EXPORTING clusterid = 'RD' employeenumber = PERNR sequencenumber = wa_rgdir-seqnr READ_ONLY_INTERNATIONAL = 'X' 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-crt INTO wa_crt. CASE wa_crt-lgart. WHEN '/101'. " Gross APPEND wa_crt TO crt. ENDCASE. CLEAR wa_out. ENDLOOP. ENDIF. ENDLOOP. ENDIF. ENDIF. ENDFUNCTION.
-
Save the function module.
How to use the Custom Function Module
Depending on the table you want to access, define the following parameters:
- Look up the function module using the BAPI extraction type.
- Populate the import parameter ACTIONID with value P1.
- Populate the field PERNR with a value for Personnel Number. The personnel number has to be entered with leading zeroes.
- Run the extraction. The data is available in the table parameter ST.
- Look up the function module using the BAPI extraction type.
- Populate the import parameter ACTIONID with value P2.
- Enter a start date and end date using the parameters STARTDATE and ENDDATE. The date fields have the format YYYYmmDD.
- Run the extraction. The data is available in the table parameter CRT.
Last update: June 6, 2024