You are on page 1of 10

HR ABAP LDB

Logical database A logical database is a special ABAP/4 program which combines the contents of certain database tables. Using logical databases facilitates the process of reading database tables.

HR Logical Database is PNP


Main Functions of the logical database PNP: Standard Selection screen Data Retrieval Authorization check

To use logical database PNP in your program, specify in your program attributes. Standard Selection Screen Date selection Date selection delimits the time period for which data is evaluated. GET PERNR retrieves all records of the relevant infotypes from the database. When you enter a date selection period, the PROVIDE loop retrieves the infotype records whose validity period overlaps with at least one day of this period. Person selection Person selection is the 'true' selection of choosing a group of employees for whom the report is to run. Sorting Data The standard sort sequence lists personnel numbers in ascending order. SORT function allows you to sort the report data otherwise. All the sorting fields are from infotype 0001. Report Class You can suppress input fields which are not used on the selection screen by assigning a report class to your program. If SAP standard delivered report classes do not satisfy your requirements, you can create your own report class through the IMG.

Data Retrieval from LDB 1. Create data structures for infotypes. INFOTYPES: 0001, "ORG ASSIGNMENT 0002, "PERSONAL DATA 0008. "BASIC PAY 2. Fill data structures with the infotype records. Start-of-selection. GET PERNR.

End-0f-selection. Read Master Data Infotype structures (after GET PERNR) are internal tables loaded with data. The infotype records (selected within the period) are processed sequentially by the PROVIDE - ENDPROVIDE loop. GET PERNR. PROVIDE * FROM Pnnnn BETWEEN PN/BEGDA AND PN/ENDDA If Pnnnn-XXXX = ' '. write:/ Pnnnn-XXXX. endif. ENDPROVIDE. Period-Related Data All infotype records are time stamped. IT0006 (Address infotype) 01/01/1990 12/31/9999 present Which record to be read depends on the date selection period specified on the selection screen. PN/BEGDA PN/ENDDA. Current Data IT0006 Address - 01/01/1990 12/31/9999

present

RP-PROVIDE-FROM-LAST retrieves the record which is valid in the data selection period. For example, pn/begda = '19990931' pn/endda = '99991231' IT0006 subtype 1 is resident address RP-PROVIDE-FROM-LAST P0006 1 PN/BEGDA PN/ENDDA.

ABAP Infotypes
Process Infotypes
RMAC Modules - RMAC module as referred to Macro, is a special construct of ABAP/4 codes. Normally, the program code of these modules is stored in table 'TRMAC'. The table key combines the program code under a given name. It can also be defined in programs.The RMAC defined in the TRMAC can be used in all Reports. When an RMAC is changed, the report has to be regenerated manually to reflect the change. Reading Infotypes - by using RMAC (macro) RP-READ-INFOTYPE REPORT ZHR00001.

PARAMETERS: PERNR LIKE P0002-PERNR. RP-READ-INFOTYPE PERNR 0002 P0002 <BEGIN> <END>. PROVIDE * FROM P0002 if ... then ...endif. ENDPROVIDE. Changing Infotypes - by using RMAC (macro) RP-READ-INFOTYPE. Three steps are involved in changing infotypes: 1. Select the infotype records to be changed; 2. Make the required changes and store the records in an alternative table; 3. Save this table to the database;

