... {TABLE itab}
| {itab [INDEX idx]} ... .
1. ... TABLE itab
2. ... itab INDEX idx
These alternatives specify at which position of the internal table itab
lines are to be inserted. If you use the option with the addition TABLE,
the position at which the line is inserted, is specified using the table key. If you use the option
with the addition INDEX, the table index is used for the specification. The latter option can only be used for index tables.
... TABLE itab
The lines line_spec to be inserted must be compatible> with the line type of the internal table. Depending on the table type, each line is inserted as follows:
If the internal table has a unique key, duplicate entries are not inserted. When inserting single lines,
sy-subrc is set to 4. When inserting multiple lines, an exception that cannot be handled is triggered.
Filling an internal table connection_tab with data of the database table spfli. Single lines are inserted using the table key and are filled with the content of the work area connection. Since the internal table has a unique key, duplicate entries are rejected. The better performing SELECT statement for which the internal table is specified directly after INTO TABLE could raise an exception due to the uniqueness of the table key.
DATA: BEGIN OF connection,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
distid TYPE spfli-distid,
distance TYPE spfli-distance,
END OF connection.
DATA connection_tab LIKE SORTED TABLE OF connection
WITH UNIQUE KEY cityfrom cityto
distid distance.
SELECT cityfrom cityto distid distance
FROM spfli
INTO connection.
INSERT connection INTO TABLE connection_tab.
ENDSELECT.
... itab INDEX idx
This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.
If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.
An exception that cannot be handled is raised when:
Within a LOOP loop,
you can omit the addition INDEX. Each line to be inserted
is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.