INSERT itab

Short Reference

Syntax

INSERT line_spec INTO itab_position [result].

Effect

This statement adds one or more lines line_spec to a position itab_position of an internal table. The position can be specified using the table key or the table index. As of release 6.10, result can be used to set a reference as a field symbol or data reference to the inserted line when inserting a single line.

System Fields

sy-subrc Meaning
0 One or more lines were inserted.
4 No line was inserted because either a line of the same unique key already existed when inserting single lines using the table key or the specified index was greater than the current number of lines plus one when inserting the lines using the table index.

Example

Insertion of single lines using the table index in a standard table int_tab and insertion of references to these lines using the table key in a hashed table ref_tab. The output in the LOOP loops result in the numbers 10 to 1 for int_tab and the numbers 1 to 10 for ref_tab.

DATA: int  TYPE i,
      dref TYPE REF TO i.

DATA: int_tab LIKE STANDARD TABLE OF int,
      ref_tab LIKE HASHED TABLE OF dref
              WITH UNIQUE KEY table_line.

DO 10 TIMES.
  INSERT sy-index
         INTO int_tab INDEX 1
         REFERENCE INTO dref.
  INSERT dref
         INTO TABLE ref_tab.
ENDDO.

LOOP AT int_tab INTO int.
  WRITE / int.
ENDLOOP.
SKIP.
LOOP AT ref_tab INTO dref.
  WRITE / dref->*.
ENDLOOP.

Exceptions

Non-Catchable Exceptions