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

The statement

SELECTION-SCREEN FIELD SELECTION FOR NODE|TABLE <node>.

declares a node <node> of a logical database for field selections in the selection include.

This means that you can list individual fields in the SELECT statements of the corresponding subroutine PUT_<node>, instead of having to use SELECT * to select all columns. This allows you to minimize the amount of data transferred from the database, which can often improve performance.

For each node for which field selection is allowed, you can specify the columns that you want to read using the FIELD addition to the GET statement in the executable program or in the FIELD_SELECTION parameter of the function module LDB_PROCESS. The database program of the logical database can access the names of the columns in the data object SELECT_FIELDS. The data object SELECT_FIELDS is automatically generated in the logical database program as follows:

TYPE-POOLS RSFS.

DATA SELECT_FIELDS TYPE RSFS_FIELDS.

You do not have to program these lines yourself. The data object SELECT_FIELDS is available in the database program and also in each connected executable program.

The type RSDS_FIELDS of the data object is defined in the type group RSDS as follows:

TYPE-POOL RSFS.

* Fields to be selected per table

TYPES: BEGIN OF RSFS_TAB_FIELDS,
         TABLENAME LIKE RSDSTABS-PRIM_TAB,
         FIELDS LIKE RSFS_STRUC OCCURS 10,
       END OF RSFS_TAB_FIELDS.

* Fields to be selected for all tables

TYPES: RSFS_FIELDS TYPE RSFS_TAB_FIELDS OCCURS 10.

RSDS_FIELDS is a deep internal table with the components TABLENAME and FIELDS. Each line of the TABLENAME column contains the name of a node that is designated for field selection. The table FIELDS contains the columns specified in the GET statements in the application program for each of these nodes. The FIELDS table have a format that allows you to use them directly in dynamic SELECT lists in SELECT statements.

To use the names of the columns in the logical database, you can specify the dynamic list FIELDS in the SELECT clause of the SELECT statements in the subroutine PUT_<node> for each node <node> for which field selections are allowed. To do this, you must read the corresponding internal table from the internal table SELECT_FIELDS. The following example shows how you can use a local data object of the subroutine for this purpose:

Example

Suppose the database table SCARR is the root node of the logical database ZHK and that SPFLI is its only subordinate node.

The selection Include DBZHKSEL contains the following lines:

SELECT-OPTIONS S_CARRID FOR SCARR-CARRID.

SELECT-OPTIONS S_CONNID FOR SPFLI-CONNID.

SELECTION-SCREEN FIELD SELECTION FOR TABLE SPFLI.

The subroutine PUT_SCARR of the database program SAPDBZHK uses the field selections as follows:

FORM PUT_SPFLI.

  STATICS: FIELDLISTS TYPE RSFS_TAB_FIELDS,
           FLAG_READ.

  IF FLAG_READ = SPACE.
    FIELDLISTS-TABLENAME = 'SPFLI'.
    READ TABLE SELECT_FIELDS WITH KEY FIELDLISTS-TABLENAME
                             INTO FIELDLISTS.
    FLAG_READ = 'X'.
  ENDIF.

  SELECT (FIELDLISTS-FIELDS)
         INTO CORRESPONDING FIELDS OF SPFLI FROM SPFLI
         WHERE CARRID = SCARR-CARRID
           AND CONNID IN S_CONNID.

    PUT SPFLI.

  ENDSELECT.

ENDFORM.

The line of the internal table SELECT_FIELDS that contains the value 'SCARR' in column SELECT_FIELD-TABLENAME is read into the local structure FIELDLISTS. The STATICS statements and the FLAG_READ field assure that the table DYN_SEL is read only once each time the executable program is run. The table FIELDLISTS-FIELDS is used in the dynamic SELECT clause.

An executable program to which the logical database HKZ is linked could now, for example, contain the following lines:

TABLES SPFLI.

GET SPFLI FIELDS CITYFROM CITYTO.

...

The FIELDS option of the GET statement defines which fields besides the primary key the logical database should read from the database table.

Internally, the system fills the table SELECT_FIELDS with the corresponding values. This can be demonstrated by adding the following lines to the program:

DATA: ITAB   LIKE SELECT_FIELDS,
      ITAB_L LIKE LINE OF ITAB,
      JTAB   LIKE ITAB_L-FIELDS,
      JTAB_L LIKE LINE OF JTAB.

START-OF-SELECTION.

  ITAB = SELECT_FIELDS.
  LOOP AT ITAB INTO ITAB_L.
    IF ITAB_L-TABLENAME = 'SPFLI'.
      JTAB = ITAB_L-FIELDS.
      LOOP AT JTAB INTO JTAB_L.
        WRITE / JTAB_L.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

These lines display the column names on the list as follows:

CITYTO

CITYFROM

MANDT

CARRID

CONNID

The fields of the primary key (MANDT, CARRID, CONNID) have been added automatically to the specified columns.

 

 

 

Leaving content frame