sapdev logo background
sapdev logo sapdev logo
Comments

ABAP READ TABLE Statement syntax, information and example SAP source code



Return to Statement index



READ TABLE itab

Short Reference

ABAP Syntax READ TABLE itab {
table_key
| free_key
| index } result .

What does it do? This statement reads a row from the internal table
itab . itab is a functional operand position .
The row must be specified by naming values for either table_key for a table key, a free condition free_key , or 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 row contents are read.
If the row to be read is not specified uniquely, the first suitable row is read. In the case of index tables, this row has the lowest row number of all suitable rows in 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 is only available 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
0Row is found. sy-tabix is set to the row number of the entry in the primary or secondary table index used. If a hash key is used, it is set to 0.
2Like sy-subrc equals 0. Distinguishes cases that use the addition COMPARING in result .
4The row was not found. If the entry was determined using a binary search, sy-tabix is set to the table index of the entry before which it would be inserted using INSERT ... INDEX ... , to preserve the sort order. This is the case if the addition table_key
or free_key was specified for a initial part of the table key of sorted keys , or if the addition
BINARY SEARCH was specified explicitly. Otherwise, sy-tabix is undefined.
8Like sy-subrc equals 4. If the entry was determined using a binary search, and the end of the table was reached, then sy-tabix
is set to the number of rows + 1.

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

Latest notes:
As an alternative to the READ TABLE statement, you can use table expressions . This allows read access to individual table rows at operand positions.
If multiple rows of an internal table are to be read, the LOOP statement generally displays better performance than using the READ TABLE statement in a loop.



Runtime Exceptions
Non-catchable Exceptions

Reason for error: When reading a table with READ ... WITH [TABLE] KEY
, overlapping or duplicate key specifications were used.
Runtime error: DYN_KEY_DUPLICATE
Reason for error: When reading a table of the type SORTED , the specified key fields have to be an initial part of the table key when BINARY SEARCH is specified.
Runtime error: ITAB_ILLEGAL_BINARY_SEARCH
Reason for error: No key specified.
Runtime error: ITAB_KEY_COMPONENT_MISSING
Reason for error: Invalid key specified when accessing a key table.
Runtime error: ITAB_KEY_ILLEGAL_COMPONENT
Reason for error: Invalid key specified implicitly in the Unicode context.
Runtime error: READ_ITAB_UC_KEY_ERROR
Reason for error: Invalid incompatible work area specified.
Runtime error: OBJECTS_WA_NOT_COMPATIBLE
Reason for error: Memory area violated when TABLES parameter accessed
Runtime error: ITAB_STRUC_ACCESS_VIOLATION
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




READ_REPORT_INTERNAL
READ_TABLE_DBTAB




comments powered by Disqus