Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Internal Tables →  Processing Statements for Internal Tables →  INSERT itab 

INSERT - line_spec

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


... wa 
  | {INITIAL LINE}
 | {LINES OF jtab [FROM idx1] [TO idx2] [USING KEY keyname]} ...

Alternatives

1. ... wa
2. ... INITIAL LINE
3. ... LINES OF jtab [FROM idx1] [TO idx2] [USING KEY keyname]

Effect

Either a work area wa, an initial row INITIAL LINE, or multiple rows of an internal table jtab can be appended.

Alternative 1

... wa

Effect

A new row is created to which the content of the work area wa is assigned. wa is a general expression position. To insert using the table key, wa must be compatible with the row type of the internal table. To insert using the table index, wa must be incompatible with the row type of the internal table. wa is converted to the relevant row type, in accordance with the conversion rules. If an arithmetic expression is specified for wa, the row type of the internal table is respected when determining the calculation type.

When inserting individual rows into an internal table with non-unique table keys, the order of the duplicate rows in relation to these keys is determined in accordance with the insertion order of the individual rows. In the case of secondary table keys, this order is determined place during the lazy update.


Notes

  • If there is a conflict with the existing unique primary table key, no row is added and if a key access occurs, sy-subrc is set to 4. In an index access occurs, a non-handleable exception is raised. In the case of a conflict with a unique secondary table key, a handleable exception of the class CX_SY_ITAB_DUPLICATE_KEY is raised.
  • Specifying a calculation expression for wa is usually only a good idea for elementary row types.
  • With the exception, an obsolete short form is possible where wa INTO can be omitted if the internal table has a header line itab with the same name. The statement then uses the header line as the work area implicitly.

Alternative 2

... INITIAL LINE

Effect

A new row is created in which every component contains the type-specific initial value.


Example

Inserting an initial row which is also linked to a field symbol by the ASSIGNING addition. This means that initial rows can be processed directly.

DATA itab TYPE TABLE OF spfli. 

FIELD-SYMBOLS <line> LIKE LINE OF itab. 

INSERT INITIAL LINE INTO itab INDEX 1 ASSIGNING <line>. 
 <line>-carrid = '...'. 
... 

Alternative 3

... LINES OF jtab [FROM idx1] [TO idx2] [USING KEY keyname]

Effect

The rows of an internal table jtab are added as a block. jtab is a functional operand position. The row types of itab and jtab must be compatible when inserting using the table key and must be convertible when inserting using the index.

The inserted rows are sequentially taken from the table jtab. The order in which the rows are taken is the same as for the statement LOOP and can also be influenced by specifying a table key keyname after USING KEY. The additions FROM idx1 and TO idx2 have, in relation to jtab, the same syntax and effect as for LOOP.

When inserting rows as a block into an internal table with non-unique table keys, the order of the duplicate rows in relation to these keys is retained.

  • If there is already a duplicate entry in a sorted target table, the duplicates of the source block are inserted in their original order in front of the first duplicate in the target table.
  • When insertions are made in standard tables, however, INSERT always operates like the statement APPEND and the rows are appended in their original order after the last row as in the addition LINES OF .

If there is a conflict with an existing unique table key, a handleable exception is raised when inserting multiple rows from an internal table.


Note

When an internal tables is constructed, the constructor operators NEW and VALUE can also insert multiple rows from a table into the target table using LINES OF.