READ TABLE - index
Short Reference
ABAP Syntax ... INDEX idx [USING KEY keyname
] ... .
ABAP_ADDITION:
... USING KEY keyname
What does it do? If the INDEX addition is used, the READ
statement reads the row of the row number specified in idx with
respect to a table index. idx is a
numerical expression position
of the operand type i . If the value of idx is less than
or equal to 0 or greater than the number of table rows, no row is read
and sy-subrc is set to 4. If the read is successful, the system
field sy-tabix contains the row number specified in idx in
the primary or secondary table index used.
If the addition USING KEY is not used, the addition INDEX
can only be specified for index tables
and determines the row to be read from the
primary table index .
Latest notes: Table expressions
enable reads to be performed in operand positions too. Here an index is
specified as a numeric argument idx
.
Example ABAP Coding Reads the first ten rows of the internal table
sflight_tab using the primary table index. Instead of the DO
loop, the LOOP loop can normally also be
used to do this.
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH NON-UNIQUE KEY seatsocc,
sflight_wa LIKE LINE OF sflight_tab.
...
SELECT *
FROM sflight
INTO TABLE sflight_tab
WHERE carrid = 'LH' AND
connid = '400'.
...
DO 10 TIMES.
READ TABLE sflight_tab INDEX sy-index INTO sflight_wa.
IF sy-subrc <(><<)>> 0.
EXIT.
ENDIF.
...
ENDDO.
ABAP_ADDITION ... USING KEY keyname
What does it do? If the addition USING KEY is used, a table key can
be declared in keyname to declare the table
index to be used explicitly.
If the table has a sorted
secondary key , this can be
specified in keyname . The row to be read is then determined from
its secondary table index . You
cannot declare a secondary hashed key .
If the primary table key is
specified under the name primary_key , the table must be an index
table, and the behavior is the same as when USING KEY is not
specified.
Latest notes: If a sorted secondary key exists, the INDEX
addition can be used for all table types, if USING KEY is used.
Table expressions enable reads to
be performed in operand positions too. The table key for an index is
specified using KEY keyname INDEX
.
Example ABAP Coding Reads the first ten rows of the internal table
sflight_tab using a secondary table index. Instead of the DO
loop, the LOOP loop can also be used to
do this.
DATA: sflight_tab TYPE HASHED TABLE OF sflight
WITH UNIQUE KEY primary_key
COMPONENTS carrid connid fldate
WITH NON-UNIQUE SORTED KEY occupied_seats
COMPONENTS seatsocc,
sflight_wa LIKE LINE OF sflight_tab.
...
SELECT *
FROM sflight
INTO TABLE sflight_tab
WHERE carrid = 'LH' AND
connid = '400'.
...
DO 10 TIMES.
READ TABLE sflight_tab
INDEX sy-index USING KEY occupied_seats
INTO sflight_wa.
IF sy-subrc <(><<)>> 0.
EXIT.
ENDIF.
...
ENDDO.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved