Tải bản đầy đủ (.pdf) (153 trang)

BC ABAP Programming PHẦN 9 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.85 MB, 153 trang )

SAP AG BC - ABAP Programming
Using Logical Databases
December 1999 1227
Using Logical Databases
There are two ways of using a logical database: Either by linking it with an executable program,
or by using the function module LDB_PROCESS in any ABAP program.
BC - ABAP Programming SAP AG
Using Logical Databases
1228 December 1999
Struktur
Selektionen
Struktur
Selektionen
Event block
GET TABLE
Event block
GET TABLE
Executable program
Declarations
NODES
TABLES
Declarations
NODES
TABLES
Selection
Selection
screen
screen
Program
Function group
CALL FUNCTION


LDB_PROCESS

CALL FUNCTION
LDB_PROCESS

FORM CALLBACK

ENDFORM
FORM CALLBACK

ENDFORM
FUNCTION LDB_PROCESS

ENDFUNCTION.
FUNCTION LDB_PROCESS

ENDFUNCTION.
Logical database
Logical database
Database
Structure
Structure
Selections
Selections
Database program
Database program
SAP AG BC - ABAP Programming
Using Logical Databases
December 1999 1229
When you link a logical database to an executable program, the user can enter values on the

selection screen, and the data read by the logical database is passed back to the program using
the interface work areas. If you call the logical database using a function module, the selection
screen is not displayed. The calling program does not have to provide interface work areas.
Instead, it uses special subroutines called callback routines, which are called by the function
module and filled with the required data.
Linking a Logical Database to an Executable Program [Page 1230]
Calling a Logical Database Using a Function Module [Page 1234]
BC - ABAP Programming SAP AG
Linking a Logical DB to an Executable Program
1230 December 1999
Linking a Logical DB to an Executable Program
When you link an executable program to a logical database by entering the name of the logical
database in the program attributes, the subroutines of the logical database program and the
event blocks of the executable program form a modularized program for reading and processing
data. The individual processing blocks are called in a predefined sequence by the runtime
environment (see the diagram in the section Logical Databases and Contexts [Page 60]). The
runtime sequence is controlled by the structure, selections, and PUT statements in the logical
database, and by the GET statements in the executable program.
Selection Screen
If you specify a logical database in the attributes of an executable program, this affects the
standard selection screen of the program. It contains both the selection fields from the logical
database and those from the program itself. You can specify which of the logical database
selections are relevant for your program, and should therefore appear on the screen, by
declaring interface work areas for the relevant nodes.
Runtime Behavior
The following list shows the sequence in which the ABAP runtime environment calls the
subroutines of the logical database and the event blocks in the executable program [Page 992].
The runtime environment executes a series of processors (selection screen processor, reporting
processor). The ABAP code listed below shows the processing blocks that belong to the
individual steps.

1. Initialization before the selection screen is processed.
Subroutine:
FORM INIT
This subroutine is called once only before the selection screen is first displayed.
Event block:
INITIALIZATION.
This event occurs once only before the selection screen is first displayed.
2. PBO of the Selection screen Initialization before each occasion on which the selection
screen is displayed (for example, to supply default values for key fields).
Subroutine:
FORM PBO.
This subroutine is called each time the selection screen is sent (before it is
displayed).
Event block:
AT SELECTION-SCREEN OUTPUT.
This event is called each time the selection screen is sent (before it is displayed).
3. The selection screen is displayed at the presentation server, and the user can enter data
in the input fields.
4. Input help (F4) or field help (F1) requests.
SAP AG BC - ABAP Programming
Linking a Logical DB to an Executable
Program
December 1999 1231
Subroutines:
FORM <par>_VAL.
FORM <selop>_VAL.
FORM <selop>-LOW_VAL.
FORM <selop>-HIGH_VAL.
If the user requests a list of possible entries for database-specific parameters <par>
or selection criteria <selop>, these subroutines are called as required.

