ABAPINSERT_ITAB_POSITION - INSERT ITAB POSITION
CL_GUI_FRONTEND_SERVICES - Frontend Services ROGBILLS - Synchronize billing plansThis documentation is copyright by SAP AG.
INSERT - itab_position
Syntax
... {TABLE itab}
| {itab INDEX idx}
| {itab} ... .
Alternatives:
1. ... TABLE itab
2. ... itab INDEX idx
3. ... itab
Effect
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 isspecified using the primary table key. If you use other options, a line number of the table index is used for the specification. The latter option can only be used forindex tables.
Note
The insert position is defined exclusively using theprimary table key or theprimary table index. For thesecondarytable key in the internal table, the system checks whether it is unique and adds the new table rowto the corresponding administration (hash administration, secondary table index). In the case of secondarykeys, administration is updated before the next access to the table, while with non-unique secondary keys, it is updated before the next usage of the secondary key.
Alternative 1
... TABLE itab
Effect
The lines line_spec to be inserted must becompatiblewith the line type of the internal table. Depending on the table type, each line is inserted as follows:
- For standardtables, each new line is appended as the last line in the internal table regardless of the primary table key.
- For sortedtables, each new line is inserted into the sort order of the internal table according to its keyvalues for the primary key and the table index of the following lines is increased by one. If the internal table does not have a unique key, duplicate entries are inserted before the existing line.
- For hashedtables, each new line is inserted into the internal table by the hash administration according to its key values for the primary key.
If the internal table has a unique key, duplicate entries are not inserted. When inserting single lines,sy-subrc is set to 4 if a duplicate entry in the primary key would occur and a handled exceptionof the class CX_SY_ITAB_DUPLICATE_KEY is triggered if a duplicate entry in the secondary key would occur. When inserting multiple lines, an exception that cannot be handled is triggered.
Note
When using the primary table key, it is important to note that this may also be thestandardkey that covers all character-like and byte-like components for structured row types. An empty standardkey is possible only for standard tables for which INSERT already works in the same way as APPEND.
Example
Filling an internal table connection_tab with data of the database table spfli. Singlelines are inserted using the primary 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 INTOTABLE 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.
Alternative 2
... itab INDEX idx
Effect
This variant can only be used for standard tables andsortedtables. Each of the lines to be inserted line_specis inserted before the line with line number idx in the primary table index. The line numbers for subsequent lines in the primary table index increase by 1. idx is anumerical print position of operand type i.
If idx contains a value equal to the number of the existing table lines plus one, the new lineis 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:
- idx contains a value less than or equal to 0
- A single line to be inserted would cause a duplicate entry in a unique primary or secondary table key
- A block of lines to be inserted would cause a duplicate entry in a unique primary table key
- A line to be inserted would disrupt the sort order of sorted tables
However, the changing ofthe sort sequence in relation to a sorted secondary key never leads to an exception. Instead, the corresponding secondary index is either immediately updated(direct update) or updated after a delay(lazy update).
If a single line to be inserted results in a duplicate entry in a unique secondary table key, a treatable exception from class CX_SY_ITAB_DUPLICATE_KEY is raised.
Alternative 3
... itab
Effect
This variant is only possible within a LOOPloop using the same table and when the USINGKEY addition is not specifed for LOOP. Each line to be inserted can be inserted before the current line in the LOOP.
If the current row has already been deleted in the same loop, however, the response is undefined.
Note
The use of this alternative is not recommended. Instead, the line numbers should be specified explicitly with the INDEX addition.
rdisp/max_wprun_time - Maximum work process run time rdisp/max_wprun_time - Maximum work process run time
This documentation is copyright by SAP AG.
Length: 9513 Date: 20120522 Time: 233306 triton ( 291 ms )






