You are on page 1of 50

SAP ABAP HR TRAINING

Topics
1. What is HR and SAP-HR Concepts & Components 2. Why HR ABAP is different from normal ABAP. 3. Logical Databases and other HR related tables 4. Overview on HR Macros 5. Programming using Logical data bases and Macros

6. Report Categories

What is HR
The task of Human Resource Management is to produce the organizational hierarchies , relationship between employees and to allow storage and administration of employee data

SAP HR Components
PA Personnel Administration and Payroll Accounting PD Personnel Planning and Development.

Components of PA (Personnel administration)


Personnel Administration - Master Data: Administration of all personnel data Hire data Organization assignment data Leave Administration Compensation & Benefits Payroll & Time Data Work Schedule Planning Data Salary Administration Appraisal

Components of PD (Plannning and Development)


Organizational Management Seminar and Convention Mgt Personnel Development Work force Planning Room Reservation Planning

The Organizational Assignment in PA


Enterprise Structure Personnel Structure and Org.Plan

The company structure or Enterprise Structure is divided into :


Company code Personnel area Personnel Sub-area

The Components in Personnel Structure are administrative :


Employee Group, Employee Subgroup Payroll area.

Organizational :
Job, Position and Organizational unit.

Why HR is different from other modules ?

The following concepts are defined in HR which differs this module with other Modules 1. Use of Infotypes 2. The use of Logical Database 3. Use of Macros 4. Storage and Access of data 5 Authorization checks

What is Infotype Why Infotype

10

Introduction to HR Infotype Concept


An infotype represents a group of related data fields, provide information structure, facilitates data entry, and allows time dependent storage. In other words we can say infotypes are information units used to enter the time dependent data of the employee. Master data in HR is stored in infotypes. Each infotype pertains to a specific type of data. Each infotype has a database table associated with it.

For example, these are the frequently used infotypes. -Actions: Infotype 0000 stores all actions for an employee.
-Org Assignment: 0001 stores all information on employees Organization Specific status

-Personnel Data: 0002 stores all information on name, birth date, Sex etc.
-Basic Pay: 0008 stores all information on pay for employee. For each employee, there can be many records stored in each infotype, each with a start and end date.

11

Introduction to HR Infotype Concept


The key of each infotype record is: - Client Represents the system No.

- Personnel number - the personnel number is the only unique key within a client
for identifying an employee. It is used to access the display and maintenance screens for an employees master data and working time data (infotypes). subtypes are subdivisions of infotypes. An infotypes subtypes can have different time constraints and form their own histories.

- Subtype -

- Object identification - the object identification is used to make a distinction


between records with the same infotype For example, the child number in infotype 0021 Family/Related Person.

12

Introduction to HR Infotype Concept


The key of each infotype record is: - Lock Indicator - the lock indicator for HR master data is used to lock and unlock
data records, which enables the double verification principle to be put into practice. In accordance with this principle, at least two users are involved in the process of writing an active data record to the database. One of the users creates a locked infotype record, and the other user unlocks - that is, activates the data record.

- End Date - end date. - Start Date Start date


- Sequential Number - is used to make a distinction between infotype records that have the same key and time constraint '3' (any number of valid infotype data records at any one time). Unlike the object identification, it is assigned by the system automatically Note: Structure PAKEY should never be changed 13

Introduction to HR Infotype Concept


Personnel Planning Infotypes
Structure: HRIKEY MANDT: This field contains the clients. PLVAR: It is a two-character alphanumeric Key for the plan versions that enables us to differentiate between alternative plan versions. OTYPE: This field contains the object type key, which is a maximum of two alphanumeric characters in length. OBJID: This field contains an eight-digit key that represents a single object. SUBTY: Contains specification of sub type ISTAT: This field is one-digit numeric key in which the planning status is indicated. There is a status for all objects and for the infotypes that describe them. BEGDA: This contains start date of the validity period ENDDA: This contains end date of the validity period VARYF: This contains the target object of a relationship SEQNR: This specifies a sequence number for Infotypes of time constraint class 3.
14

Introduction to HR Infotype Concept


Time constraints:
Enable you to determine how the validity periods of Infotype data records interact. TC 1: Exactly one valid data record of the infotype in question must exist for the entire time that the employee belongs to the enterprise. Ex: IT 0001 Org.Assignment

TC 2: No more than one valid data record of the infotype in question can exist at any one time. Ex: IT 0032 Internal Data
TC 3: Any number of valid data records of the infotype in question can exist at any one time. EX: IT0022 - Education TC A: Infotype exists just once from Jan.1 1800 to Dec.12 9999 Ex: IT 0003 Payroll Status TC T :Time constraint is based on subtype or subtype table Ex: IT 0008 Basic pay 15

Programming using Logical Databases


Important core topic in HR programming. To reduce programming Efforts, it often helps to use the logical databases when creating reports. Logical databases are special ABAP Programs that provide selection screens, additional features and so on. The LDB usually consists of the following components. 1. Structure 2. Selections 3. Database programs Functions of LDB: Data retrieval | Screening | Authorization check
Logical Databases used In HR: PAP PNP PNPCE - Enhanced version of PNP available form SAP Enterprise version onwards PCH PTRVP The LDB PAP is for Applicant administration, PNP and PNPCE for Personnel Management, PCH for Organisational Management and PTVRP for Travel Management. The Logical Databases PNP/PNPCE and PCH are mostly used.

16

Programming using Logical Databases


Default Selection Screen provided by PNP.

17

Programming using Logical Databases


In program attributes, enter the following under logical database.

18

Programming using Logical Databases With out LDB


Reading Infotypes Without Logical DB (1)

PAnnnn
INFOTYPES: <nnnn>. ... CALL FUNCTION 'HR_READ_INFOTYPE'...

SAP AG 1999

You can also read infotype records for a particular personnel number without using the logical database. To do this, use the function module HR_READ_INFOTYPE. However, you must ensure that the internal table for the required infotype is declared with the INFOTYPE statement.
19

Programming using Logical Databases With out LDB


Reading Infotypes Without Logical DB (1)

Reading Infotypes Without Logical DB (2)

INFOTYPES: 0002. PAnnnn DATA: return LIKE SY-SUBRC.


INFOTYPES: <nnnn>. CALL FUNCTION 'HR_READ_INFOTYPE' ... EXPORTING CALL FUNCTION . . . 'HR_READ_INFOTYPE'... PERNR = <person> INFTY = '0002' BEGDA = <begdat> ENDDA = <enddat>

SAP AG 1999

IMPORTING SUBRC TABLES INFTY_TAB EXCEPTIONS INFTY_NOT_FOUND OTHERS

= return = P0002 = 1 = 2.

SAP AG 1999

20

Programming using Logical Databases


Example of an HR report HR report that uses the logical database uses the following basic structure: Report zdemo01. Tables: PERNR. INFOTYPES: 0001. GET PERNR. PROVIDE * FROM P0001 BETWEEN PN-BEGDA AND PN-ENDDA. WRITE: / P0001-PERNR, P0001-STELL, P0001-BEGDA, P0001-ENDDA. ENDPROVIDE. The above report evaluates the Organizational assignment infotype records in the specified data selection period.

21

Programming using Logical Databases


Infotype Declaration.
All infotypes to be processed in the report are listed in the ABAP INFOTYPES keyword.
The database usually contains several records with different validity periods and not just one record for each infotype and personnel number. Infotypes are time-dependent since their data changes over time. For this reason, one structure or work are would not suffice for the provision of infotype data in the main memory. Therefore the INFOTYPES statement is used to create an internal table for each of the listed infotypes. The structure of this table corresponds to that of the relevant infotype.

22

Programming using Logical Databases


Data Retrieval
Data is retrieved at the GET PERNR event. The GET PERNR action is executed for all personnel numbers that were selected on the basis of selection screen entries. GET PERNR fills the internal tables of infotypes that are declared for each employees using the INFOTYPES statement. The internal infotype table is filled with all records existing between the lowest and highest system date. The internal table has the name Pnnnn, where nnnn is the infotype number. The header of the internal table Pnnnn is undefined after the GET PERNR action. PERNR is a Data Dictionary structure without a database. You must declare this structure in the report using the TABLES statement.

23

Programming using Logical Databases


DATA STRUCTURES (PA-PAD).

Structure of Infotypes.
The Data dictionary contains Pnnnn corresponds to the table PAnnnn. The infotype is defined in the Data Dictionary as a structure without a database. The Pnnnn structure of the infotype is used as the field structure for the infotype entry screen. The effect of INFOTYPES statement is that it will create an internal table Pnnnn as follows:

DATA BEGIN OF Pnnnn OCCURS 10. INCLUDE STRUCTURE Pnnnn. DATA END OF Pnnnn VALID BETWEEN BEGDA AND ENDDA. (eg) INFOTYPES 0001.
The infotype records can be processed using the infotype structure when the report is run. PERNR structure. 24

Programming using Logical Databases


DATA STRUCTURES (PA-PAD).

Event keywords for data retrieval from a logical database have the following syntax. GET <TABLE>.
The logical HR database used the table PERNR. You must declare it in the TABLES statement. At the GET PERNR event, the PERNR structure contains the data for a personnel number chosen on the basis for selection screen entries. The PERNR-PERNR field contains the personnel number which is selected for processing. Only the PERNR-PERNR field should be read from the work area of the PERNR table. The other fields are intended for internal use only.

