ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables → Processing Statements for Internal Tables → READ TABLE itab → READ TABLE - result
Internal Tables, Output Area
This example demonstrates how, and where to, the row contents of internal tables are read.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: BEGIN OF line,
col1 TYPE i,
col2 TYPE i,
END OF line.
DATA itab LIKE SORTED TABLE OF line WITH UNIQUE KEY col1.
FIELD-SYMBOLS <fs> LIKE LINE OF itab.
DO 4 TIMES.
line-col1 = sy-index.
line-col2 = sy-index ** 2.
INSERT line INTO TABLE itab.
WRITE: / line-col1, line-col2.
ENDDO.
SKIP.
ULINE.
<span class="blue">* INTO line COMPARING</span>
line-col1 = 2.
line-col2 = 3.
READ TABLE itab FROM line INTO line COMPARING col2.
WRITE: 'SY-SUBRC =', (1) sy-subrc.
SKIP.
WRITE: / line-col1, line-col2.
SKIP.
ULINE.
<span class="blue">* INTO line TRANSPORTING</span>
CLEAR line.
READ TABLE itab WITH TABLE KEY col1 = 3
INTO line TRANSPORTING col2.
WRITE: 'SY-SUBRC =', (1) sy-subrc,
/ 'SY-TABIX =', (1) sy-tabix.
SKIP.
WRITE: / line-col1, line-col2.
SKIP.
ULINE.
<span class="blue">* TRANSPORTING NO FIELDS</span>
READ TABLE itab WITH KEY col2 = 16 TRANSPORTING NO FIELDS.
WRITE: 'SY-SUBRC =', (1) sy-subrc,
/ 'SY-TABIX =', (1) sy-tabix.
SKIP.
ULINE.
<span class="blue">* ASSIGNING</span>
READ TABLE itab WITH TABLE KEY col1 = 2 ASSIGNING <fs>.
<fs>-col2 = 100.
LOOP AT itab INTO line.
WRITE: / line-col1, line-col2.
ENDLOOP.
Description
Four alternatives for output behaviour during the reading of internal tables are shown. First a sorted table is filled with a list of square numbers.
In the first alternative, the work area line
, which is compatible with the
row type, is filled with the numbers 2 and 3. Using the READ
statement the rows of the table are found, in which the keyfield
col1
has the same contents as the work area, and these are then copied.
sy-subrc
is two because different numbers were found during the comparison of field col2
.
In the second alternative, the READ
statement is used to read those rows
in which the keyfield col1
has the value 3. Only the content of col2
is copied to the work area line
. sy-subrc
has
the value zero and sy-tabix
is three because itab
is an index table.
In the third alternative, the READ
statement is used to find the rows of
the table in which col2
is 16. The primary table key is not used. No fields are copied to the work area and no rows are assigned a field symbol. Only system fields are set.
sy-subrc
is zero because a row has been found and sy-tabix
is four.
In the READ
statement of the final alternative, the rows of the table are
read in which the keyfield col1
has the value 2 and are then assigned to
the field symbol <fs>
. The component col2
of <fs>
is assigned the value 100. This also changes the corresponding field of the table.