10
The ABAP HR is an integral part of ABAP. Generally in ABAP the following are done: 1) Table development 2) Date Processing 3) Report developing 4) BAPIs /RFC s 5) Data base update 6) Screens development/enhancement 7) Scripts and smart forms. 8) Function Building 9) Java connectors etc. The following concepts are defined in ABAP HR which is different with other modules. 1) Use of Infotypes 2) The use of Logical Database 3) Use of Macros and Provide statement 4) Storage and Access of data 5) Authorization checks There is nothing much difference between abap and hr abap. The way we retrieve the data from data base is deferent. In general ABAP data is stored in Tables, but coming to HR ABAP employee data is sorted through Infotypes. The way we retrieve the data from infotypes is deferent in hr abap. In general ABAP we use Logical data base very rare, as in HR ABAP most of the programs use Logical data base to select data from Infotypes by using Get event. In ABAP we use read statement to read particular record, still in HR ABAP we do use read statement apart from that we have Macros and provide statement.

The ABAP HR is an Integral Part of ABAP

Embed Size (px)

Citation preview

Page 1: The ABAP HR is an Integral Part of ABAP

The ABAP HR is an integral part of ABAP. Generally in ABAP the following are done:

1) Table development2) Date Processing3) Report developing4) BAPIs /RFC s5) Data base update6) Screens development/enhancement7) Scripts and smart forms.8) Function Building9) Java connectors etc.

The following concepts are defined in ABAP HR which is different with other modules.

1)  Use of Infotypes

2)  The use of Logical Database

3)  Use of Macros and Provide statement

4)  Storage and Access of data

5)  Authorization checks

There is nothing much difference between abap and hr abap. The way we retrieve the data from data base is deferent.

In general ABAP data is stored in Tables, but coming to HR ABAP employee data is sorted through Infotypes. The way we retrieve the data from infotypes is deferent in hr abap.

In general ABAP we use Logical data base very rare, as in HR ABAP most of the programs use Logical data base to select data from Infotypes by using Get event.

In ABAP we use read statement to read particular record, still in HR ABAP we do use read statement apart from that we have Macros and provide statement.

Macro is pre defined code (like function module) which reads data from internal table (internal infotype) based on dates.

Provide statement is like Select statement but selects data from internal table

Storage and access of data in hr abap is completely deferent in hr abap comparing with ABAP. We use transaction code PA20 and PA30 to maintain data in infotypes.

PA20 is display mode and PA30 is change mode. We can create, change, display, copy, and delete in Infotypes with PA30 transaction.

Page 2: The ABAP HR is an Integral Part of ABAP

For Infotypes authorizations can be maintained infotype and subtype (field) level as HR data is more sensitive and secrete.

Evaluating Repetitive Structures in SAP HR ABAP Programming

In many master data Infotypes, data is entered in table form. This, for example, allows you to enter up to forty different wage types and their amounts. By scrolling, you can enter up to forty wage types. The structure of the wage type line is stored in the Infotype structure P0008, and the individual fields are numbered from one to forty. This means that each field of the wage type table is defined.

A loop offers a more streamlined method of evaluation. Here, one line of the repeat structure is evaluated each time the loop is executed

As SAP consultant you might know the structures. But what is the repetitive structures?. The sentence it self explains that in a structure, some fields are available multiple times with the sequence number change, like fieldname01, fieldname02, fieldname03 etc…

For example In Master data Infotypes we have:Infotype 0008 (Basic Pay)Infotype 0025 (Appraisals)Infotype 0041 (Date Specifications)Infotype 0052 (Wage Maintenance)

If we look at Infotype 0008 below fields are getting repeated 40 times (Lower versions of SAP only 20 times like 4.6C).

LGA01 – wage type1BET01 – wage type AmountANZ01 – NumberEIN01 – Time/Measurement UnitOPK01 – Operation Indicator for Wage Types

LGA02 – wage type2BET02 – wage type amountANZ02 – NumberEIN02 – Time/Measurement UnitOPK02 – Operation Indicator for Wage Types

Till

LGA40 – wage type40BET40 – wage type amountANZ40 – NumberEIN40 – Time/Measurement UnitOPK40 – Operation Indicator for Wage Types

