Entering content frameStructure of Logical Databases Locate the document in its SAP Library structure

A logical database is made up of three components (see illustration for further details). They are:

The structure defines the data view of the logical database. It determines the structure of the other components and the behavior of the logical database at runtime. The order in which data is made available to the user depends on the hierarchical structure of the logical database concerned.

The selections define a selection screen, which forms the user interface of the executable programs that use the logical database. Its layout is usually determined by the structure. You can adapt the selections to your own requirements and also add new ones. When you link a logical database to an executable program, the selections of the logical database become part of the standard selection screen of the program (screen number 1000). If you call a logical database using the function module LDB_PROCESS, the selections are filled using interface parameters.

The database program contains the ABAP statements used to read the data and pass it to the user of the logical database. The structure of the database program is a collection of special subroutines. It is determined by the structure and the selections. You can adapt the database program to your own requirements and also extend it.

Other components such as documentation, language-specific texts, and user-defined selection screens extend the functions further.

Structure

The structure of a logical database is usually based on the foreign key relationships between hierarchical tables in the R/3 System. Logical databases have a tree-like structure, which can be defined as follows:

· There is a single node at the highest level. This is known as the root node.

· Each node can have one or several branches.

· Each node is derived from one other node.

The nodes must be structures defined in the ABAP Dictionary or data types from a type group. Normally, these are the structures of database tables which the logical database reads and passes to the user for further evaluation. However, it is also possible, and sometimes useful, to use ABAP Dictionary structures without an underlying database. For technical reasons, the maximum number of nodes allowed in the structure of a logical database is 300.

Any executable ABAP program that has a logical database linked to it can contain a GET statement for each node of the structure. When you run the program, the corresponding event blocks are processed in the sequence prescribed by the hierarchical structure of the logical database. If a program does not contain a GET statement for every node of a logical database, the processing passes through all the nodes that lie in the path from the root to the nodes specified by GET statements.

If you call a logical database using the function module LDB_PROCESS, the depth to which the system reads is controlled by an interface parameter.

Example

Suppose LFA1 is the root node, LFBK and LFB1 are branches of LFA1, and LFC1 is a branch of LFB1.

This graphic is explained in the accompanying text

If the executable program contains GET statements for all nodes, the GET events are executed in the order LFA1, LFBK, LFB1, LFC1. If the program only contains a single GET statement for LFB1, the processing only passes through LFA1 and LFB1.

Selections

The selections in a logical database are defined using the normal statements for defining selection screens, that is, PARAMETERS, SELECT-OPTIONS; and SELECTION-SCREEN. In a logical database, you can also use the additions VALUE-REQUEST and HELP-REQUEST to define specific input and value help. You define the selection screen in a special include program known as the selection include.

When you write programs using a logical database, you can also add your own selections. The standard selection screen then contains the database-specific selections, followed by the program-specific selections that you have defined.

When the system generates the selection screen for an executable program, database-specific selection criteria and parameters are only displayed if you have declared an interface work area for them in your program using the NODES or TABLES statement.

Example

Suppose you have a selection include containing the following lines:

SELECT-OPTIONS SLIFNR FOR LFA1-LIFNR.
PARAMETERS PBUKRS LIKE LFB1-BUKRS FOR TABLE LFB1.

The selection criterion SLIFNR is linked to table LFA1, the parameter PBUKRS to table LFB1. If the TABLES statement in an executable program (report) declares LFA1 but not LFB1, SLIFNR is displayed on the selection screen, but PBUKRS does not appear.

The selection screen of a logical database can contain dynamic selections as well as static ones. Dynamic selections are extra, user-defined selections that the user can make as well as using the static selections defined in the selection include. To improve performance, you should always use this option instead of reading more data than you need and then sorting it out in the application program.

To make dynamic selections available for the node <node> of a logical database, the selection include must contain the following statement:

SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE|TABLE <node>.

If the node <node> is requested by the user of the logical databases, the dynamic selections are included in the selection screen. A user can then choose Dynamic selections to enter extra selections for the corresponding fields. If you call the logical database using the function module LDB_PROCESS, you can pass a corresponding parameter. You can use these selections in dynamic statements in the logical database program to read data. The values of the program-specific selection criteria that you defined for a node for which dynamic selections were available are also passed to the logical database. The user can also define the fields for dynamic selections as a selection view for the logical database.

The selection screen of a logical database is part of the standard selection screen (number 1000) of the executable program to which the logical database is attached. It has a standardized layout - the selection criteria and parameters appear on separate lines in the order in which they were declared. You can change the layout using the SELECTION-SCREEN statement.

The runtime environment generates the selection screen with number 1000 for every program in which the attributes do not contain a different selection screen version. You can prevent certain input fields from the selection screen of a logical database from appearing on the selection screen by defining selection screen versions with a screen number lower than 1000 in the selection include, and entering this version number in the program attributes. By pressing F4 there, you can get an overview of the selection screen versions defined in the logical database concerned. To define a selection screen version, use the statements SELECTION-SCREEN BEGIN|END OF VERSION. Within these statements you can use SELECTION-SCREEN EXCLUDE to specify fields that you do not want to appear on the selection screen.

If the attributes of an executable program contain the number of a selection screen version, the version is used in the standard selection screen. Although the input fields that you excluded from the selection screen are not displayed, the corresponding selections still exist, and you can still edit them in the program or by calling the function module LDB_PROCESS.

Database Program

The name of the database program of a logical database <ldb> conforms to the naming convention SAPDB<ldb>. It serves as a container for subroutines, which the ABAP runtime environment calls when a logical database is processed. The sequence of the calls and their interaction with the events in executable programs or the function module LDB_PROCESS depends on the structure of the logical database.

