You are on page 1of 32

Logical Database

What is 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.

Logical Databases - Views of Data


A logical database provides a particular view of database tables in the R/3 System. The data structure in a logical database is hierarchical. Many tables in the R/3 System are linked to each other using foreign key relationships. Some of these dependencies form tree-like hierarchical structures. LDBs read data from database tables that are part of these structures.

Using LDB
There are two ways of using a LDB : By linking it with an executable program. By using the function module LDB_PROCESS in any ABAP program.

Linking LDB with executable program


By entering the name of the logical database in the program attributes The subroutines of the logical database program and the event blocks of the executable program form a modularized program for reading and processing data. The runtime sequence is controlled by the structure, selections, and PUT statements in the LDB, and by the GET statements in the executable program.

Events in LDB Programming


GET GET LATE

GET Event
This is the most important event for executable programs that use a LDB. It occurs when the logical database has read a line from the node <table> and made it available to the program in the work area declared using the statement NODES <table>. You can process the data in the work area in this event block. For example, you can write it directly to a list, or store it in a sequential dataset (internal table or extract) so that you can process it later.

Get Late Event


This event is triggered when all of the data records for a node of the logical database have been read. You can use the event block for processing steps that should occur at the end of the block, like, for example, calculating statistics.

HR LDBs
PNP - Evaluates all HR Master Data and time data. PAP - Applicant Master Data PCH - Personnel Planning

Functions
Standard Selection Screen Data Retrieval Authorization check

Selection Screen

LDB provides a standard selection screen which gives standard look and feel throughout all programs

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.

Report Category
Selection Screen can be customised by use of Report Category Able to show/remove/hide certain standard selection criteria Able to set selection periods eg As At Date Able to turn Org Structure button on/off. In SE38 Change Program Attributes Click HR Report Category Create This button only appears in PNP

Report Category
Steps to create new: Click new entries Enter report category and description Check Org Structure allowed for org struc button Interval for Date period range. Double click Allowable Selection Criteria Click New Entries Select entries from pull down list

Report Category
Selections which are not available must be coded in your program as additional selection criteria. Save Back Include report category in your program Re-activate program Run and test it out.

Programming using LDB


An HR report which uses the LDB has the following basic structure. Report sample Tables: PERNR. INFOTYPES: 0001. GET PERNR. PROVIDE * from p0001 between pn-begda and pn-ennda. Write : / p0001-pernr, p0001-stell, p0001-begda. END PROVIDE.

PERNR
Pernr is a data dictionary structure without a database. You must declare this structure in the report using the tables statement.

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. 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.

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. It 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.

After the Get pernr event, the internal tables of the infotypes contain records and are ready for processing. Internal tables are generally processed line-by-line using the loop statement

Processing Infotype Records


Processing of infotype records is time-dependent, by this we mean dependent on the data selection and period entered on the processed at the same time and made available for a specific partial period. It is processed with the provide statement. The syntax is, Provide * from pnnnn between pn-begda and pnendda. Write : / pnnnn-field. Endprovide.

Nnnn stands for the four digit infotype number. The relationship between the infotype and the data selection period of the selection screen is established using the pn-begda and pn-endda variables. In the provide loop, the data of an infotype record is available for processing in the pnnnn structure.

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. Or RP-PROVIDE-FROM-FIRST pnnnn space pn-begda pn-endda.

These statements make the most recent of 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.

Example report
Report sample. Tables : pernr. Infotypes : 0001. Get pernr. RP-PROVIDE-FROM-LAST P0001 SPACE PN-BEGDA PN-ENDDA. If PNP-SW-FOUND = 1. Write : / p0001-stell, pn-begda, pn-endda. Else. Reject. Endif.

HR Transactions

HR Master Data
PA40 PA30 PA10 PA20 Personnel Events Maintain HR Master Data Personnel File Display HR Master Data

Applicant Master Data


PB10 PB20 PB30 PB40 Init.entry of applicant master data Display applicant master data Maintain applicant master data Applicant events

THANK YOU

You might also like