If the user requests field help for these parameters, the subroutines are called with
the ending _HLP instead of _VAL.
Event blocks:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR <par>.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR <selop>-LOW.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR <selop>-HIGH.
If the user requests a list of possible entries for database-specific parameters <par>
or selection criteria <selop>, these events are triggered as required.
If the user requests field help for these parameters, the events with the addition ON
HELP-REQUEST occurs instead of ON VALUE-REQUEST.
5. PAI of the selection screen. Checks to see whether the user has entered correct,
complete, and plausible data. Also contains authorization checks. If an error occurs, you
can program a user dialog and make the relevant fields ready for input again.
Subroutines:
FORM PAI USING FNAME MARK.
The interface parameters FNAME and MARK are passed by the runtime
environment.
FNAME contains the name of a selection criterion or parameter on the selection
screen.
If MARK = SPACE, the user has entered a simple single value or range selection.
If MARK = '*', the user has also entered selections on the
Multiple Selection screen.
Using the combination FNAME = '*' and MARK = 'ANY', you can check all entries at
once when the user chooses a function or presses ENTER.
Event blocks:
AT SELECTION-SCREEN ON <fname>.
Event for processing a particular input field.
AT SELECTION-SCREEN ON END OF <fname>.
Event for processing multiple selections.
AT SELECTION-SCREEN.

Event for processing all user input.
6. Processing before reading data.
Subroutine:
BC - ABAP Programming SAP AG
Linking a Logical DB to an Executable Program
1232 December 1999
BEFORE EVENT 'START-OF-SELECTION'.
The logical database can use this subroutine for necessary actions before reading
data, for example, initializing internal tables.
Event block:
START-OF-SELECTION.
First event in an executable program after the selection screen has been processed.
You can use this event block to prepare the program for processing data.
7. Reading data in the logical database and processing in the executable program.
Subroutine:
FORM PUT_<node>
The logical database reads the selected data of the node <node>.
Event block:
GET <table> [LATE].
This event is triggered by the PUT statement in the above subroutine. This event
block allows you to process the data read for <node> in the corresponding interface
work area.
8. Processing after reading data.
Subroutine:
AFTER EVENT 'END-OF-SELECTION'.
The logical database can use this subroutine for necessary actions after reading
data, for example, releasing memory space.
Event block:
END-OF-SELECTION.
Last reporting event. You can use this event block to process the temporary dataset

that you have created (for example, sort it).
9. If a list was generated during the above steps, the list processor in the runtime
environment takes control of the program and displays the list.

Suppose TABLE1 is the root node and TABLE2 is its only subordinate node in a
logical database. The processing steps for reading and processing data would then
have the following hierarchical order:
START-OF-SELECTION.
FORM PUT_TABLE1.
GET TABLE1.
FORM PUT_TABLE2.
GET TABLE2.
GET TABLE1 LATE.
SAP AG BC - ABAP Programming
Linking a Logical DB to an Executable
Program
December 1999 1233
END-OF-SELECTION.
Authorization Checks in Logical Databases
It makes sense to use authorization checks using the AUTHORITY-CHECK [Page 506]
statement in the following subroutines in the database program or event blocks of the executable
program:
• Subroutines in the database program:
− PAI
− AUTHORITY_CHECK_<table>
• Event blocks in the executable program:
− AT SELECTION-SCREEN
− AT SELECTION-SCREEN ON <fname>
− AT SELECTION-SCREEN ON END OF <fname>
− GET <table>

Whether you place the authorization checks in the database program or in the executable
program depends on the following:
• The structure of the logical database.
For example, you should only check authorizations for company code if you actually read
lines containing the company code at runtime.
• Performance
Avoid repetitive checks (for example, within a SELECT loop).
The separation of database access and application logic allows you to program
all of your
authorization checks centrally in the logical database program. This makes it easier to maintain
large programming systems.
BC - ABAP Programming SAP AG
Calling a Logical Database Using a Function Module
1234 December 1999
Calling a Logical Database Using a Function Module
From Release 4.5A it is possible to call logical databases independently from any ABAP
program. Previously it was only possible to link a logical database to an executable program, in
which the processing blocks of the logical database and the program were controlled by the
ABAP runtime environment.
To call a logical database from another program, use the function module
LDB_PROCESS. This
allows you to use the logical database as a routine for reading data. You can call more than one
logical database from the same program. You may also call the same logical database more than
once from the same program. In the past, it was only possible to use a logical database more
than once or use more than one logical database by calling a further executable program using
SUBMIT [Page 1059]. These programs had to be linked to the corresponding logical database,
and the data had to be passed to the calling program using ABAP memory [Page 1073] or a
similar technique.
When you call a logical database using the function module LDB_PROCESS, its selection screen
is not displayed. Instead, you fill the selections using the interface parameters of the function

