Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Processing of External Data →  Logical Databases (Obsolete) →  Logical Databases - Examples 

Example of a Database Program

A logical database TEST_LDB has the structure shown in Example of a Logical Database. All nodes are database tables. Selections are defined in the selection include:

SELECT-OPTIONS SLIFNR  FOR LFA1-LIFNR.
SELECT-OPTIONS SBUKRS  FOR LFB1-BUKRS.
SELECT-OPTIONS SGJAHR  FOR LFC1-GJAHR.
SELECT-OPTIONS SBELNR  FOR BKPF-BELNR.

The generated proposal for the database program is then as follows:

Other versions: 7.31 | 7.40 | 7.54

Master program SAPDBTEST_LDB

----------------------------------------------------------
      DATABASE PROGRAM OF LOGICAL DATABASE TEST_LDB
*----------------------------------------------------------

INCLUDE DBTEST_LDBTOP .    " header
INCLUDE DBTEST_LDBXXX .    " all system routines
* INCLUDE DBTEST_LDBF001 . " user defined include

Include program DBTEST_LDBTOP

PROGRAM SAPDBTEST_LDB DEFINING DATABASE TEST_LDB.
TABLES: LFA1,
         LFB1,
         LFC1,
         BKPF.
* DATA: ...          "user defined variables

Include program DBTEST_LDB001

----------------------------------------------------------
* Call event GET LFA1
----------------------------------------------------------
FORM PUT_LFA1.
* SELECT * FROM LFA1
   INTO LFA1
   INTO TABLE ? (choose one!)
   WHERE LIFNR = ?.
    PUT LFA1.
ENDSELECT.
ENDFORM.                               "PUT_LFA1
----------------------------------------------------------
* Authority Check for node LFA1
----------------------------------------------------------
* FORM AUTHORITY_CHECK_LFA1.
   AUTHORITY-CHECK ...
ENDFORM.

Include programs DBTEST_LDB002 and DBTEST_LDB003

Like DBTEST_LDB001 for the nodes LFB1 and LFC1

Include program DBTEST_LDB004

----------------------------------------------------------
* Call event GET BKPF
----------------------------------------------------------
FORM PUT_BKPF.
* STATICS FLAG.
* IF FLAG = SPACE.
   FLAG = 'X'.
** Declarations for field selection for node BKPF *
   STATICS BKPF_FIELDS TYPE RSFS_TAB_FIELDS.
   MOVE 'BKPF' TO BKPF_FIELDS-TABLENAME.
   READ TABLE SELECT_FIELDS WITH KEY BKPF_FIELDS-TABLENAME
     INTO BKPF_FIELDS.
* ENDIF.
* SELECT (BKPF_FIELDS-FIELDS) INTO CORRESPONDING FIELDS OF
     BKPF / TABLE ? " (choose one of them)
*     FROM BKPF
   WHERE BUKRS = LFB1-BUKRS
     AND BELNR IN SBELNR
*     AND GJAHR = ?.
    PUT BKPF.
ENDFORM.                               "PUT_BKPF
*----------------------------------------------------------

* Authority Check for node BKPF
----------------------------------------------------------
* FORM AUTHORITYCHECK_BKPF.
   AUTHORITY-CHECK ...
ENDFORM.                             "AUTHORITY_CHECK_BKPF

Include program DBTEST_LDBFXXX

----------------------------------------------------------
* BEFORE_EVENT will be called before event EVENT
* Possible values for EVENT: 'START-OF-SELECTION'
----------------------------------------------------------
* FORM BEFORE_EVENT USING EVENT.
   CASE EVENT.
     WHEN 'START-OF-SELECTION'
*
   ENDCASE.
ENDFORM.                             "BEFORE_EVENT
----------------------------------------------------------
* AFTER_EVENT will be called after event EVENT
* Possible values for EVENT: 'END-OF-SELECTION'
----------------------------------------------------------
* FORM AFTER_EVENT USING EVENT.
   CASE EVENT.
     WHEN 'END-OF-SELECTION'
*
   ENDCASE.
ENDFORM.                             "AFTER_EVENT
-----------------------------------------------------------
* Initialize global data for multiple processing of
* one logical database.
* Set returncode:
      0 -> all data are initialized, multiple processing o.k.
*  other -> no multiple processing allowed
------------------------------------------------------------*
FORM  LDB_PROCESS_INIT CHANGING SUBRC LIKE SY-SUBRC.

ENDFORM.                    "LDB_PROCESS_INIT
------------------------------------------------------------
* LDB_PROCESS_CHECK_SELECTIONS is called
* after select-options and parameters are filled
------------------------------------------------------------
FORM  LDB_PROCESS_CHECK_SELECTIONS CHANGING SUBRC LIKE SY-SUBRC
                                            MSG LIKE SYMSG.

ENDFORM.                    "LDB_PROCESS_CHECK_SELECTIONS
----------------------------------------------------------
* Initialize selection screen (processed before PBO)
----------------------------------------------------------
FORM INIT.

ENDFORM.                               "INIT.
----------------------------------------------------------
* PBO of selection screen (processed always after ENTER)
----------------------------------------------------------
FORM PBO.

ENDFORM.                               "PBO.
----------------------------------------------------------
* PAI of selection screen (processed always after ENTER)
----------------------------------------------------------
FORM PAI USING FNAME MARK.
* CASE FNAME.
   WHEN 'SLIFNR  '.
   WHEN 'SBUKRS  '.
   WHEN 'SBELNR  '.
*   WHEN 'SGJAHR  '.
   WHEN ''.
   ENDCASE.
ENDFORM.                               "PAI

Include program DBTEST_LDBSXXX

*****************
* !!! PLEASE DO NOT CHANGE MANUALLY (BEGIN OF BLOCK) !!!!!! *
-----------------------------------------------------------
* Data structures for search pattern selection
*
* !!! PLEASE DO NOT CHANGE MANUALLY (END OF BLOCK) !!!!!!!! *
*****************
-----------------------------------------------------------
* PUT_TEST_LDB_SP.
* Processed when search pattern selection is used,
* i.e. user input into PARAMETERS p_sp AS SEARCH PATTERN
* STRUCTURE.
-----------------------------------------------------------
* FORM PUT_TEST_LDB_SP.

* ENDFORM.                             "PUT_EXAMPLE_SP

The comment characters before ABAP statements used in addition to the mandatory statements can be deleted and the question marks can be replaced by appropriate expressions. The syntax check checks all include programs that match the naming conventions and also the selection include.

When the database is accessed in the subroutines put_node, SELECT statements with conditions for the primary key fields in the WHERE clauses are generated. The performance of these statements is, however, not yet optimized. In particular, the subroutines put_node of a subtree of the structure represent nested SELECT loops, which should generally be avoided. Instead, the data read can be buffered in internal tables, for example, and passed from here to the application program using the PUT statement. The statement PUT node, though, should always be located in a subroutine whose name starts with put_node for technical reasons.

If the selections specify dynamic selections or field selections for a node, corresponding statements are generated in the subroutine put_node and the SELECT statement created automatically is modified, as seen in the example for the node BKPF.

The subroutines before_event, after_event, and put_ldb_sp are created as comments in the database program and can be modified and, by deleting the asterisks, activated. before_event is called before the event specified in event is processed. after_event is called after the event specified in event is processed. When a selection is made using a search help, put_ldb_sp is called to edit the return values for the root node, instead of put_node.