The RP-UPDATE macro updates the database. The parameters of this macro are the OLD internal table containing the unchanged records and the NEW internal table containing the changed records. You cannot create or delete data. Only modification is possible. INFOTYPES: Pnnnn NAME OLD, Pnnnn NAME NEW. GET PERNR. PROVIDE * FROM OLD WHERE .... = ... "Change old record *Save old record in alternate table NEW = OLD. ENDPROVIDE. RP-UPDATE OLD NEW. "Update changed record Infotype with repeat structures How to identify repeat structures. a. On infotype entry screen, data is entered in table form. IT0005, IT0008, IT0041, etc. b. In the infotype structure, fields are grouped by the same name followed by sequence number. P0005-UARnn P0005-UANnn P0005-UBEnn P0005-UENnn P0005-UABnn Repeat Structures Data is entered on the infotype screen in table format but stored on the database in a linear structure. Each row of the table is stored in the same record on the database. When evaluating a repeat structure, you must define the starting point, the increment and the work area which contains the complete field group definition. Repeat Structures Evaluation (I) To evaluate the repeat structures a. Define work area. The work area is a field string. Its structure is identical to that of the field group. b. Use a DO LOOP to divide the repeat structure into segments and make it available for processing in the work area, one field group (block) at a time.

Repeat Structures Evaluation(II) * Define work area DATA: BEGIN OF VACATION, UAR LIKE P0005-UAR01, "Leave type UAN LIKE P0005-UAN01, "Leave entitlement UBE LIKE P0005-UBE01, "Start date UEN LIKE P0005-UEN01, "End date UAB LIKE P0005-UAB01, "Leave accounted END OF VACATION. GET PERNR. RP-PROVIDE-FROM-LAST P0005 SPACE PN/BEGDA PN/ENDDA. DO 6 TIMES VARYING VACATION FROM P0005-UAR01 "Starting point NEXT P0005-UAR02. "Increment If p0005-xyz then ... endif. ENDDO.

HR ABAP - Time
Processing 'Time Data'. Dependence of time data on validity period Importing time data Processing time data using internal tables Time Data and Validity Period Time data always applies to a specific validity period. The validity periods of different types of time data are not always the same as the date selection period specified in the selection screen. Date selection period |---------------| Leave |-------------| PROVIDE in this case is therefore not used for time infotypes. Importing Time Data GET PERNR reads all time infotypes from the lowest to highest system data, not only those within the date selection period. To prevent memory overload, add MODE N to the infotype declaration. This prevents the logical database from importing all data into infotype tables at GET PERNR. Use macro RP-READ-ALL-TIME-ITY to fill infotype table. INFOTYPES: 2001 MODE N. GET PERNR. RP-READ-ALL-TIME-ITY PN/BEGDA PN/ENDDA.

LOOP AT P0021. If P0021-XYZ = ' '. A=B. Endif. ENDLOOP. Processing Time Data Once data is imported into infotype tables, you can use an internal table to process the interested data. DATA: BEGIN OF ITAB OCCURS 0, BUKRS LIKE P0001-BUKRS, "COMPANY WERKS LIKE P0001-WERKS, "PERSONNEL AREA AWART LIKE P2001-AWART, "ABS./ATTEND. TYPE ASWTG LIKE P2001-ASWTG, "ABS./ATTEND. DAYS END OF ITAB. GET PERNR. RP-PROVIDE-FROM-LAST P0001 SAPCE PN/BEGDA PN/ENDDA. CLEAR ITAB. ITAB-BUKRS = P0001-BURKS. ITAB-WERKS = P0001-WERKS. RP-READ-ALL-TIME-ITY PN/BEGDA PN/ENDDA. LOOP AT P2001. ITAB-AWART = P2001-AWART. ITAB-ASWTG = P2001-ASWTG. COLLECT ITAB. (OR: APPEND ITAB.) ENDLOOP.