Page 3: The ABAP HR is an Integral Part of ABAP

For the above scenario we have multiple wage types for one Personnel number for one particular period. Viz... Basic Pay, House rent allowance, conveyance, special allowance, car allowance, salary exempt, salary non exempt (All these are wage types).For the above scenario wage types are stored in LGA01, LGA02, LGA03, LGA04, LGA05, LGA06, LGA07, and its amount correspondingly BET01, BET02, BET03, BET04, BET05, BET06, BET07. This is the brief overview about repetitive structures in SAP.

Now as a technical consultant your job starts. How do you read the data form repetitive structure Infotypes. For example we need to select basic wage from Infotype 0008 and display in report. We are not sure in which field the basic wage is going to be stored like it might be in LGA01 or LGA02 or LGA03 or LGA04. Here my question is, are we going to check 40 time IF condition for each field (LGA01 to LGA40). My answer is No. We have syntax in ABAP by using that we can achieve out target very easily.

Before going forward if you are new to ABAP HR, please go through the below Link:

SAP ABAP HR Program code using LDB PNP

The following Report shows you how to access these data fields. The example determines the wage type and its amount for particular period.

Data declarations: The required data declarations are first made at the beginning of theReport. Fields LGART and BETRG are required to read the repetitive structures.

Tables: PERNR is used to get the standard selection screen as well work area.Declare Tables: PERNR and press F8 you will get standard selection screen.

Infotypes: when we declare tables at the runtime of program will have work area the same way, when we declare Infotypes, will have internal table (we call as internal Infotype) with header with the structure of associated Infotype.

Macros:You often only require the most recent or earliest Infotype record, not all Infotype records. In this case, use one of the following statements:

RP_PROVIDE_FROM_LAST Pnnnn SPACE PN-BEGDA PN-ENDDA.

These statements make the most recent or earliest record in the PN/BEGDA to PN/ENDDA data selection period available in the structure Pnnnn for infotype nnnn.If the infotype has subtypes, replace the SPACE parameter by the appropriate subtype number.When a record has been successfully read, the return code PNP-SW-FOUND = 1 is returned.

Page 4: The ABAP HR is an Integral Part of ABAP

What is Logical Database?

Logical database in SAPThe LDB is special type of ABAP program that combines the contents of certain related database tables and retrieve some related data and make it available to application programs.

In other words, a LDB is a method by which ABAP programs read and process the data. The sequence in which the data is supplied to the program is determined by a tree structure.

The LDB usually consists of the following components:

StructureSelectionsDatabase programs

Logical databases have a tree structure. A logical database can contain a maximum of 300 tables

SAPDBPNP is the name of the database program for the logical database PNP.

How are logical database used

1. Logical databases when generating an ABAP program

The selection screen generated contains the selections (SELECT-OPTIONS AND PARAMETERS) of both the logical database and the program.

The only database-specific selections displayed on the selection screen are those needed by the program for data retrieval purposes

2. Logical databases at run-time of an ABAP program

At run-time, the system processes the events in the program and in the logical database in the following order

Before displaying the selection screen, certain initializations (e.g. calculating default values such as key date, etc.) are performed for the selection screen by the logical database and the program.The selection screen is displayed and the user enters data in the input fields.

The logical database and the program check that the input is correct and complete, but also that the user has the appropriate authorizations. If an error occurs, some fields are made ready for input again, so that the user can make the necessary correction(s).

In the event START-OF-SELECTION, the ABAP program performs any preliminary work (for ex, importing files).

Page 5: The ABAP HR is an Integral Part of ABAP

The logical database reads the selected data and the program processes it within the GET events according to the sequence specified by the structure.

In the event END-OF-SELECTION, the ABAP program performs any concluding operations (for example, calculating totals, exporting files).

3. Designing the selection screensThe standard selection screen of a logical database has a standard layout where SELECT-OPTIONS and PARAMETERS appear in the sequence they are declared, each on a new line. The system automatically generates such a screen for each program that does not have its own selection screen entered in the attributes.You can define your own selection screens for any logical database . If the attributes of a program include the number of its own selection screen, the system uses this screen as a model when generating. Any program-specific selections appear after the database selections. The flow logic for such screens is also generated automatically and therefore cannot be modified. You cannot delete database selections

Functions of LDB:

Data retrieval :

The personnel data of each employee is loaded into the main memory where it can be accessed for processing.

Screening:

Employees can be selected according to the organizational criteria entered on the selection screen.

E.g.…Hourly wage earners in a particular personnel sub area.There are two types of screening..Person selection and data selection period.

Person selection defines those employees for whom a report is to be run.

E.g.. Monthly wage earners in a specific personnel sub-area.E.g.. Personnel number rangeE.g... Features of org. Assignment…Employees who assigned to certain cost center.E.g. Employee status.Active or inactive.

The data selection period delimits the time period for which data is evaluated.When you enter the data selection period, the provide loop retrieves the infotype records whose validity period overlaps with at least one day of this period.

Authorization check:

This ensures that the person starting the evaluation Is authorized to access the report data.

Logical Data bases in HR ABAP:

Page 6: The ABAP HR is an Integral Part of ABAP

PNPPNPCEPAPPCH

Personnel Administration (PA):

PA involves administrating employee data, commonly referred to Master Data. Master Data contains all employee data used in HR processing. Master Data includes Personal (Eg. address), Organizational (Position description), Benefits (Insurance, Pension), Time & Payroll.Master Data is stored in Infotypes. Infotypes are tables (for user Data entry screen) that contain logically related employee data. Data can be stored for specific periods, which includes current and historical.

Components of PA:

• Personnel Area: represents a division of a company code into subunits. It is an organizational entity representing an area within an organization defined by specific aspects of personnel administration, time management and payroll. Personnel areas are subdivided into personnel subareas. Personnel area is specific to HR and is a four character alphanumeric identification. E.g. Personnel area 100 is for employees in Karnataka, 200 is for Chennai.

• Personnel Subarea: is a further subdivision of Personnel area. It may represent geographical locations. Functions include:1. Set groupings for Time Management, so that work schedules, substitution and absence and leave types can be setup for individual personnel subareas.2. Generate default pay scale type and area for an employee’s basic pay.3. Define public holiday calendar.

• Employee Groups: divides or groups employees into various categories. E.g. Active employees, Retired employees, Contractors. Employee groups are used to generate default values for payroll accounting area and basic pay.

• Employee Subgroups: are further differentiated within the employee group. Eg. Salaried employees, Hourly employees, unionized employees, Executives. The employee subgroup grouping for the payroll rule allows you to define different payroll procedures for different employee subgroups. For e.g. you can specify whether an employee’s pay should be determined on hourly or monthly basis. The employee subgroup grouping for the work schedule defines the validity of work schedule, and the attendance or absence quota type determines the validity of time quotas.

Page 7: The ABAP HR is an Integral Part of ABAP

Macros in HR-ABAP programming

Most commonly used Macros in ABAP-HR ?

Macro contains some part of source code which it will be useful for number of applications.( Like function modules )

Generally we use two macros in ABAP-HR or SAP-HRRP-PROVIDE-FROM-LASTRP-PROVIDE-FROM-FRST

Ex:RP-PROVIDE-FROM-LAST P0000 SPACE PN-BEGDA PN-ENDDA.IF PN-SW-FOUND = 1.WRITE YOUR CONDITION.ENDIF.

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.

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. ( same as sy-subrc but the value is in reverse case)

The macro RP-READ-INFOTYPE retrieves all the data record(s) which is valid in the data selection period.

If SY-SUBRC = 0 , then the process is successful.

All the Macros are stored in table TRMAC

Whenever you are using the macros like

RP-PROVIDE-FROM-LAST orRP-PROVIDE-FROM-FRST,

check whether you have included logical database PNP in program attributes.

It is not necessary to include logical database PNP/PNPCE in your program when you are using the macro like

RP-READ-INFOTYPE A B C D E , where

A corresponds to PERNR which describes for which personnel number you require records.

Page 8: The ABAP HR is an Integral Part of ABAP

B corresponds to INFOTYPE which describes from which infotype you require records.

C corresponds to data structure of the declared infotype (internal table like P0000 for infotype 0000) where all the records of the particular personnel number will be stored.

D corresponds to Start date.

E corresponds to End date.