A logical database program usually contains the following subroutines:

Called once only before the logical database is processed. It prepares it to be called more than once by the function module LDB_PROCESS.

Called once only before the selection screen is processed.

Called before the selection screen is displayed, each time it is displayed. Consequently, it is only called when you use the logical database with an executable program, not with the function module LDB_PROCESS.

Called when the user interacts with the selection screen. Consequently, it is only called when you use the logical database with an executable program, not with the function module LDB_PROCESS. The interface parameters FNAME and MARK are passed to the subroutine.

FNAME contains the name of a selection criterion or parameter on the selection screen.

MARK describes the selection made by the user: MARK = SPACE means that the user has entered a simple single value or range selection. MARK = '*' means that the user has also made entries on the Multiple Selection screen.

Called instead of the subroutine PAI if the logical database is called using the function module LDB_PROCESS without a selection screen. This subroutine can check the selections passed in the function module interface.

Called in the sequence defined in the structure. Reads the data from the node <node> and uses the

PUT <node>.

statement to trigger a corresponding GET event in the ABAP runtime environment. The PUT statement is the central statement in this subroutine: It can only be used within a subroutine of a logical database. The logical database must contain the node <node>, and the subroutine name must begin with PUT_<node>. The PUT statement directs the program flow according to the structure of the logical database. The depth to which the logical database is read is determined by the GET statements in the application program or the interface parameter CALLBACK of the function module LDB_PROCESS.

First, the subroutine PUT_<root> is executed for the root node. The PUT statement then directs the program flow as follows:

i) If the database program contains the subroutine AUTHORITY_CHECK_<table>, the first thing the PUT_<node> statement does is to call it.

ii) Next, the PUT statement triggers a GET event in the runtime environment. If there is a corresponding GET <node> statement in the executable program to which the logical database is linked, the associated event block is processed. If the CALLBACK parameter of the function module LDB_PROCESS is filled accordingly, the corresponding callback routine is called.

iii) The PUT statement then directs the program flow as follows:

(a) To the next subroutine of a node that follows directly, if a lower-level node (not necessarily the very next) in the same subtree is requested by GET in the executable program or in the function module.

(b) To the subroutine of a node at the same level, if the preceding node branches to such a node and if a GET statement exists for such a node in the executable program or the function module.

The PUT statement in that subroutine starts again at step (i). In the subroutine of the lowest node in a subtree to be processed using GET, the program control does not branch further. Instead, the current subroutine is processed further. When a subroutine PUT_<node> has been executed in its entirety, the program flow returns to the PUT statement from which it branched to the subroutine PUT_<node>.

iv) When control has returned from a lower-level subroutine PUT_<node>, the PUT statement triggers the event GET <node> LATE in the runtime environment.

Called automatically by the PUT <table> statement. In this subroutine, you can specify authorization checks for the appropriate node <table> from the structure of the logical database.

Called when the user makes a selection using a search help to process the key chosen in the search help. <ldba> is the name of the logical database. From this subroutine, you can use the entries in the search help tables to read the relevant entries from the root node <root>. The processing in the program can then be triggered using PUT <root>. The subroutine PUT_<root> is then not called automatically.

Called before an event, the name of which is passed in the parameter EVENT. Currently, the EVENT field can only contain the value START-OF-SELECTION, to call a subroutine before this event.

Called after an event, the name of which is passed in the parameter EVENT. Currently, the EVENT field can only contain the value END-OF-SELECTION, to call a subroutine after this event.

Called when the user calls possible values help for the parameter <par> or the selection criterion <selop>. These must belong to the selections in the logical database.

Called when the user calls input help for the parameter <par> or the selection criterion <selop>. These must belong to the selections in the logical database.

Example

Example

Suppose that in the logical database structure, LFB1 is a branch of LFA1,

and that the following selection criteria are defined in the selection include:

SELECT-OPTIONS: SLIFNR FOR LFA1-LIFNR,
                SBUKRS FOR LFB1-BUKRS.

A section of the database program would then read:

FORM PUT_LFA1.
  SELECT * FROM LFA1
           WHERE LIFNR IN SLIFNR.
    PUT LFA1.
  ENDSELECT.
ENDFORM.

FORM PUT_LFB1.
  SELECT * FROM LFB1
           WHERE LIFNR =  LFA1-LIFNR.
           AND   BUKRS IN SBUKRS.
    PUT LFB1.
  ENDSELECT.
ENDFORM.

An executable program (report) linked to the logical database could contain the lines:

GET LFA1.
  WRITE LFA1-LIFNR.

GET LFB1.
  WRITE LFB1-BUKRS.

In this example, the runtime environment calls the routine PUT_LFA1 after the event START-OF-SELECTION. The event GET LFA1 is triggered by the statement PUT LFA1. Once the corresponding event block in the program is complete, PUT LFA1 branches to the subroutine PUT_LFB1. From this subroutine, the event GET LFB1 is triggered in the application program. If LFB1 is the last node to be read, processing resumes with the SELECT loop in PUT_LFB1. Otherwise, the program flow moves to the subroutine PUT_<node> of the next node. At the end of the SELECT loop of the last node, processing resumes in the SELECT loop of the node at the next level up. The example of programming using nested SELECT loops is only used to make the program flow clearer. In a real logical database, you would avoid doing this in order to minimize the number of database accesses.

The following diagram shows the program flow:

This graphic is explained in the accompanying text

In this example, the PUT statements do not branch to the authorization check subroutines.

 

 

 

 

Leaving content frame