Show TOC

Example of a Logical DatabaseLocate this document in the navigation structure

Let us consider the logical database TEST_LDB.

Structure

Selections in the Selection Include

SELECT-OPTIONS: slifnr   FOR lfa1-lifnr,                    sbukrs   FOR lfb1-bukrs,                    sgjahr   FOR lfc1-gjahr,                    sbelnr   FOR bkpf-belnr.

Database Program

*-------------------------------------------------------** DATABASE PROGRAM OF THE LOGICAL DATABASE TEST_LDB *-------------------------------------------------------*PROGRAM sapdbtest_ldb DEFINING DATABASE test_ldb. TABLES: lfa1,         lfb1,         lfc1,         bkpf.

*-------------------------------------------------------** Initialize selection screen (process before PBO) *-------------------------------------------------------*FORM init. ....ENDFORM.                                "INIT

*-------------------------------------------------------** PBO of selection screen (always before selection * screen *-------------------------------------------------------*FORM pbo.  ....ENDFORM.                                "PBO

*-------------------------------------------------------** PAI of selection screen (process always after ENTER) *-------------------------------------------------------*FORM pai USING fname mark.   CASE fname.    WHEN 'SLIFNR'.     ....    WHEN 'SBUKRS'.     ....    WHEN 'SGJAHR'.     ....    WHEN 'SBELNR'.     ....  ENDCASE.ENDFORM.                                "PAI

*-------------------------------------------------------** Call event GET LFA1 *-------------------------------------------------------*FORM put_lfa1.   SELECT * FROM lfa1            WHERE lifnr      IN slifnr.    PUT lfa1.  ENDSELECT.ENDFORM.                                "PUT_LFA1

*-------------------------------------------------------** Call event GET LFB1 *-------------------------------------------------------*FORM put_lfb1.   SELECT * FROM lfb1            WHERE lifnr      =  lfa1-lifnr              AND bukrs      IN sbulrs.    PUT lfb1.  ENDSELECT.ENDFORM.                                "PUT_LFB1

*-------------------------------------------------------** Call event GET LFC1 *-------------------------------------------------------*FORM put_lfc1.   SELECT * FROM lfc1            WHERE lifnr      =  lfa1-lifnr              AND bukrs      =  lfb1-bukrs              AND gjahr      IN sgjahr.    PUT lfc1.  ENDSELECT.ENDFORM.                                "PUT_LFC1

*-------------------------------------------------------** Call event GET BKPF *-------------------------------------------------------*FORM put_bkpf.   SELECT * FROM bkpf            WHERE bukrs      =  lfb1-bukrs              AND belnr      IN sbelnr              AND gjahr      IN sgjahr.    PUT bkpf.  ENDSELECT.ENDFORM.                                "PUT_BKPF 

The PROGRAM statement has the addition DEFINING DATABASE test_ldb. This defines the database program as belonging to the logical database TEST_LDB.

You declare the node of the structure using the TABLESstatement. This creates the necessary interface work areas as table work areas. You can also use the NODES statement to define database tables as nodes. If a node of a logical database is not a database table, you must use the NODESstatement. The interface work areas are shared by the database program and the user, and so act as an interface for passing data. The term "user" here can mean either an executable program to which the logical database is linked, or the function module LDB_PROCESS.

The subroutines INIT and PBO initialize the selection screen.

In the PAI subroutine, you can include an authorization check for the user input on the selection screen. Plausibility or value range checks are also possible. If a check fails, you can write an error dialog. The corresponding field on the selection screen is then made ready for input again.

The PUT_node subroutines read the database tables according to the selection criteria entered by the user and trigger the relevant GET events. This program is intended only to show the essential structure of a logical database. It does not contain any refinements to improve response times. The order in which the subroutines are called is determined by the structure of the logical database.