READ TABLE itab

READ - Read an Internal Table

Variants:
1a. READ TABLE itab FROM wa [ additions].
1b. READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn
[ additions].

2a. READ TABLE itab WITH KEY = v1 [BINARY SEARCH] [ additions].
2b. READ TABLE itab WITH KEY k1 = v1 ... kn = vn
[BINARY SEARCH][ additions].

3. READ TABLE itab INDEX idx [ additions ].

4. obsolete Varianten.

Effect

Reads an entry from the internal table . You can select the entry using a key or the index. The return code SY-SUBRC indicates whether the system found a matching entry. If the key you specify is not unique (key type NON-UNIQUE , the system takes the corresponding entry with the lowest index and places it in the output area.

SY-SUBRC = 0:

Entry found
SY-TABIX is set to the index of the entry.

SY-SUBRC = 2:

Entry found
SY-TABIX is set to the index of the entry. For more details, see the additions under COMPARING.

SY-SUBRC = 4:

Entry not found.
SY-TABIX is set depending on the table type and the BINARY SEARCH addition.
When you use the SORTED TABLE or STANDARD TABLE table types with the BINARY SEARCH addition, SY-TABIX points to the next largest table entry.
Otherwise, SY-TABIX is not set.

SY-SUBRC = 8:

Entry not found
The return code is only set for table type SORTED TABLE or for table type STANDARD TABLE with the BINARY SEARCH addition. SY-TABIX is set to (number of entries + 1).

READ TABLE itab FROM wa [ additions ].

READ TABLE itab WITH TABLE KEY k1 = v1 ... kn = vn [ additions].

Effect

The system uses the specified value for the table key to find the entry. If there is more than one entry for the key, it takes the first one. The way in which the system searches for entries in the table depends on the table type:

If you specify a key using k1 = v1 ... kn = vn, you must provide a full set of values. If the type of a value is incompatible with the type of the key, the system converts it into the type of the component using MOVE logic. If you do not know a component until runtime, you can specify it as the contents of field ni in the expression WITH WITH TABLE KEY ... (ni) = vi ....

Variant 2a

READ TABLE itab WITH KEY = v1 [BINARY SEARCH] [ additions].

Variant 2b

READ TABLE itab WITH KEY k1 = v1 ... kn = vn
[BINARY SEARCH] [ additions].

Effect

The specified key is used to find the required line. If the type of a value is not compatible with the type of the corresponding key, the system converts it into that type using MOVE logic . This is an asymmetric comparison logic, where the component type is always more important than the value type.
The way in which the system searches for table entries depends on the table type:

The system reads the first entry where k1 ... kn corrrespond to v1 ... vn. If you do not know a component until runtime, you can specify it as the contents of the field ni in the expression WITH KEY ... (ni) = vi .... If ni is empty at runtime, the system ignores that component. If ni contains an invalid component name, the system triggers a runtime errror.


Variant 3

READ TABLE itab INDEX idx [ additions ].

Effect

Reads the entry in the internal table itab with the index idx.