READ TABLE - table_key

Syntax

... { FROM wa }
  | { WITH TABLE KEY {comp_name1|(name1)} = dobj1
                     {comp_name2|(name2)} = dobj2
                     ...                           } ... .

Alternatives:

1. ... FROM wa

2. ... WITH TABLE KEY ...

Effect:

The values of the search key can be specified either implicitly in a work area wa after FROM, or by explicitly listing the components of the table key after TABLE KEY.

Alternative 1

... FROM wa


Effect:

The work area wa must be a data object that is compatible with the line type of the internal table. The first found line of the internal table is read for which the values in the columns of the table key match the values in the corresponding components of wa.

Note:

Apart from in classes, the specification FROM wa can be omitted if the internal table has a header line itab with the same name. In this case, the statement then does not evaluate the content of the table key, but instead evaluates the standard key. Initial fields receive special treatment (see obsolete variants of READ TABLE).

Alternative 2

... WITH TABLE KEY ...


Effect:

Each component of the table key must listed either directly as comp_name1 comp_name2 ..., or as a bracketed character-type data object name1 name2 ..., which contains the name of the component when the statement is executed (before release 6.10 in upper case). If name contains spaces only, this component specification is ignored when the statement is executed. A data object must be assigned to each component, which is compatible with or can be converted to the data type of the component. The first found line of the table is read, for which the values in the columns of the table key match the values in the assigned data objects dobj1 dobj2 .... If necessary, the content of dobj1 dobj2 ... is converted to the data type of the component before the comparison.

The different table types are accessed as follows:

Notes:

Example:

Reading from lines of the internal table spfli_tab using the table key. The first READ statement evaluates the work area spfli_key, in the second READ statement, the components of the table key are specified explicitly.

DATA: spfli_tab TYPE SORTED TABLE OF spfli
                WITH UNIQUE KEY carrid connid,
      spfli_key LIKE LINE OF spfli_tab.

FIELD-SYMBOLS <spfli> TYPE spfli.

...

SELECT *
       FROM spfli
       INTO TABLE spfli_tab
       WHERE carrid = 'LH'.

...

spfli_key-carrid = 'LH'.
spfli_key-connid = '0400'.

READ TABLE spfli_tab FROM spfli_key ASSIGNING <spfli>.

IF sy-subrc = 0.
  ...
ENDIF.

...

READ TABLE spfli_tab
           WITH TABLE KEY carrid = 'LH' connid = '2402'
           ASSIGNING <spfli>.

IF sy-subrc = 0.
  ...
ENDIF.