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

You can append either a workarea wa, an inital row INITIAL LINE or several rows of an internal table jtab.

Alternative 1

... wa

Effect

A new row is created to which the content of the workarea wa is assigned. wa is a functional operand position. To insert using the table key, you need to ensure that wa must be compatible with the row type of the internal table. To insert using the table index, you need to ensure that wa can be incompatible with the line type of the internal table. Wa is converted to the relevant row type, in accordance with the conversion rules.

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.
  • 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 the target table, the duplicates of the source block are inserted in their original order in front of the first duplicate in the target table.


Note

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