module. The logical database does not trigger any GET events in the calling program, but
passes the data back to the caller in callback routines. Calling a logical database using
LDB_PROCESS thus decouples the actual data retrieval from the preceding selection screen
processing and the subsequent data processing.
There is
no need to adapt a logical database for use with LDB_PROCESS, except in the
following cases: If you do not adapt a logical database, it is not possible to use the function
module to call the same logical database more than once. The PAI subroutine is not called when
you use LDB_PROCESS. This means that none of the checks for selections programmed in it
are performed. You can work around these restrictions by including the subroutines
LDB_PROCESS_INIT and LDB_PROCESS_CHECK_SELECTIONS [Page 1269] in the
database program.
Runtime Behavior
The subroutines in the logical database are called in the following sequence when you call the
function module LDB_PROCESS:
1. LDB_PROCESS_INIT
2. INIT
3. LDB_PROCESS_CHECK_SELECTIONS
4. PUT <node>.
None of the subroutines used to process the selection screen when you link the logical database
to an executable program [Page 1230] are called, neither does the runtime environment trigger
any reporting events in the calling program. Instead, the PUT statements in the logical database
trigger actions in the function module that call callback routines in the calling program. In other
words, the function module catches the events that are otherwise processed by the runtime
environment.
Parameters of LDB_PROCESS
The function module has the following import parameters:
• LDBNAME
SAP AG BC - ABAP Programming
Calling a Logical Database Using a

Function Module
December 1999 1235
Name of the logical database you want to call.
• VARIANT
Name of a variant to fill the selection screen of the logical database. The variant must
already be assigned to the database program of the logical database. The data is passed
in the same way as when you use the WITH SELECTION-TABLE addition in a SUBMIT
[Page 1060] statement.
• EXPRESSIONS
In this parameter, you can pass extra selections for the nodes of the logical database for
which dynamic selections are allowed. The data type of the parameter RSDS_TEXPR is
defined in the type group RSDS. The data is passed in the same way as when you use
the WITH FREE SELECTION addition in a SUBMIT [Page 1060] statement.
• FIELD_SELECTION
You can use this parameter to pass a list of the required fields for the nodes of the logical
database for which dynamic selections are allowed. The data type of the parameter is
the deep internal table RSFS_FIELDS, defined in the type group RSFS. The component
TABLENAME contains the name of the node and the deep component FIELDS contains
the names of the fields that you want to read.
The function module has the following tables parameters:
• CALLBACK
You use this parameter to assign callback routines to the names of nodes and events.
The parameter determines the nodes of the logical database for which data is read, and
when the data is passed back to the program and in which callback routine.
• SELECTIONS
You can use this parameter to pass input values for the fields of the selection screen of
the logical database. The data type of the parameter corresponds to the structure
RSPARAMS in the ABAP Dictionary. The data is passed in the same way as when you
use the WITH SELECTION-TABLE addition in a SUBMIT [Page 1060] statement.
If you pass selections using more than one of the interface parameters, values passed in

SELECTIONS and EXPRESSIONS overwrite values for the same field in VARIANT.
Read Depth and Callback Routines
When you link a logical database with an executable program, the GET statements determine the
depth to which the logical database is read. When you call the function module LDB_PROCESS,
you determine the depth by specifying a node name in the CALLBACK parameter. For each node
for which you request data, a callback routine can be executed at two points. These correspond
to the GET and GET LATE events in executable programs. In the table parameter CALLBACK,
you specify the name of the callback routine and the required execution point for each node. A
callback routine is a subroutine in the calling program or another program that is to be executed
at the required point.
For the GET event, the callback routine is executed directly after the data has been read for the
node, and before the subordinate nodes are processed. For the GET_LATE event, the callback
routine is processed after the subordinate nodes have been processed.
The line type of the table parameter CALLBACK is the flat structure LDBCB from the ABAP
Dictionary. It has the following components:
BC - ABAP Programming SAP AG
Calling a Logical Database Using a Function Module
1236 December 1999
• LDBNODE
Name of the node of the logical database to be read.
• GET
A flag (contents X or SPACE), to call the corresponding callback routine at the GET
event.
• GET_LATE
A flag (contents X or SPACE), to call the corresponding callback routine at the GET
LATE event.
• CB_PROG
Name of the ABAP program in which the callback routine is defined.
• CB_FORM
Name of the callback routine.

