We are now familiar with the creation of internal tables and populating them with data. We will now see how do we actually use the data or retrieve the data from the internal tables.
1. Using Loop -Endloop
One of the ways of accessing or reading the internal table is by using LOOP-ENDLOOP.
Syntax
1
2
3
4
5
|
LOOP AT <itable> [INTO <wa>] ................................... ENDLOOP. |
Here when you say LOOP AT ITABLE, then the internal table ITABLE is read line by line. You can access the values of the columns for that line during any part of the LOOP-ENDLOOP structure. The value of the SY-SUBRC is set to 0, even if only one record is read.
2. Using READ
The other method of reading the internal table is by using the READ statement.
Syntax-
1
|
READ TABLE <itable> [INTO <wa>] INDEX <idx>. |
This statement reads the current line or line as specified by index <idx>. The value of SY-TABIX is the index of the line read. If an entry with the specified index is found, then SY-SUBRC is set to 0. If the specified index is less than 0, then run-time error occurs. If the specified index exceeds table size then SY-SUBRC is set to 4.