Ansicht
Dokumentation

ABAPREAD_TABLE - READ TABLE

ABAPREAD_TABLE - READ TABLE

Vendor Master (General Section)   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

READ TABLE itab

Short Reference



READ TABLE itab ${ table_key
                $| free_key
                $| index $} result.


Effect

This statement reads a line from the internal table itab. itab is a functional operand position.

The line must be specified by specifying values for either table_key for a table key, using a free condition free_key, or by specifying an index index. The latter is possible only for index tables and when using a sorted secondary key. The output response result determines how and to where the line content is read.

If the line to be read is not specified uniquely, the first suitable line is read. In index tables, this line has the lowest line number of all suitable lines with respect to the table index used.

If the internal table is specified as the return value or result of a functional method, a constructor expression, or a table expression, the value only exists when the statement is executed. Afterwards, it is no longer possible to access the internal table.

System Fields

The statement READ TABLE sets the values for the system fields sy-subrc and sy-tabix.

sy-subrc Meaning
0 Line is found. sy-tabix is set to the line number of the entry in the primary or secondary table index used. If a hash key is used, it is set to 0.
2 Like sy-subrc equals 0. Distinguishes cases that use the addition COMPARING in result.
4 Line was not found. If the entry was determined using a binary search, sy-tabix is set to the line number of the entry in the primary or secondary table index in front of which it would be inserted using INSERT ... INDEX ..., to preserve the sort order. This is the case if, when sorted keys are used, the addition table_key or free_key was specified in addition to the complete table key or if the addition BINARY SEARCH was specified explicitly. Otherwise, sy-tabix is undefined (-1).
8 Line was not found. The entry was found using a binary search and the end of the table was reached. sy-tabix is set to the number of lines + 1.

The system fields sy-tfill and sy-tleng are also filled.

Notes

  • There is no implicit selection of a suitable key or index. The used table key or table index is always specified uniquely. The syntax check issues a warning if there is a suitable secondary table key but this table key is not used. This warning should be removed through using the key. However, in exceptional cases, it can be bypassed using a pragma.
  • As an alternative to the statement READ TABLE, table expressions can be used to allow reads to be performed on individual table lines at operand positions.
  • If multiple lines of an internal table are to be read, the statement LOOP generally has better performance than using the statement READ TABLE in a loop.

Reading of individual table lines from a standard table in a WHILE loop. The table lines are read in reverse order with respect to the sorted secondary key sort_key. A CHECK statement exits the loop if the specified condition is not met. This construct demonstrates how an internal table could be processed in reverse order, before the addition STEP was introduced for the LOOP statement.

Reading of individual table lines from a standard table in a WHILE loop. The table lines are read in reverse order with respect to the sorted secondary key sort_key. A CHECK statement exits the loop if the specified condition is not met. This construct replaces the missing option of performing LOOP statements in reverse order. See also the corresponding executable example with a FOR expression.

Exceptions

Non-Catchable Exceptions

  • Cause: When reading a table with READ ... WITH $[TABLE$] KEY, overlapping or duplicate keys were used.
    Runtime Error: DYN_KEY_DUPLICATE
  • Cause: When reading a table of the type SORTED, the specified key fields must be an initial part of the table key when BINARY SEARCH is specified.
    Runtime Error: ITAB_ILLEGAL_BINARY_SEARCH
  • Cause: Missing key specification.
    Runtime Error: ITAB_KEY_COMPONENT_MISSING
  • Cause: Invalid key specified when accessing a key table.
    Runtime Error: ITAB_KEY_ILLEGAL_COMPONENT
  • Cause: Invalid implicit key specification.
    Runtime Error: READ_ITAB_UC_KEY_ERROR
  • Cause: Invalid incompatible work area specification.
    Runtime Error: OBJECTS_WA_NOT_COMPATIBLE
  • Cause: Memory area violated when TABLES parameter accessed
    Runtime Error: ITAB_STRUC_ACCESS_VIOLATION






Fill RESBD Structure from EBP Component Structure   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 9163 Date: 20240425 Time: 133821     sap01-206 ( 64 ms )