If you pass an internal table to the CALLBACK parameter, you must fill at least one of the GET or
GET_LATE columns with X for each node (you may also fill both with X).
A callback routine is a subroutine that must be defined with the following parameter interface:
FORM <subr> USING <node> LIKE LDBCB-LDBNODE
<wa> [TYPE <t>]
<evt>
<check>.
The parameters are filled by the function module LDB_PROCESS. They have the following
meaning:
• <node> contains the name of the node.
• <wa> is the work area of the data read for the node. The program that calls the function
module LDB_PROCESS and the program containing the callback routine do not have to
declare interface work areas using NODES or TABLES. If the callback routine is only
used for one node, you can use a TYPE reference to refer to the data type of the node in
the ABAP Dictionary. Only then can you address the individual components of
structured nodes directly in the subroutine. If you use the callback routine for more than
one node, you cannot use a TYPE reference. In this case, you would have to address
the components of structured nodes by assigning them one by one [Page 214] to a field
symbol.
• <evt> contains G or L, for GET or GET LATE respectively. This means that the
subroutine can direct the program flow using the contents of <evt>.
• <check> allows the callback routine to influence how the program is processed further
(but only if <evt> contains the value G). The value X is assigned to the parameter when
the subroutine is called. If it has the value SPACE when the subroutine ends, this flags
that the subordinate nodes of the logical database should not be processed in the
function module LDB_PROCESS. This is the same as leaving a GET event block using
CHECK [Page 1015] in an executable program. If this prevents unnecessary data from
being read, it will improve the performance of your program.
SAP AG BC - ABAP Programming
Calling a Logical Database Using a

Function Module
December 1999 1237
Exceptions of LDB_PROCESS
• LDB_ALREADY_RUNNING
A logical database may not be called if it is still processing a previous call. If this occurs,
the exception LDB_ALREADY_RUNNING is triggered.
• LDB_NOT_REENTRANT
A logical database may only be called repeatedly if its database program contains the
subroutine LDB_PROCESS_INIT [Page 1269], otherwise, this exception is triggered.
• LDB_SELECTIONS_NOT_ACCEPTED
Error handling in the subroutine LDB_PROCESS_CHECK_SELECTIONS [Page 1269] of
the database program can trigger this exception. The error message is placed in the
usual system fields SY-MSG [Page 486].
For details of further exceptions, refer to the function module documentation in the Function
Builder.
Example

TABLES SPFLI.
SELECT-OPTIONS S_CARR FOR SPFLI-CARRID.
TYPE-POOLS: RSDS, RSFS.
DATA: CALLBACK TYPE TABLE OF LDBCB,
CALLBACK_WA LIKE LINE OF CALLBACK.
DATA: SELTAB TYPE TABLE OF RSPARAMS,
SELTAB_WA LIKE LINE OF SELTAB.
DATA: TEXPR TYPE RSDS_TEXPR,
FSEL TYPE RSFS_FIELDS.
CALLBACK_WA-LDBNODE = 'SPFLI'.
CALLBACK_WA-GET = 'X'.
CALLBACK_WA-GET_LATE = 'X'.
CALLBACK_WA-CB_PROG = SY-REPID.

CALLBACK_WA-CB_FORM = 'CALLBACK_SPFLI'.
APPEND CALLBACK_WA TO CALLBACK.
CLEAR CALLBACK_WA.
CALLBACK_WA-LDBNODE = 'SFLIGHT'.
CALLBACK_WA-GET = 'X'.
CALLBACK_WA-CB_PROG = SY-REPID.
CALLBACK_WA-CB_FORM = 'CALLBACK_SFLIGHT'.
APPEND CALLBACK_WA TO CALLBACK.
SELTAB_WA-KIND = 'S'.
SELTAB_WA-SELNAME = 'CARRID'.
LOOP AT S_CARR.
MOVE-CORRESPONDING S_CARR TO SELTAB_WA.
BC - ABAP Programming SAP AG
Calling a Logical Database Using a Function Module
1238 December 1999
APPEND SELTAB_WA TO SELTAB.
ENDLOOP.
CALL FUNCTION 'LDB_PROCESS'
EXPORTING
LDBNAME = 'F1S'
VARIANT = ' '
EXPRESSIONS = TEXPR
FIELD_SELECTION = FSEL
TABLES
CALLBACK = CALLBACK
SELECTIONS = SELTAB
EXCEPTIONS
LDB_NOT_REENTRANT = 1
LDB_INCORRECT = 2
LDB_ALREADY_RUNNING = 3

