Entering content frameEditing the Database Program Locate the document in its SAP Library structure

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 database program from another component. The name of the program is SAPDB<ldb>, where <ldb> is the name of the logical database.

Structure of the Database Program

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.

This graphic is explained in the accompanying textThe main program SAPDB<ldb> 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 DB<ldb>XXX 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 NODES and TABLES statements, 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 DB<ldb>F<nnn> to ensure that they are transported with the logical database.

Full Example of a Generated ABAP Program

Example

Suppose the logical database TEST_LDB has the following structure:

This graphic is explained in the accompanying text

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.

Main 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 observe the performance rules for Open SQL statements. In particular, the PUT_<node> subroutines for a subtree a structure form nested SELECTED 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 PUT statement. 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 SELECT statements, 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 GET statements.

Generated Data Objects and Subroutines

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.

· KIND = 'X': Node is addressed in GET and GET LATE.

· KIND = 'G': Node is addressed only in GET.

· KIND = 'L': Node is addressed only in GET LATE.

· KIND = 'P': Node is addressed neither in GET nor in GET LATE. However, a subordinate node is addressed in GET or GET LATE.

· KIND = ' ': Node is addressed neither in GET nor in GET LATE. No subordinate node is addressed either.

 

Dynamic Selections in the Database Program

Field Selections in the Database Program

Search Helps in the Database Program

Independent Calls and the Database Program

 

 

Leaving content frame