To display or change the database program of a logical database, choose Database program from the initial screen of the Logical Database Builder, or navigate to the ABAP Editor for database program from another component. The name of the program is SAPDBldb, where ldb is the name of the logical database.
When you open the database program for editing for the very first time, the system generates it. The generated database program looks like a function group, since it consists of a series of generated include programs . This makes their structure easy to follow, even if the logical database has a large number of nodes. Older logical databases may not use includes and consist instead only of a main program.
The main program SAPDBldb usually contains the following include programs:
Contains global declarations.
Contains further include programs for individual subroutines.
User-defined include programs for extra functions.
The include program DBldbXXX usually contains the following include programs:
Contain the subroutines PUT_node and AUTHORITY_CHECK_node for the individual nodes of the logical database.
Contains most of the remaining subroutines for initialization, PBO, and PAI of the selection screen, and so on.
Contains the subroutine FORM PUT_ldb_SP for processing the search help.
You must not change the predefined NODES and TABLESstatements, or the prescribed names of the automatically-generated include programs and subroutines. However, you can define extra includes and subroutines, and change the ABAP statements used to read data. User-defined include programs must follow the naming convention DBldbFnnn to ensure that they are transported with the logical database.
Suppose the logical database TEST_LDB has the following structure:
All of the nodes are database tables. Suppose the following 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 essential lines of the automatically-generated database program and its include programs are listed below. The program also contains some user and performance hints as comment lines, but these are not included here.
Framework 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, LFC!, BKPF.
* data: ... "user defined variables
Include Program DBTEST_LDBXXX
*----------------------------------------------------------* * Automatically generated file * contains all necessary system routines of the database program * !!!!!DO NOT CHANGE MANUALLY !!!!! *----------------------------------------------------------*
INCLUDE DBTEST_LDBN001 ." Node LFA1 INCLUDE DBTEST_LDBN002 . " Node LFB1 INCLUDE DBTEST_LDBN003 . " Node LFC1 INCLUDE DBTEST_LDBN004 . " Node BKPF INCLUDE DBTEST_LDBFXXX . " INIT, PBO, PAI INCLUDE DBTEST_LDBSXXX . " search help
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. "AUTHORITY_CHECK_LFA1
Include Programs DBTEST_LDB002 and DBTEST_LDB003
Similar to DBTEST_LDB001, but 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 function of most of the subroutines is described in the section Structure of Logical Databases .
The comment symbols (*) before the ABAP statements that are optional can be deleted, and the question marks (?) replaced by appropriate expressions. When you check the syntax of the program, all of the include programs that conform to the naming convention and the selection include are also checked.
In the subroutines PUT_node, SELECT statements are generated with conditions in their WHERE clauses for the primary key fields of the node. Note that these statements do not yet satisfy the requirements of the performance rules for Open SQL statements. In particular, the PUT_nodesubroutines for a subtree of a structure represent nested SELECT loops, which you should avoid. Instead, you can buffer the data in internal tables, and pass it to the application program from there using the PUTstatement. However, for technical reasons, the PUT node statement should always occur in a subroutine whose name begins PUT_node.
If the selection contains dynamic selections or field selections for a node, the system generates the corresponding statements in the subroutine PUT_node, and adjusts the automatically-generated SELECTstatements, as in the example for the node BKPF. The following sections explain how you can process user input in the dynamic selections and column specifications after GETstatements.
Some internal tables and other subroutines are automatically generated, and can be used in the program.
DATA: BEGIN OF GET_EVENTS OCCURS 10, NODE(10), KIND, END OF GET_EVENTS.
Each line contains the name of a node of the logical database in the NODE field. The KIND field specifies whether and how the node is requested by the user.
Dynamic Selections in the Database Program
Field Selections in the Database Program