LDB_ERROR = 4
LDB_SELECTIONS_ERROR = 5
LDB_SELECTIONS_NOT_ACCEPTED = 6
VARIANT_NOT_EXISTENT = 7
VARIANT_OBSOLETE = 8
VARIANT_ERROR = 9
FREE_SELECTIONS_ERROR = 10
CALLBACK_NO_EVENT = 11
CALLBACK_NODE_DUPLICATE = 12
OTHERS = 13.
IF SY-SUBRC <> 0.
WRITE: 'Exception with SY-SUBRC', SY-SUBRC.
ENDIF.
FORM CALLBACK_SPFLI USING NAME TYPE LDBN-LDBNODE
WA TYPE SPFLI
EVT TYPE C
CHECK TYPE C.
CASE EVT.
WHEN 'G'.
WRITE: / WA-CARRID, WA-CONNID, WA-CITYFROM, WA-CITYTO.
ULINE.
WHEN 'L'.
ULINE.
ENDCASE.
ENDFORM.
FORM CALLBACK_SFLIGHT USING NAME TYPE LDBN-LDBNODE
WA TYPE SFLIGHT
EVT TYPE C
CHECK TYPE C.
WRITE: / WA-FLDATE, WA-SEATSOCC, WA-SEATSMAX.

ENDFORM.
The program is written to read data using the logical database F1S. The structure of
F1S is:
SAP AG BC - ABAP Programming
Calling a Logical Database Using a
Function Module
December 1999 1239
SBOOK
SBOOK
SFLIGHT
SFLIGHT
SPFLI
SPFLI
A program-specific selection screen is defined at the beginning of the program. This
requires the TABLES statement. Next, the required variables are defined for the
interface.
The internal table CALLBACK is filled so that various callback routines are called in
the program for the two nodes SPFLI and SFLIGHT. For SPFLI, the routine is to be
called for GET and GET_LATE, for SFLIGHT, only at the GET event.
The internal table SELTAB is filled with values for the node SPFLI from the selection
table S_CARR from the program-specific selection screen.
The program then calls the function module LDB_PROCESS with these parameters.
The subroutines CALLBACK_SPFLI and CALLBACK_SFLIGHT serve as callback
routines. The interface parameter WA is fully typed, so you can address the
individual components of the work areas. The events GET and GET LATE are
handled differently in CALLBACK_SPFLI.
The beginning of the list output might look like this:
BC - ABAP Programming SAP AG
Calling a Logical Database Using a Function Module
1240 December 1999

SAP AG BC - ABAP Programming
Editing Logical Databases
December 1999 1241
Editing Logical Databases
You edit logical databases using the Logical Database Builder in the ABAP Workbench. To start
the Logical Database Builder, use Transaction SE36 or SLDB, or choose
Tools → ABAP
Workbench
, followed by Development → Programming environment → Logical Database Builder.
You can also start it by forward navigation from the Repository Browser or other ABAP
Workbench tools.
In the
Logical database field, you can enter a name of up to 20 characters. The name may also
contain a three to ten-character namespace prefix, enclosed in forward slashes.
On the initial screen, you can create, copy, and delete logical databases. However, you can only
delete a logical database if it is not linked to an executable program. Even if a logical database is
not linked to any executable programs, it can still be used by a program that calls it using the
function module LDB_PROCESS. Before deleting one, you should therefore check that it is not
still in use. However, the
Where-used list function only shows where a logical database is
assigned to an executable program.
You can select the individual components of the logical database directly. When you are editing
a logical database, two arrow icons appear in the application toolbar that allow you to navigate
backwards and forwards between the most important components. You can also use the normal
Goto function to navigate between components.
Creating a Logical Database [Page 1242]
Editing the Structure [Page 1244]
Editing a Search Help [Page 1246]
Editing Selections [Page 1247]
Editing the Database Program [Page 1251]

Editing Other Components [Page 1270]
Improving Performance [Page 1271]
BC - ABAP Programming SAP AG
Creating a Logical Database
1242 December 1999
Creating a Logical Database
To create a new logical database, you should follow the procedure below. The Logical Database
Builder then saves you work by using components that you have already defined to generate
proposals for other components. Some of the most important attributes of a logical database are
set when you define its structure. When you have defined the structure, the Logical Database
Builder automatically generates a proposal for the selection include. The system then generates
an input mask for the database program, based on the structure of the logical database and the
selections.
These generated proposals allow you to create a working logical database quickly. However,
you must program refinements such as authorization checks and performance optimization
yourself.
Procedure for Creating a Logical Database
1. Enter a name on the initial screen of the Logical Database Builder and choose Create.
2. A dialog box appears. Enter a short text. You can change this later by choosing
Extras

Short text or Administration info.
3. Once you have entered the short text, you must define the root node of the logical
database. Enter the node name and its attributes. There are three different types of
nodes:
§ Database tables. The table must be active in the ABAP Dictionary. Tables
always have a flat structure. The name of the node must correspond with the
name of the table.
§ Data types from the ABAP Dictionary: The node may refer to any data type in
the ABAP Dictionary [Page 105]. The node name and the name of the data type

