Skip to content

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

Logical Databases - Dynamic Selections

Alongside static selections, the selection screen of a logical database can also contain dynamic selections. Dynamic selections enable the user to instruct the logical database to make further user-defined selections for database reads, alongside the static selections defined in the selection include. Before the logical database can offer dynamic selections for a node, the statement SELECTION-SCREEN DYNAMIC SELECTIONS must be specified in the selection include.

If the node node specified here is requested by the associated program, the dynamic selections become part of the selection screen. After choosing Dynamic Selections, the user can make selections for the fields offered by the logical database. If called by the function module LDB_PROCESS, an appropriate parameter can be passed. In the database program, dynamic statements can be used to instruct the selections to read the data. The values of every program-specific selection criterion for which a dynamic selection node is defined are also passed to the logical database before the data is selected. The user can define the field list specified for dynamic selections as a selection view of the logical database.

Before the dynamic selections can be used in the SELECT statements of a subroutine put_node, the data object dyn_sel must be used that is declared implicitly in the logical database program with reference to the data type rsds_type from the type group RSDS. The data object dyn_sel is available only in the database program, but not in an associated executable program. dyn_sel is a deep structure with the following components:

  • clauses
    Internal table with the dynamic selections entered by the user (or any program-specific selection criteria) for dynamic WHERE conditions. In each row, the column tablename contains the name of a node reserved for dynamic selections. For each of these nodes, the table-like component where_tab contains the ranges conditions of the dynamic selections in a format that can be used directly in a dynamic WHERE.
  • texpr
    Contains the selections of the dynamic selections in an internal format (reverse Polish notation) that can be used for both the function modules FREE_SELECTIONS_INIT and FREE_SELECTIONS_DIALOG for program-driven creation of dynamic selections.
  • trange
    Internal table containing the selections of the dynamic selection as ranges tables. In each row, the column tablename contains the name of a node reserved for dynamic selections. For each of these nodes, the table-like component frange_t contains a column fieldname with the field names and selopt_t with the associated ranges tables.

Other versions: 7.31 | 7.40 | 7.54


Note

trange enables the selections for individual fields of the nodes to be accessed directly. Furthermore, selections with this format are easier to modify than selections in clauses format.


Example

Uses dynamic selections in a dynamic WHERE condition in the database program. The table SCARR is the root node of a logical database DEMO and the table SPFLI is the only successor. The selection include DBDEMOSEL contains the following lines:

SELECT-OPTIONS s_carrid FOR scarr-carrid.
SELECT-OPTIONS s_connid FOR spfli-connid.
SELECTION-SCREEN DYNAMIC SELECTIONS FOR TABLE scarr.

The subroutine put_scarr of the database program SAPDBDEMO uses the dynamic selections as follows:

FORM put_scarr.
  STATICS: dynamic_selections TYPE rsds_where,
           flag_read TYPE abap_bool.
  IF flag_read = abap_false.
    dynamic-selections-tablename = 'SCARR'.
    READ TABLE dyn_sel-clauses
               WITH KEY dynamic_selections-tablename
               INTO dynamic_selections.
    flag_read = abap_true.
  ENDIF.
  SELECT * FROM scarr
         WHERE  carrid IN s_carrid
         AND   (dynamic_selections-where_tab).
    PUT scarr.
  ENDSELECT.
ENDFORM.

The row of the internal table dyn_sel-clauses for which the column tablename contains the value "SCARR" is read to the local structure dynamic_selections. The STATICS statements and the field flag_read make sure that the table dyn_sel only needs to be read once each time the program is executed. The table where_tab is used in the dynamic WHERE clause.

Each executable program that uses the logical database and contains a NODES or TABLES statement for SCARR or SPFLI offers dynamic selections for the fields of the table SCARR on its selection screen and the logical database reads only those rows that meet the ranges conditions on the selection screen and the dynamic selections.


Example

Uses ranges tables in the database program. The same applies to the structure and selections as in the previous example. The subroutine put_scarr is now as follows:

FORM put_scarr.
  STATICS: dynamic_ranges TYPE rsds_range,
           dynamic_range1 TYPE rsds_frange,
           dynamic_range2 TYPE rsds_frange,
           flag_read TYPE abap_bool.
  IF flag_read = abap_false.
    dynamic_ranges-tablename = 'SCARR'.
    READ TABLE dyn_sel-trange
               WITH KEY dynamic_ranges-tablename
               INTO dynamic_ranges.
    dynamic_range1-fieldname = 'CARRNAME'.
    READ TABLE dynamic_ranges-frange_t
               WITH KEY dynamic_range1-fieldname
               INTO dynamic_range1.
    dynamic_range2-fieldname = 'CURRCODE'.
    READ TABLE dynamic_ranges-frange_t
               WITH KEY dynamic_range2-fieldname
               INTO dynamic_range2.
    flag_read = abap_true.
  ENDIF.
  SELECT * FROM scarr
         WHERE  carrid IN s_carrid
         AND    carrname IN dynamic_range1-selopt_t
         AND    currcode IN dynamic_range2-selopt_t.
    PUT scarr.
  ENDSELECT.
ENDFORM.

The row of the internal table trange for which the column tablename contains the value "SCARR" is read to the local helper table dynamic_ranges. The nested tables frange_t are read from fieldname to the local helper tables dynamic_range1 and dynamic_range2, depending on their content. The STATICS statements and the field flag_read make sure that the tables only need to be read once each time the program is executed. The nested tables selopt_t of these helper tables now contain the ranges tables for the database columns CARRNAME and CURRCODE. The tables selopt_t are used directly as ranges tables in the SELECT statement. CARRNAME and CURRCODE are the only other columns in the database table SCARR, which means this logical database offers the same functions as in the previous database.