Entering content frameReading Lines Using the Index Locate the document in its SAP Library structure

You can use the READ statement to read lines in tables using their index. To read a single line of an index table, use the statement:

READ TABLE <itab> INDEX <idx> <result>.

The system reads the line with the index <idx> from the table <itab>. This is quicker than searching using the key. The <result> part can specify a further processing option for the line that is retrieved.

If an entry with the specified index was found, the system field SY-SUBRC is set to 0 and SY-TABIX contains the index of that line. Otherwise, SY-SUBRC is set to a value other than 0.

If <idx> is less than or equal to 0, a runtime error occurs. If <idx> is greater than the number of lines in the table, SY-SUBRC is set to 4.

Example

Example

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 20 TIMES.
  LINE-COL1 = SY-INDEX.
  LINE-COL2 = 2 * SY-INDEX.
  APPEND LINE TO ITAB.
ENDDO.

READ TABLE ITAB ASSIGNING <FS> INDEX 7.

WRITE:   SY-SUBRC, SY-TABIX.
WRITE: / <FS>-COL1, <FS>-COL2.

The output is:

    0         7
         7         14

The example creates a sorted table ITAB and fills it with 20 lines. The line with index 7 is read and assigned to the field symbol <FS>.

 

 

 

Leaving content frame