Logical Database

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Topic Objectives

Logical Databases and usage

In this section, we will Explain Logical Databases Describe Report Driven Reading of Vendor Master Data Describe Reading Data Compare Logical Databases v. Select Define the structure of a Logical Database Explain Event Keywords Describe the interaction of Logical Databases and Reports

What are Logical Databases?


Database within a database, but logically stored within existing (physical) tables. Physical Database

Logical Database

Logical Database

Logical Database

Logical databases are special ABAP programs that retrieve data and make it available to application programs. The most common use of logical databases is still to read data from database tables by linking them to executable ABAP programs. Logical databases contain Open SQL statements that read data from the database. You do not therefore need to use SQL in your own programs. The logical database reads the program, stores them in the program if necessary, and then passes them line by line to the application program or the function module LDB_PROCESS using an interface work area.

Logical Databases - Views of Data


A logical database provides a particular view of database tables in the R/3 System. It is always worth using logical databases if the structure of the data that you want to read corresponds to a view available through a logical database. 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. Logical databases read data from database tables that are part of these structures.

The diagram illustrates how the R/3 System might represent the structure of a company. A logical database can read the lines of these tables one after the other into an executable program in a sequence which is normally defined by the hierarchical structure. The term logical database is sometimes used to mean not only the program itself, but also the data that it can procure.

Tasks of Logical Databases Reading the same data for several programs. Defining the same user interface for several programs. Central authorization checks Improving performance

Structure of a Logical Database


Logical Databases: Display Structure of KDF

LFA1 LFAS LFBK LFB1 LFB5 LFC1 LFC3 BSIK BKPF BSEG GSEG GSEG LFAS LFBK LFB1

Vendor master data


LFA1

Documents
BSIK BKPF BSEG

LFB5

LFC1

LFC3

Reading Data

ABAP Dictionary

1
Logical Database
REPORT ... . TABLES:SPFLI,SFLIGHT. GET SPFLI. GET SFLIGHT.

2
Without Logical Database
REPORT ... . TABLES: SPFLI,SFLIGHT. SELECT SPFLI. SELECT SFLIGHT. ....

Processing

Processing

Processing

.... ENDSELECT. ENDSELECT.

Event Key Words: Overview


START-OF-SELECTION Introduces any initial processing to be done prior to next event keyword (usually GET).

END-OF-SELECTION

Introduces any statements that are to be processed after all logical database records have been read and processed. Retrieves the table <dbtab> for processing via the logical database program SAPD<db><a>. Introduces statements that are only processed once subordinate tables have been read and processed. These statements are processed before the next loop is performed.

GET <dbtab>

GET <dbtab> LATE

Interaction of Logical Databases and Report


Read program
LFA1

KDF
REPORT RSDEMO00. TABLES: LFA1, LFBK, LFB5 . GET LFA1.

Logical database KDF


LFB1

REPORT SAPDBKDF... FORM PUT LFA1 . SELECT * FROM LFA1... . PUT LFA1 . ENDSELECT . ENDFORM . FORM PUT_LFBK . SELECT * FROM LFBK... . PUT LFBK. ENDSELECT. ENDFORM. FORM PUT_LFB1. SELECT * FROM LFB1... . PUT LFB1. ENDSELECT. ENDFORM. FORM PUT_LFB5. SELECT * FROM LFB5... . PUT LFB5. ENDSELECT. ENDFORM.

LFBK

LFB5

LFC1

LFC3

BSIK

GET LFBK.

GET LFB5.

Overview: Events in the Context of Logical Databases


START-OF-SELECTION
1 GET LFA1 1 2 LFB1 LFA1 5 1 LFA1 5 2 GET LFB1 3 GET LFC1 4 GET LFB1 LATE 5 GET LFA1 LATE

4 2 LFB1 4

LFC1 LFC1 LFC1 3 3 3

LFC1 LFC1 3 3

END-OF-SELECTION

Report-Driven Reading of Vendor Master Data


REPORT ZZ70D121. TABLES: LFA1, LFB1, LFC3. SELECT * FROM LFA1 WHERE LIFNR ...
Processing LFA1

SELECT * FROM LFB1 WHERE LIFNR = LFA1-LIFNR.


Processing LFB1

SELECT * FROM LFC3 WHERE LIFNR = LFA1-LIFNR AND BUKRS = LFB1-BUKRS.


Processing LFC3

ENDSELECT. ENDSELECT. ENDSELECT.

The STOP Statement


REPORT ZZ70D124. TABLES: LFA1. DATA: COUNTER TYPE I. GET LFA1. WRITE: GET LFA1, 15 LFA1-LIFNR, LFA1-NAME. COUNTER = COUNTER + 1. SKIP. IF COUNTER > 1. STOP. ENDIF. END-OF-SELECTION. WRITE: / END-OF-SELECTION, TEXT-001. * TEXT-001: Thats it buddy !.

Logical Database vs. Select


GET
The functional connection already exists Beginners can find the database they are after easier The logic is reusable Select-Options are flexible Authority check is made automatically

SELECT
Faster than logical databases More powerful than logical databases select into order by More flexible More specific coding is easier work for the database.

BUT:
Logical databases are slower Changes to a logical database affect all programs that use it

BUT:
; Authority check missing ; Parameters for selectoptions have to be coded

Classic Scenario verses Function Module LDB_PROCESS


Classic Scenario

LDB_PROCESS

You might also like