do not have to be the same. You can use deep data types as nodes.
§ Data types from type groups: The node can also refer to a data type from a
type group in the ABAP Dictionary. Enter the name of the type group in the
corresponding field. You must choose
Other types before specifying this type.
Data types in type groups were the forerunners of real data types in the ABAP
Dictionary. Wherever possible, you should use ABAP Dictionary data types.
They have all of the semantic properties of their underlying data elements. This
is useful, for example, when you use a logical database to create ABAP Queries.
You can use the
Text from Dictionary function to adopt the text stored in the ABAP
Dictionary for the relevant table or data type.
1. The structure editor of the Logical Database Builder appears. On the left is the name of
the root node, followed by a code for the node type:
T for a database table, S for a ABAP
Dictionary type, and
C for a type from a type group. The new logical database now has a
structure with a single node.
2. You can now extend the structure as described in Editing the Structure [Page 1244].
3. If you choose Next screen (right arrow in the application toolbar), a screen appears on
which you can enter a search help for the logical database as described under Editing
Search Helps [Page 1246].
4. If you choose Next screen (right arrow in the application toolbar), a dialog box appears,
asking you whether the system should generate the selections for the logical database.
SAP AG BC - ABAP Programming
Creating a Logical Database
December 1999 1243
When you have confirmed the dialog box, a list appears, on which you can select all of
the nodes that you want to use for field selections or dynamic selections. The fields that
you select are included in the source code generated by the system for the selection

include.
5. The generated selection include is displayed in the ABAP Editor. You can change it as
described in Editing Selections [Page 1247].
6. If you choose Next screen (right arrow in the application toolbar), a dialog box appears,
asking you whether the system should generate the database program for the logical
database. The database program is generated from the structure and the selection
include. It has a modular structure, consisting of several include programs and all of the
necessary subroutines, with proposals for the statements that will read the data.
7. The generated database program is displayed in the ABAP Editor. You can change it as
described in Editing the Database Program [Page 1251].
8. If you repeatedly choose Previous screen (left arrow in the application toolbar), you can
display and change the general attributes of the logical database.
9. Finally, you can maintain optional selection texts and documentation.
BC - ABAP Programming SAP AG
Processing the Structure
1244 December 1999
Processing the Structure
To display or change the structure of a logical database, choose Structure from the initial screen
of the Logical Database Builder, or navigate to the structure editor from another component.
Displaying the Structure
The structure editor displays the structure hierarchy. Each node is displayed as follows:
<node>
<node>
<id>
<id>
<type>
<type>
<text>
<text>



• <node> is the name of the node.
• <id> is the type of the node: T for a database table, S for a ABAP Dictionary type, and C
for a type from a type group.
• <type> is the name of the ABAP Dictionary object to which the node refers.
• <text> is the short text for the node.
As usual, you can expand or collapse the subordinate tree structures, and edit individual
subtrees. You can display the attributes of a node by double-clicking it. To display the structure
of a node, that is, the components of its data type, place the cursor on the node and choose
Display table fields.
The
PUT routine function allows you to display the subroutine PUT_<node>. For this to work, the
subroutine must be contained in its own include that follows a particular naming convention. For
further information, refer to Editing the Database Program [Page 1251].
Changing the Structure
• To rename an existing node, place the cursor on it and choose Edit → Node → Change.
• To create a new node at a subordinate level to the cursor position, or on the same level,
choose
Edit →
→→
→ Node →
→→
→ Create. Nodes that you create like this in the structure editor
consists at first only of its logical name, with which it is declared in the database program
using the TABLES or NODES statement. To define the node fully, double-click it. You
can then enter its type, the name of the data type from the ABAP Dictionary to which it
refers, and its short text.
• To select/deselect a sub-tree, choose Edit →
→→
→ Sub-tree →

→→
→ Select/deselect. To move a
selected sub-tree in a structure to a position indicated by the cursor, choose
Edit →
→→
→ Sub-
tree

→→
→ Reassign.
• To delete a sub-tree, place the cursor on the node or select it and choose Edit →
→→
→ Sub-
tree

→→
→ Delete.
SAP AG BC - ABAP Programming
Processing the Structure
December 1999 1245
BC - ABAP Programming SAP AG
Editing a Search Help
1246 December 1999
Editing a Search Help
A search help is a ABAP Dictionary object used to define possible values (F4) help. There are
two kinds of search help - elementary and collective. An elementary search help uses a search
path to determine the possible entries. A collective search help consists of two or more
elementary search helps, and thus provides more than one possible search path.
To display or change the link between a logical database and a search help, choose
Search