25

Programming using Logical Databases


JOIN

A join processes records from two or more infotypes. The data from these infotypes is provided for a specific partial period. To know in which time period an employee worked at which job at which address he or she resided during this time. The following addresses data is available: Jan March California April June Stamford The following work center data is available: Jan April Developer May November Team Lead If the address and work center data are provided for specific partial periods, the following cases. Jan Feb California / Developer March October Stamford / Team Leader.
The following program will fetch the results.
26

Programming using Logical Databases


JOIN REPORT ZTEST_JOIN. TABLES: PERNR. INFOTYPES: 0001, 0006. GET PERNR. PROVIDE * FROM P0001 * FROM P0006 BETWEEN PN-BEGDA AND PN-ENDDA. WHERE P0006-SUBTY = 1. WRITE: / PERNR-PERNR, P0001-STELL, P0006-STRAS,P0006-BEGDA, P0006-ENDDA. ENDPROVIDE.

Note: Changing data in any one of the infotypes linked by a join causes a split in the selection period.
27

Programming using Logical Databases Projection

An employee has worked as developed for 2 years in the three different personnel areas. The following organizational assignment data is available. Jan 2001 Jan 2002 Jan 2003 - Dec 2001 Developer / Personnel area 1. - Dec 2002 Developer / Personnel area 2. -Dec 2003 Developer / Personnel area 3.

28

Programming using Logical Databases

If we only require the time period during which an employee performs a specific job and not the personnel area for an evaluation, the following applies. January 2003 to Dec 2003 Developer.

REPORT ZTEST_PROJECTION. TABLES: PERNR. INFOTYPES: 0001. GET PERNR. PROVIDE STELL FROM P0001 BETWEEN PN-BEGDA AND PNENDDA. WRITE: / PERNR-PERNR, P0001-STELL, P0001-BEGDA, P0001-ENDDA. ENDPROVIDE.

29

Programming using Logical Databases


Join and Projection.
Data from Several Infotypes and the fields. Tables: pernr. Infotypes: 0001, 0002. GET PERNR. PROVIDE STELL ENAME FROM P0001 GBDAT FROM P0002 BETWEEN PN-BEGDA PN-ENDDA. WRITE:.. ENDPROVIDE.

30

Programming using Logical Databases


PAP applicant master data.
Example of a report in HR recruitment. HR report which uses the logical database has the following basic structure: REPORT ZTEST_BASE_STRUCTURE. TABLES: APPLICANT. INFOTYPES: 0001. GET APPLICANT. PROVIDE * FROM P0001 BETWEEN PA$BEGDA AND PA$ENDDA. WRITE: / P0001-PERNR, P0001-ENAME, P0001-BEGDA, P0001-ENDDA. ENDPROVIDE. Data Retrieval. Data is retrieved at the GET APPLICANT event. The GET APPLICANT action is executed for all personnel numbers that were selected on the basis of selection screen entries. The event should therefore be viewed as a loop via the selected personnel numbers.

31

Programming using Logical Databases


GET APPLICANT fills the internal tables of infotypes that are declared for each employee using the INFOTYPES statement.

The internal infotype table is filled with all records existing between the lowest and highest system date. The internal table has the name Pnnnn, where nnnn is the infotype number.
The syntax is as follows: PROVIDE * FROM Pnnnn BETWEEN PA$BEGDA AND PA$ENDDA. WRITE: / Pnnnn-<FIELD>. ENDPROVIDE. The relationship between the infotype and the data selection period of the selection screen is established using the PA$BEGDA AND PA$ENDDA variables. Often only require the most recent or earliest infotype record, not all infotype records. In this case, use one of the following statements: PAP_PROVIDE_FROM_LAST Pnnnn SPACE PA$BEGDA PA$ENDDDA. (or) PAP_PROVIDE_FROM_FRST Pnnnn SPACE PA$BEGDA PA$ENDDA. These statements make the newest or oldest record in the PA$BEGDA TO PA$ENDDA data selection period available in the structure Pnnnn.

32

Programming using Logical Databases


If the infotype has subtypes, replace the SPACE parameter by the appropriate subtype number. When a record has been successfully read, the return code PAP-SW-FOUND = 1. Sample report: REPORT ZTEST_APPLICANT_DATA. TABLES: APPLICANT. INFOTYPES: 0001. GET APPLICANT. PAP_PROVIDE_FROM_FIRST P0001 SPACE PA$BEGDA PA$ENDDA. IF PAP_SW_FOUND eq 1. WRITE: / APPLICANT-APLNO, P0001-BUKRS, PA$BEGDA, PA$ENDDA. ELSE. REJECT. ENDIF. Structure of HR Recruitment tables: Recruitment data is stored in the transparent tables PBnnnn. Apart from the keys (client, applicant number, subtype, object ID, lock indicator, validity period, and sequential number), table PBnnnn only contains the data for the infotype in question.

