Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete Internal Table Processing 

READ TABLE- obsolete_key

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Obsolete Syntax

READ TABLE itab { { }
                | { WITH KEY dobj }
                | { WITH KEY = dobj [BINARY SEARCH] } } result.

Alternatives

1. ... { }
2. ... WITH KEY dobj

3. ... WITH KEY = dobj [BINARY SEARCH]

Effect

As well as the additions listed in the statement READ TABLE for specifying the individual rows to be read, outside of classes the search key can also be specified in three obsolete forms.

Alternative 1

... { }

Effect

If the search key is not specified explicitly, the internal table itab must be a standard table with a header line. The first row found in the internal table is read for which the values in the columns of the standard key match the values in the corresponding components of the header line. Key fields in the header line that only contain blank characters are handled as if they match all values. If all the key fields in the header line only contain blank characters, the first entry in the table is read.


Notes

  • In Unicode programs, the standard key of the internal table must not contain any byte-like components when the implicit search key is used.
  • The statement READ TABLE itab ... is not the same as the explicit declaration of the header line itab as a work area wa in the statement READ TABLE itab FROM wa .... In the latter, the table key and not the search key of the header field is used for the search.
  • The search key can be omitted regardless of the additional obsolete short form (where no explicit target area is specified).

Example

In the following READ statement (in contrast to the example for READ TABLE - table_key) no entry is usually found, since the whole standard key is compared. In particular, the components deptime and arrtime that belong to the standard key of the internal table are of type t and contain the value "000000" instead of blank characters as an initial value in the header line. Only table entries that contain exactly these values are read.

DATA: spfli_tab TYPE STANDARD TABLE OF spfli 
                WITH NON-UNIQUE KEY carrid connid 
                WITH HEADER LINE. 

FIELD-SYMBOLS <spfli> TYPE spfli. 

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

spfli_tab-carrid = 'LH'. 
spfli_tab-connid = '0400'. 
READ TABLE spfli_tab ASSIGNING <spfli>. 

Alternative 2

... WITH KEY dobj

Effect

If a single data object is specified directly after the addition WITH KEY, the internal table itab must be a standard table. The first row found in the internal table is read whose left-aligned content matches the content of the data object dobj. The data object dobj expects only flat data types. In the search, the start of table rows that are longer than the data object dobj are handled as if they have the same data type dobj (casting).


Example

To use the addition WITH KEY dobj for evaluating specific key fields, a structure must be created that corresponds to the relevant starting part of the line type. In contrast to the example for READ TABLE - table_key, in the following program section, the client column mandt of the table spfli_tab must be respected by the search key.

DATA: spfli_tab TYPE STANDARD TABLE OF spfli 
                WITH NON-UNIQUE KEY carrid connid. 

DATA: BEGIN OF key_struc, 
        mandt  TYPE spfli-mandt  VALUE '000', 
        carrid TYPE spfli-carrid VALUE 'LH', 
        connid TYPE spfli-connid VALUE '0400', 
      END OF key_struc. 

FIELD-SYMBOLS <spfli> TYPE spfli. 

SELECT * 
       FROM spfli 
       INTO TABLE spfli_tab 
       WHERE carrid = 'LH'. 
READ TABLE spfli_tab WITH KEY key_struc ASSIGNING <spfli>. 

Alternative 3

... WITH KEY = dobj [BINARY SEARCH]

Effect

If the addition WITH KEY is followed by a single data object after an "equals" sign, the first row found in the internal table itab is read whose entire content corresponds to the content of the data object dobj. It must be possible to convert the data object dobj to the row type of the internal table. If the data type of dobj does not matchj the row type of the internal table, a conversion is performed for the comparison in accordance with the conversion rules.


Note

This statement has the same function as specifying the pseudo component table_line as a free key, and is replaced by this component.

READ TABLE itab WITH KEY table_line = dobj
                [BINARY SEARCH] ...


Example

Determines (obsoletely) whether a row in an internal table exists with an elementary row type. The comment lines show the generally valid syntax with the pseudo-component table_line.

DATA itab TYPE TABLE OF i. 

DO 10 TIMES. 
  APPEND sy-index TO itab. 
ENDDO. 

READ TABLE itab WITH KEY = 4 
           TRANSPORTING NO FIELDS. 
* READ TABLE itab WITH KEY table_line = 4 
*                 TRANSPORTING NO FIELDS. 

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

Exceptions


Non-Catchable Exceptions

  • Cause: The key has stricter alignment requirements than the individual table rows.
    Runtime Error: READ_BAD_KEY_ALIGN
  • Cause: The key is longer than a table row and cannot be shortened.
    Runtime Error: READ_BAD_KEY_PARTIAL