helps
from the initial screen of the Logical Database Builder or use the navigation function from
another component.
Here, you can assign a search help to the logical database by choosing from a list. You can also
delete the link between the logical database and an existing search help.
In deciding which search help is appropriate for the logical database, you must consider its
content. For example, if you create a logical database that reads creditor records, the creditor
number should be one of the output fields of the search help. The contents of the output fields of
the search help are available to the logical database at runtime for the actual database access.
There are two ways of finding information about the output fields of a search help. You can either
use the ABAP Dictionary, or enter a search help and then look at the ensuing list.
To enable the user to use the search help, you must declare a special parameter in the selection
include using the addition AS SEARCH PATTERN. The system interprets the user’s input on the
selection screen and reads the value list from the database. The values are made available to
the database program in the internal table <ldb>_SP, and the subroutine PUT_<ldb>_SP is
called instead of PUT_<root>. <ldb> is the name of the logical database, and <root> is the name
of the root node. This subroutine can use the value list in <ldb>_SP to read the actual data and
trigger the GET <root> event using the PUT_<root> statement.
SAP AG BC - ABAP Programming
Editing Selections
December 1999 1247
Editing Selections
To display or change the structure of a logical database, choose Selections from the initial screen
of the Logical Database Builder, or navigate to the selection include from another component.
The name of the selection include is DB<ldb>SEL, where <ldb> is the name of the logical
database. You
must not incorporate this include program in the database program using an
INCLUDE statement. Instead, the runtime environment includes the selection include in the
database program and the corresponding programs when it generates the logical database.
If you try to edit the selections but no selection include yet exists, the system generates one. This

includes SELECT-OPTIONS statements for all of the database tables in the structure (nodes with
type T). For each database table, the system proposes selection criteria [Page 718] for all of the
fields in its primary key.
The SELECT-OPTIONS statements are commented out, and contain question marks instead of
the names of the selection criteria. For each selection criterion that you want to use, you must
enter the name and delete the comment character (*).
If a
search help is specified for the logical database, the system also generates a corresponding
PARAMETERS statement with the addition AS SEARCH PATTERN. A group box entitled
Selection using search help then appears on the selection screen with input fields for the search
help ID and the search string. There is also a pushbutton for complex search helps. If you
choose this function, you can enter multiple selections for each field.
Finally, SELECTION-SCREEN statements are generated for
dynamic selections and field
selections
for nodes with type T or S (if this is allowed by the structure definition).
As well as the default elements, you can use the following statements to extend the selection
screen:
• Use the PARAMETERS statement and its additions to add input fields for single values
[Page 699]. You could use these, for example, to control the flow of the program. In the
selection include, you must use the addition FOR NODE or FOR TABLE in the
PARAMETERS statement. You can use NODE for all node types. You can only use
TABLE for nodes with type T. When the selection screen is generated, the system only
generates fields for the nodes declared in the executable program in the NODES or
TABLES statement, or those requested by the function module LDB_PROCESS.
• Use the SELECTION-SCREEN statement to format the selection screen [Page 734].
• The statement
SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE|TABLE <node>.
allows you to define further nodes for dynamic selections. If the node has type T, you
can use TABLE instead of NODE. The user can then decide at runtime the components

of the node for which he or she wants to enter selections. Dynamic selections require
special handling in the database program.
• The statement
SELECTION-SCREEN FIELD SELECTION FOR NODE|TABLE <node>.
allows you to define further nodes for field selections. If the node has type T, you can
use TABLE instead of NODE. In an executable program, you can use a field list in the
GET statement to specify which fields of the node of the logical database should be read.
In the function module LDB_PROCESS, the parameter FIELD_SELECTION must be
BC - ABAP Programming SAP AG
Editing Selections
1248 December 1999
passed accordingly. Dynamic selections require special handling in the database
program.
• The statements
SELECTION-SCREEN BEGIN OF VERSION <dynnr>

SELECTION-SCREEN EXCLUDE <f>.

SELECTION-SCREEN BEGIN OF VERSION <dynnr>.
allow you to create different versions of the selection screen with screen number
<dynnr> less than 1000. You can hide the input fields of selection criteria or parameters
as specified in <f>. This allows an executable program to work with an appropriate
selection screen version.
To check the selection include DB<dba>SEL for syntax errors, choose
Check on the initial
screen. The system also checks the syntax of the selection include if you choose
Check while
editing the database program.

