Anda di halaman 1dari 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 Logical Logical


Database Database 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 Vendor master data


LFA1
LFB1

LFB5
LFAS LFBK LFB1 Documents
LFC1

LFC3 LFC3 BSIK


LFB5 LFC1

BSIK BKPF

BKPF
BSEG
BSEG
GSEG
GSEG
Reading Data

ABAP Dictionary
1 2
Logical Database Without Logical
Database
REPORT ... .
TABLES:SPFLI,SFLIGHT. REPORT ... .
GET SPFLI. TABLES: SPFLI,SFLIGHT.
SELECT SPFLI.
Processing SELECT SFLIGHT.
GET SFLIGHT.
.... 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.

GET <dbtab> Retrieves the table <dbtab> for


processing via the logical database
program SAPD<db><a>.

GET <dbtab> LATE Introduces statements that are only processed


once subordinate tables have been read and
processed. These statements are processed
before the next loop is performed.
Interaction of Logical Databases and Report
Read program KDF
Logical REPORT SAPDBKDF... REPORT RSDEMO00.
LFA1
database KDF FORM PUT LFA1 .
SELECT * FROM LFA1... . TABLES: LFA1,
PUT LFA1 . LFBK,
LFBK LFB1
ENDSELECT . LFB5 .
ENDFORM . GET LFA1.
FORM PUT_LFBK .
LFB5 LFC1 LFC3 BSIK SELECT * FROM LFBK... .
PUT LFBK. GET LFBK.
ENDSELECT.
ENDFORM.
FORM PUT_LFB1.
SELECT * FROM LFB1... .
PUT LFB1.
ENDSELECT.
ENDFORM.
FORM PUT_LFB5.
SELECT * FROM LFB5... .
PUT LFB5. GET LFB5.
ENDSELECT.
ENDFORM.
Overview: Events in the Context of Logical
Databases

START-OF-SELECTION

1 GET LFA1
1 LFA1 5 1 LFA1 5
2 GET LFB1
2 LFB1 4 2 LFB1 4
3 GET LFC1

4 GET LFB1 LATE


LFC1 LFC1 LFC1 LFC1 LFC1
3 3 3 3 3 5 GET LFA1 LATE

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: ‘That’s it buddy !’.
Logical Database vs. Select
GET SELECT
• The functional connection • Faster than logical databases
already exists • More powerful than logical
• Beginners can find the databases -
database they are after – select into
easier – order by
• The logic is reusable • More flexible
• Select-Options are flexible • More specific coding is easier
• Authority check is made work for the database.
automatically

BUT: BUT:
Logical databases are slower ; Authority check missing
Changes to a logical database ; Parameters for select-
affect all programs that use it options have to be
coded
Classic Scenario verses Function Module
LDB_PROCESS

Classic Scenario

LDB_PROCESS

Anda mungkin juga menyukai