HR ABAP - Payroll
Database Tables in HR Personnel Administration (PA) - master and time data infotype tables (transparent tables). PAnnnn: e.g. PA0001 for infotype 0001 Personnel Development (PD) - Org Unit, Job, Position, etc. (transparent tables). HRPnnnn: e.g. HRP1000 for infotype 1000 Time/Travel expense/Payroll/Applicant Tracking data/HR work areas/Documents (cluster PCLn: e.g. PCL2 for time/payroll results. Cluster Table Cluster tables combine the data from several tables with identical (or almost identical) keys into one physical record on the database. . Data is written to a database in compressed form. Retrieval of data is very fast if the primary key is known. Cluster tables are defined in the data dictionary as transparent tables. External programs can NOT interpret the data in a cluster table. Special language elements EXPORT TO DATABASE, IMPORT TO DATABASE and

DELETE FROM DATABASE are used to process data in the cluster tables. PCL1 PCL2 PCL3 PCL4 Database for HR work area; Accounting Results (time, travel expense and payroll); Applicant tracking data; Documents, Payroll year-end Tax data

Database Tables PCLn PCLn database tables are divided into subareas known as data clusters. Data Clusters are identified by a two-character code. e.g RU for US payroll result, B2 for time evaluation result... Each HR subarea has its own cluster. Each subarea has its own key. Database Table PCL1 The database table PCL1 contains the following data areas: B1 time events/PDC G1 group incentive wages L1 individual incentive wages PC personal calendar TE travel expenses/payroll results TS travel expenses/master data TX infotype texts ZI PDC interface -> cost account Database Table PCL2 The database table PCL2 contains the following data areas: B2 time accounting results CD cluster directory of the CD manager PS generated schemas PT texts for generated schemas RX payroll accounting results/international Rn payroll accounting results/country-specific ( n = HR country indicator ) ZL personal work schedule Database Table PCL3 The database table PCL3 contains the following data areas: AP action log / time schedule TY texts for applicant data infotypes Data Management of PCLn The ABAP commands IMPORT and EXPORT are used for management of read/write to database tables PCLn. A unique key has to be used when reading data from or writing data to the PCLn. Field Name KEY Length Text MANDT X 3 Client RELID X 2 Relation ID (RU,B2..) SRTFD X 40 Work Area Key SRTF2 X 4 Sort key for dup. key

Cluster Definition The data definition of a work area for PCLn is specified in separate programs which comply with fixed naming conventions. They are defined as INCLUDE programs (RPCnxxy0). The following naming convention applies: n = 1 or 2 (PCL1 or PCL2) xx = Relation ID (e.g. RX) y = 0 for international clusters or country indicator (T500L) for different country cluster Exporting Data (I) The EXPORT command causes one or more 'xy' KEY data objects to be written to cluster xy. The cluster definition is integrated with the INCLUDE statement. REPORT ZHREXPRT. TABLES: PCLn. INCLUDE: RPCnxxy0. "Cluster definition * Fill cluster KEY xy-key-field = <value>. * Fill data object .... * Export record EXPORT TABLE1 TO DATABASE PCLn(xy) ID xy-KEY. IF SY-SUBRC EQ 0. WRITE: / 'Update successful'. ENDIF. Exporting Data (II) . Export data using macro RP-EXP-Cn-xy. When data records are exported using macro, they are not written to the database but to a main memory buffer. To save data, use the PREPARE_UPDATE routine with the USING parameter 'V'. REPORT ZHREXPRT. *Buffer definition INCLUDE RPPPXD00. INCLUDE RPPPXM00. "Buffer management DATA: BEGIN OF COMMON PART 'BUFFER'. INCLUDE RPPPXD10. DATA: END OF COMMON PART 'BUFFER'. ... RP-EXP-Cn-xy. IF SY-SUBRC EQ 0. PERFORM PREPARE_UPDATE USING 'V'.. ENDIF. Importing Data (I) The IMPORT command causes data objects with the specified key values to be read from

PCLn. If the import is successful, SY-SUBRC is 0; if not, it is 4. REPORT RPIMPORT. TABLES: PCLn. INCLUDE RPCnxxy0. "Cluster definition * Fill cluster Key * Import record IMPORT TABLE1 FROM DATABASE PCLn(xy) ID xy-KEY. IF SY-SUBRC EQ 0. * Display data object ENDIF. Importing data (II) Import data using macro RP-IMP-Cn-xy. Check return code SY-SUBRC. If 0, it is successful. If 4, error. Need include buffer management routines RPPPXM00 REPORT RPIMPORT. *Buffer definition INCLUDE RPPPXD00. DATA: BEGIN OF COMMON PART 'BUFFER'. INCLUDE RPPPXD10. DATA: END OF COMMON PART 'BUFFER'. *import data to buffer RP-IMP-Cn-xy. .... *Buffer management routines INCLUDE RPPPXM00. Cluster Authorization Simple EXPORT/IMPORT statement does not check for cluster authorization. Use EXPORT/IMPORT via buffer, the buffer management routines check for cluster authorization. Payroll Results (I) Payroll results are stored in cluster Rn of PCL2 as field string and internal tables. n - country identifier. Standard reports read the results from cluster Rn. Report RPCLSTRn lists all payroll results; report RPCEDTn0 lists the results on a payroll form. Payroll Results (II) The cluster definition of payroll results is stored in two INLCUDE reports: include: rpc2rx09. "Definition Cluster Ru (I) include: rpc2ruu0. "Definition Cluster Ru (II) The first INCLUDE defines the country-independent part; The second INCLUDE defines the country-specific part (US). The cluster key is stored in the field string RX-KEY.

Payroll Results (III) All the field string and internal tables stored in PCL2 are defined in the ABAP/4 dictionary. This allows you to use the same structures in different definitions and nonetheless maintain data consistency. The structures for cluster definition comply with the name convention PCnnn. Unfortunately, 'nnn' can be any set of alphanumeric characters. *Key definition DATA: BEGIN OF RX-KEY. INCLUDE STRUCTURE PC200. DATA: END OF RX-KEY. *Payroll directory DATA: BEGIN OF RGDIR OCCURS 100. INCLUDE STRUCTURE PC261. DATA: END OF RGDIR. Payroll Cluster Directory To read payroll results, you need two keys: pernr and seqno . You can get SEQNO by importing the cluster directory (CD) first. REPORT ZHRIMPRT. TABLES: PERNR, PCL1, PCL2. INLCUDE: rpc2cd09. "definition cluster CD PARAMETERS: PERSON LIKE PERNR-PERNR. ... RP-INIT-BUFFER. *Import cluster Directory CD-KEY-PERNR = PERNR-PERNR. RP-IMP-C2-CU. CHECK SY-SUBRC = 0. LOOP AT RGDIR. RX-KEY-PERNR = PERSON. UNPACK RGDIR-SEQNR TO RX-KEY-SEQNO. *Import data from PCL2 RP-IMP-C2-RU. INLCUDE: RPPPXM00. "PCL1/PCL2 BUFFER HANDLING Function Module (I) CD_EVALUATION_PERIODS After importing the payroll directory, which record to read is up to the programmer. Each payroll result has a status. 'P' - previous result 'A' - current (actual) result 'O' - old result Function module CD_EVALUATION_PERIODS will restore the payroll result status for a period

when that payroll is initially run. It also will select all the relevant periods to be evaluated. Function Module (II) CD_EVALUATION_PERIODS call function 'CD_EVALUATION_PERIODS' exporting bonus_date = ref_periods-bondt inper_modif = pn-permo inper = ref_periods-inper pay_type = ref_periods-payty pay_ident = ref_periods-payid tables rgdir = rgdir evpdir = evp iabkrs = pnpabkrs exceptions no_record_found = 1. Authorization Check Authorization for Persons In the authorization check for persons, the system determines whether the user has the authorizations required for the organizational features of the employees selected with GET PERNR. Employees for which the user has no authorization are skipped and appear in a list at the end of the report. Authorization object: 'HR: Master data' Authorization for Data In the authorization check for data, the system determines whether the user is authorized to read the infotypes specified in the report. If the authorization for a particular infotype is missing, the evaluation is terminated and an error message is displayed. Deactivating the Authorization Check In certain reports, it may be useful to deactivate the authorization check in order to improve performance. (e.g. when running payroll) You can store this information in the object 'HR: Reporting'.

You might also like