Suppose the logical database TEST_LDB has the following structure:

LFC1
LFC1
LFB1
LFB1
LFA1
LFA1
BKPF
BKPF
The generated default selection include would look like this:
* *
* Include DBTEST_LDBSEL
* It will be automatically included into the database program
* *
* If the source is automatically generated,
* please perform the following steps:
* 1. Replace ? by suitable names (at most 8 characters).
* 2. Activate SELECT-OPTIONS and PARAMETERS (delete stars).
* 3. Save source code.
* 4. Edit database program.
*
* Hint: Syntax-Check is not possible within this Include!
* It will be checked during syntax-check of database program.
* *
* SELECT-OPTIONS : ? FOR LFA1-LIFNR.
SAP AG BC - ABAP Programming
Editing Selections
December 1999 1249
* Parameter for search pattern selection (Type SY-LDB_SP):
* PARAMETERS p_sp AS SEARCH PATTERN FOR TABLE LFA1.
* SELECT-OPTIONS :

* ? FOR LFB1-LIFNR,
* ? FOR LFB1-BUKRS.
* SELECT-OPTIONS :
* ? FOR LFC1-LIFNR,
* ? FOR LFC1-BUKRS,
* ? FOR LFC1-GJAHR.
* SELECT-OPTIONS :
* ? FOR BKPF-BUKRS,
* ? FOR BKPF-BELNR,
* ? FOR BKPF-GJAHR.
* Enable DYNAMIC SELECTIONS for selected nodes :
* Enable FIELD SELECTION for selected nodes :
If the nodes LFA1 and LFB1 are defined for dynamic selections, and node LFC1 is
defined for field selections, the following lines of code will also be generated:
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE LFA1.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE LFB1.
SELECTION-SCREEN FIELD SELECTION FOR TABLE LFC1.
The automatically-created selection include could be modified as follows:
* Selection criteria:
SELECT-OPTIONS SLIFNR FOR LFA1-LIFNR.
SELECT-OPTIONS SBUKRS FOR LFB1-BUKRS.
SELECT-OPTIONS SGJAHR FOR LFC1-GJAHR.
SELECT-OPTIONS SBELNR FOR BKPF-BELNR.
* Self-defined parameters:
PARAMETERS PSTIDA LIKE SY-DATUM FOR NODE BKPF.
* Dynamic selections for LFA1 and LFB1:
SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODEE: LFA1, LFB1.
* Field selection for LFB1 and LFC1:
SELECTION-SCREEN FIELD SELECTION FOR NODE: LFB1, LFC1.
Here, selections are chosen from the available selection criteria and are given

names. An additional parameter PSTIDA is declared and linked to the node BKPF.
Dynamic selections are defined for the tables LFA1 and LFB1. Field selections are
defined for tables LFB1 and LFC1.
BC - ABAP Programming SAP AG
Editing Selections
1250 December 1999
SAP AG BC - ABAP Programming
Editing the Database Program
December 1999 1251
Editing the Database Program
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 [Page 449]. 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.
Main program SAPDB<ldb>
INCLUDE DB<ldb>TOP.
INCLUDE DB<ldb>XXX.
INCLUDE DB<ldb>001.
INCLUDE DB<ldb>002.
INCLUDE DB<ldb>FXXX.
INCLUDE DB<ldb>SXXX.

INCLUDE DB<ldb>001.
INCLUDE DB<ldb>002.

INCLUDE DB<ldb>FXXX.
INCLUDE DB<ldb>SXXX.

INCLUDE DB<ldb>F001.
PROGRAM SAPDB<ldb>.
NODES:
TABLES:
TYPES:
DATA:
PROGRAM SAPDB<ldb>.
NODES:
TABLES:
TYPES:
DATA:


Include programs
FUNCTION <name>.

ENDFUNCTION.
FUNCTION <name>.

ENDFUNCTION.
FUNCTION <name>.

ENDFUNCTION.
FUNCTION <name>.

ENDFUNCTION.
FORM PUT_<node>.


ENDFORM.
FORM PUT_<node>.

ENDFORM.

The main program SAPDB<ldb> usually contains the following include programs:
• DB<ldb>TOP
Contains global declarations.
• DB<ldb>XXX.
Contains further include programs for individual subroutines.
• DB<ldb>F<001>, DB<ldb>F<002>
User-defined include programs for extra functions.
The include program DB<ldb>XXX usually contains the following include programs:

×