Ansicht
Dokumentation

ABAPINSERT_ITAB_POSITION - INSERT ITAB POSITION

ABAPINSERT_ITAB_POSITION - INSERT ITAB POSITION

BAL Application Log Documentation   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

INSERT, itab_position

Short Reference



... ${TABLE itab$}
  $| ${itab INDEX idx$}
  $| ${itab$} ...

Alternatives:

1. ... TABLE itab

2. ... itab INDEX idx

3. ... itab

Effect

These alternatives specify the position in the internal table itab at which lines are inserted. In the variant with the addition TABLE, the position of the insert is specified using the primary table key. In any of the other variants, a line number from the primary table index is used. The latter is only possible for index tables.

Note

The insert position is determined exclusively using either the primary table key or the primary table index only. For the secondary table keys in the internal table, the system checks for uniqueness and adds the new table line to the corresponding administration (hash administration, secondary table index). In the case of secondary keys, the administration is updated before the next access; for non-unique secondary keys, it is updated before the secondary key is used again.

Alternative 1

... TABLE itab


Effect

The lines to be inserted line_spec must be compatible with the line type of the internal table. Depending on the table category, each line is inserted as follows:

  • For standard tables, each new line is appended as the last line to the internal table regardless of the primary table key.
  • For sorted tables, each new line is inserted into the sort order of the internal table in accordance with its key values with respect to the primary key. The line numbers in the primary table index of the following lines are increased by one. If the internal table has a non-unique key, duplicate entries are inserted before the existing line.
  • In hashed tables, each new line is inserted into the internal table by the hash administration in accordance with its key values with respect to the primary key.

If the internal table has one or more unique table keys, no entries are inserted that would produce duplicate entries in one of the unique table keys. When single lines are inserted, sy-subrc is set to 4 if a duplicate entry with respect to the primary key were to be produced, and a catchable exception of the class CX_SY_ITAB_DUPLICATE_KEY is raised if a duplicate entry with respect to a secondary key were to be produced. If multiple lines are inserted, an uncatchable exception is raised.

Note

If the primary table key is used, it should be noted that this key can be the standard key that covers all character-like and byte-like components if the line type is structured. An empty standard key is possible only for standard tables. In these tables, INSERT always works like APPEND in this variant.

Example

Filling of an internal table connection_tab with data from the database table spfli. Single lines 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 primary key, any duplicate entries are discarded. The better performing SELECT statement, in which the internal table is specified directly after INTO TABLE, could raise an exception due to the uniqueness of the primary table key.

Alternative 2

... itab INDEX idx


Effect

This variant can only be used for standard tables and sorted tables. Each of the lines to be inserted line_spec is inserted before the line with the line number idx in the primary table index. The line numbers in the primary table index of the following lines are increased by one. idx is a numeric expression position of operand type i.

If idx contains a value that corresponds to the number of existing table lines plus one, the new line is appended as the last line to the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.

An uncatchable exception is raised in the following cases:

  • If idx contains a value less than or equal to 0.
  • If a single line to be inserted would produce a duplicate entry in a unique primary or secondary table key.
  • If a block of lines to be inserted would produce a duplicate entry in a unique primary table key.
  • If a line to be inserted would disrupt the sort order of a sorted table.
Modifying the sort order with respect to a sorted secondary key, however, never raises an exception. Instead, the associated secondary index is either updated directly (direct update) or updated after a delay (lazy update).

If a single line to be inserted produces a duplicate entry in a unique secondary table key, a catchable exception of the class CX_SY_ITAB_DUPLICATE_KEY is raised.

Example

Insertion of a line after a previously searched for line.

Alternative 3

... itab


Effect

This variant is only possible within a LOOP across the same internal table and if the addition USING KEY is not specified in the LOOP. Each line to be inserted can be inserted in front of the current line in the LOOP.

If the current line was already deleted in the same loop, however, the behavior is undefined.

Note

This alternative is not recommended. Instead, the addition INDEX should be used to specify the line number explicitly.

Example

Conditional insertion of a line in front of every line in an internal table.






BAL Application Log Documentation   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.

Length: 8523 Date: 20240420 Time: 100754     sap01-206 ( 141 ms )