Selection Tables 

You use the statement

SELECT-OPTIONS <seltab> for <f>.

to declare a selection table in the program that is linked to the <f> column of a database table, or to an internal <f> field in the program. A selection table is an internal table object of the standard table type that has a standard key and a header line. Selection tables are used to store complex selections using a standardized procedure. They can be used in several ways. Their main purpose is to directly translate the selection criteria into database selections using the WHERE addition in Open SQL statements.

In addition to selection tables that you create using SELECT-OPTIONS, you can use the RANGES statement to create internal tables that have the structure of selection tables. You can use these tables with certain restrictions the same way you use actual selection tables.

Structure of Selection Tables

The row type of a selection table is a structure that consists of the following four components: SIGN, OPTION, LOW and HIGH. Each row of a selection table that contains values represents a sub-condition for the complete selection criterion. Description of the individual components:

The data type of SIGN is C with length 1. The contents of SIGN determine for each row whether the result of the row condition is to be included in or excluded from the resulting set of all rows. Possible values are I and E.

– I stands for "inclusive" (inclusion criterion - operators are not inverted)

– E stands for "exclusive" (exclusion criterion - operators are inverted)

The data type of OPTION is C with length 2. OPTION contains the selection operator. The following operators are available:

– If HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP. These operators are the same as those that are used for logical expressions. Yet operators CP and NP do not have the full functional scope they have in normal logical expressions. They are only allowed if wildcards ( '*' or '+' ) are used in the input fields, and no escape character is defined.

– If HIGH is filled, you can use BT (BeTween) and NB (Not Between). These operators correspond to BETWEEN and NOT BETWEEN that you use when you check if a field belongs to a range.

The data type of LOW is the same as the column type of the database table, to which the selection criterion is linked.

– If HIGH is empty, the contents of LOW define a single field comparison. In combination with the operator in OPTION, it specifies a condition for the database selection.

– If HIGH is filled, the contents of LOW and HIGH specify the upper and lower limits for a range. In combination with the operator in OPTION, the range specifies a condition for the database selection.

The data type of HIGH is the same as the column type of the database table, to which the selection criterion is linked. The contents of HIGH specify the upper limit for a range selection.

If the selection table contains more than one row, the system applies the following rules when creating the complete selection criterion:

  1. Form the union of sets defined on the rows that have SIGN field equal to I (inclusion).
  2. Subtract the union of sets defined on the rows that have SIGN field equal to E (exclusion).
  3. If the selection table consists only of rows in which the SIGN field equals E, the system selects all data outside the set specified in the rows.

RANGES Tables

You can use the RANGES statement to create internal tables of the same type as selection tables.

RANGES <rangetab> FOR <f>.

This statement is simply a shortened form of the following statements:

DATA: BEGIN OF <rangetab> OCCURS 0,
         SIGN(1),
         OPTION(2)
         LOW  LIKE <f>,
         HIGH LIKE <f>,
      END OF <rangetab>.

Internal tables created with RANGES have the same structure as selection tables, but they do not have the same functionality.

Selection tables created with RANGES are not components of the selection screen. As a result, no relevant input fields are generated. Also, you cannot use a RANGES table as a data interface in program <prog> called by the following statement:
SUBMIT <prog> WITH <rangetab> IN <table>.

However, you can use RANGES to create the table <table> in the calling program. The main function of RANGES tables is to pass data to the actual selection tables without displaying the selection screen when executable programs are called.

Although you can use RANGES tables like actual selection tables in the WHERE clause of Open SQL statements and in combination with the IN operator in logical expressions, they are not linked to a database table. This means that RANGES tables:

REPORT DEMO1.

RANGES S_CARRID FOR SPFLI-CARRID.

S_CARRID-SIGN = 'I'.
S_CARRID-OPTION = 'EQ'.
S_CARRID-LOW = 'LH'.

APPEND S_CARRID.

SUBMIT DEMO2 WITH CARRID IN S_CARRID.

In this example, RANGES table S_CARRID is created with reference to column CARRID of database table SPFLI. Fields S_CARRID-LOW and S_CARRID-HIGH have the same type as CARRID. The header line of internal table S_CARRID is filled and appended to the table. Program DEMO2 is called. If DEMO2 is linked to logical database F1S, its selections screen contains the fields of selection criterion CARRID from the logical database. These fields are filled with the contents of the RANGES table.