Entering content frameLinking to a Logical Database Locate the document in its SAP Library structure

When you create an executable program, you can specify the name of a logical database in its program attributes. A logical database is a special ABAP program that combines the contents of certain database tables. You can use a logical database with any number of executable programs. If you enter an asterisk (*) for the logical database, the system uses a standard database that controls the selection screen, but does not read any data.

Running Programs With and Without Logical Databases

When you run an executable program that has a logical database linked to it, the two programs function like a single executable program, whose processing blocks are called by the runtime environment in a particular order. For further details, refer to the diagram in the section Logical Databases and Contexts.

The main functions of a logical database are to call the selection screen and read data. If there is an appropriate logical database in the system, you no longer need to program these functions in your own executable program.

Executable programs that do not use a logical database, but define their own selection screen and read data using Open SQL statements are sometimes called SQL reports.

Some SQL reports have only one processing block - the default block START-OF-SELECTION. In this case (and only in this case), an executable program behaves like a classic sequentially-processed program. However, as soon as you process a selection screen in the program (for example, filling input fields or checking user input), you have to include further processing blocks (INITIALIZATION, AT SELECTION-SCREEN). If you use a logical database, the program is fully event-driven. The most important event used with logical databases is GET. In it, the logical database passes a database entry to the executable program.

For an overview of events and the sequence in which they are processed, refer to Event Blocks in Executable Programs. You can, of course, program your own database accesses using Open SQL in any event block.

Example

The following example compares two simple executable programs that read data from the hierarchical database tables SPFLI and SFLIGHT. One does not use a logical database, the other uses the logical database F1S. Both programs generate the same list.

Without logical database:

PROGRAM READ_TABLES.

DATA: WA_SPFLI TYPE SPFLI,
      WA_SFLIGHT TYPE SFLIGHT.

SELECT-OPTIONS: SEL_CARR FOR WA_SPFLI-CARRID,
                ...

SELECT CARRID CONNID CITYFROM CITYTO
       FROM SPFLI
       INTO CORRESPONDING FIELDS OF WA_SPFLI
       WHERE CARRID IN SEL_CARR.

  WRITE: / WA_SPFLI-CARRID,
           WA_SPFLI-CONNID,
           WA_SPFLI-CITYFROM,
           WA_SPFLI-CITYTO.

  SELECT FLDATE
         FROM SFLIGHT
         INTO CORRESPONDING FIELDS OF WA_SFLIGHT
         WHERE CARRID = WA_SPFLI-CARRID
           AND CONNID = WA_SPFLI-CONNID.

    WRITE: / WA_SFLIGHT-FLDATE.

  ENDSELECT.

ENDSELECT.

This program does not need any explicitly-declared processing blocks. All non-declarative statements automatically belong to the default event block START-OF-SELECTION. The selection screen, work areas for data, and the SELECT statements all have to be written in the program itself.

With logical database

This graphic is explained in the accompanying text

The logical database F1S is entered in the attributes of the executable program:

PROGRAM READ_TABLES.

NODES: SPFLI, SFLIGHT.

GET SPFLI FIELDS CARRID CONNID CITYFROM CITYTO.

  WRITE: / SPFLI-CARRID,
           SPFLI-CONNID,
           SPFLI-CITYFROM,
           SPFLI-CITYTO.

GET SFLIGHT FIELDS FLDATE.

  WRITE: / SFLIGHT-FLDATE.

If you compare this program with the one that does not use a logical database, you will see that it does not have to define a selection screen or read the data itself. These tasks are performed by the logical database. The NODES statement declares the work areas into which the logical database places the data that it reads.

Controlling the Logical Database from the Program

When you use a logical database, you can control the selection screen and the depth to which the logical database reads data. In the NODES statement, you specify the nodes of the logical database that you want to use in the program. The statement declares table work areas for these nodes in the program. These are data objects with the same name and structure as the corresponding node. The selection screen of the logical database only contains input fields for the nodes that you have declared in the NODES statement.

You control the depth to which the logical database reads data by defining GET event blocks. You do not have to program a GET event block for every node in the NODES statement. The logical database always reads the necessary data, that is, at least the key fields, for all nodes along the path from the root node to the lowest-level node for which a GET event block is defined. If you have not defined a particular node for processing, the logical database ignores it and all of its subordinate nodes.

Each GET event block knows both the fields of the current node and the fields that it has read from all of the nodes higher in the hierarchy along the current read path. At the end of a hierarchy level, the logical database resets the table work area in the program to HEX 00.

You can also change the depth to which the logical database is read by terminating a GET event block using the EXIT or CHECK statement. When you terminate a GET event, the logical database ignores any subordinate nodes in the hierarchy.

To control the amount of data read in a GET event block, use a field list in the GET statement. This only works if the relevant node in the logical database has been defined for field selections.

Example

Example of read depth using logical database F1S:

NODES: SPFLI, SFLIGHT, SBOOK.
  ...
  GET SPFLI.

The logical database does not read any data from the table SFLIGHT or SBOOK.

NODES: SPFLI, SBOOK.
  ...
  GET SBOOK.

The logical database reads data from the tables SPFLI and SFLIGHT, since they are on the access path for the node SBOOK. However, you cannot access data from SFLIGHT in the program.

Advantages of Using Logical Databases

Logical databases save you having to define a selection screen and read data from the database in every program. The program does not have to specify how to retrieve the data, but instead only has to process it and display it on the screen.

An executable program can only work with one logical database, but each logical database can be used by several programs. This offers considerable advantages over integrating the database accesses with SELECT statements into each executable program. It means that you only have to code identical access paths once. The same applies to coding authorization checks.

When you use logical databases, most executable programs benefit from having

· an easy-to-use and standard user interface

· check functions, which check that user input is complete, correct, and plausible

· meaningful data selection

· central authorization checks for database accesses

· good read access performance (for example, with views) while retaining the hierarchical data view determined by the application logic.

Even though you are using central logical databases, the program itself remains flexible because:

· You can still create your own selection screens for each program

· You can code your own functions in any event block in the program. For example, you may want to write user dialogs for further authorization or plausibility checks on the selection screen.

Programming Logical Databases

To create, edit, or display a logical database, use the Logical Database Builder in the ABAP Workbench (Transaction SLDB, or choose Tools ® ABAP Workbench, followed by Development ® Programming environment ® Logical databases. For further information about programming logical databases, refer to the section Logical Databases.

 

 

 

 

Leaving content frame