33

Programming using Logical Databases


The APPLICANT-APPLNO field should be read from the work area of the APPLICANT TABLE. The other fields are intended for internal use only. Default screen for PAP logical database.

34

Programming using Logical Databases


ORGANIZATIONAL MANAGEMENT DATA. PCH Personnel Planning. Used to retrieve data from Org Management Infotypes. Sample Report: REPORT ZTEST_OM_PCH. TABLES: OBJEC. INFOTYPES: 1001. GET OBJEC. WRITE: / OBJEC-OBJID, OBJEC-STEXT. PROVIDE * FROM P1001 BETWEEN PCHBEGDA AND PCHENDDA. WRITE: / P1001-OBJID, P1001-RELAT, P1001-SOBID. ENDPROVIDE. To read up on Org Management Infotypes, go to HELP->SAP Library->Human Resources->HR Infotypes->Personnel Mgt->Org Management.

35

Programming using Logical Databases


o

Default screen for PCH Logical database.

36

Programming using Logical Databases


MACROS Macro contains some part of source code which it will be Useful for number of applications. The macro RP_PROVIDE_FROM_LAST retrieves the last(latest) data record which is valid in the data selection period. The macro RP_PROVIDE_FROM_FRST retrieves the first(start) data record which is valid in the data selection period. The macro RP-READ-INFOTYPE retrieves the data record(s) which is valid in the data selection period. For every macro, whether the operation was successful or not will be checked with PNP-SW-FOUND. If PNP-SW-FOUND = 1 , then the operation is successful.

37

Programming using Logical Databases


MACROS
Macro Modules

TABLES: PERNR. INFOTYPES: 0001, 0002, 0006, ....

"Organizational Assignment "Personal Data "Addresses

GET PERNR. RP_PROVIDE_FROM_LAST P0001 SPACE PN-BEGDA PN-ENDDA. WRITE...


* * * Include program DBPNPMAC. DEFINE RP_PROVIDE_FROM_LAST. PNP-SW-FOUND = '0'. . . . END-OF-DEFINITION.

SAP AG 1999

38

Programming using Logical Databases


MACROS

Example Report: Report Ztest_Macro. Tables: PERNR. INFOTYPES: 0001. GET PERNR. RP_PROVIDE_FROM_LAST P0001 SPACE PN-BEGDA PN-ENDDA. PNP-SW-FOUND = 1. write: / PERNR-PERNR, P0001-STELL, PN-BEGDA, PN-ENDDA. ELSE. REJECT. ENDIF.

39

Programming using Logical Databases


Reading Time Data

Infotypes 2000 to 2999 are time infotypes. They are stored in tables PA2000 to PA2999. Infotypes are declared with the INFOTYPE statement, and data is made available for processing in the internal infotype tables (infotype 2011 is an exception). You should not load all the infotype records from the earliest to most recent system dates into the main memory. This would quickly lead to memory overload, especially if a front-end time recording system is connected to the HR system. That is why time data should be read only for a specific period. Use the infotype declaration supplement MODE N to define that the internal time infotype tables should be declared but not filled at the GET PERNR event. Time infotype tables are processed with the LOOP statement since the PROVIDE statement limits, and thus changes, the infotype start and end dates to the data selection period.

40

Programming using Logical Databases


Importing Time Data

Using Macro RP_READ_ALL_TIME_ITY PN-BEGDA PN-ENDDA To control the amount of time required to read time infotypes, MODE N Is assigned to the infotypes in declaration. The time infotype tables are subsequently filled using the RP_READ_ALL_TIME_ITY macro, however, only in the specified period.

41

Programming using Logical Databases


Some important fields PERNR Personnel Number WERKS Personnel Area BTRTL Personnel Subarea PERSG Employee Group PERSK Employee Subgroup ABKRS Payroll Area LGART Wage Type BETRG Amount ANZHL Number MOLGA Country code BEGDA Start Date ENDDA End Date MOABW Personnel subarea grouping for absence and attendance types

42

Report Categories

You can create your own report categories for your report programming Using Logical Database PNP. Instead of standard PNP logical data base selection screen, your own selection Will appear .

43

Report Categories
Go to Attributes click HR Report Category Button.

44

Report Categories
It takes you to report categories maintenance view, press new entries

45

Report Categories
It takes you to report categories maintenance view, press new entries Give the Report Category Name and save.

46

Report Categories
Double click the Allowable Selection Criteria in left hand side. Give your own selection options.

47

Report Categories
Save the entries.

48

Report Categories
Go to SE38 and execute the program , you can see your own Selected Selection screen options.

49

End of Session

50

You might also like