Variants: See Short forms not allowed in line
operations. Variant 1 Effect is set as follows: SY-SUBRC = 4: is set to 0. Example Effect The is set as follows: SY-SUBRC = 4: Example Variant 3 Effect is set in the same way as in variant 1. If you insert an empty table,
SY-SUBRC is set to 0. Example Variant 4 See Compatible line types with INSERT INTO TABLE. Effect Notes Performance: Note Runtime errors: Related
1. INSERT [wa INTO|INITIAL LINE INTO] itab [INDEX idx].
2. INSERT [wa INTO|INITIAL LINE INTO] TABLE itab.
3. INSERT LINES OF itab1 [FROM idx1] [TO idx2]
INTO itab2 [INDEX idx3].
4. INSERT LINES OF itab1 [FROM idx1] [TO idx2]
INTO TABLE itab2.
If you use "wa INTO " the contents of the work area wa are
used as the new line. If the respective types of wa and itab
are incompatible, the contents of wa are moved according to
If you use INITIAL LINE INTO a line is inserted in the table, filled
with the initial values appropriate to the field types.
If you do not specify anything before itab , the new line is taken
from the header line of the internal table itab.
You use INDEX idx to specify the table index before which the line is
inserted into itab. If the table has idx - 1 entries, the
line is appended to the end of the table.
If you are adding entries to an index table using a
If the target table itab has the type SORTED TABLE
, it must be correctly sorted after you have finished inserting lines,
otherwise a runtime error is triggered.
If the target table is defined with a UNIQUE KEY, the
uniqueness must be preserved when you insert new lines. If it is not, a
runtime error is triggered.
The
When you specify the insertion point using INDEX idx:
DATA: VALUE TYPE I,
ITAB TYPE I OCCURS 100 WITH HEADER LINE.
ITAB = 5.
VALUE = 36.
INSERT ITAB INDEX 1.
INSERT VALUE INTO ITAB INDEX 2.
INSERT INITIAL LINE INTO ITAB INDEX 2.
In contrast to variant 1, you can use this variant for any table.
If the target table has a UNIQUE KEY , the system ignores
any duplicates when you insert lines and sets SY-SUBRC as described
below.
The way in which the system inserts a new entry into the table depends on the
table type:
The new entry is added to the end of the table. Generic insertion is therefore
the same as an
The new entry is added in its appropriate place, determined by the table key.
The key values are taken from the specified work area wa or from the
header line of the table. If the key is NON-UNIQUE, the entry is
placed at the top of the list of duplicates. The insertion point is determined
internally using a binary search. This makes the relationship between the
runtime required and the number of table entries logarithmic.
The new entry is placed in the internal hash administration of the table
according to the table key. The key values are taken from the specifiedwork
area wa or the header line of the table. The runtime required remains
constant, since it does not depend on the number of table entries. The key
must be unique.
TYPES: BEGIN OF PERSON,
NAME(10) TYPE C,
AGE TYPE I,
END OF PERSON.
DATA: P TYPE PERSON,
PTAB TYPE SORTED TABLE OF PERSON
WITH UNIQUE KEY NAME AGE.
P-NAME = 'Steve'. P-AGE = 20. INSERT P INTO TABLE PTAB.
P-NAME = 'Andy'. P-AGE = 20. INSERT P INTO TABLE PTAB.
P-NAME = 'Steve'. P-AGE = 17. INSERT P INTO TABLE PTAB.
P-NAME = 'Andy'. P-AGE = 20. INSERT P INTO TABLE PTAB.
Andy 20
Steve 17
Steve 20
SY-SUBRC is set to 4.
[INDEX idx3].
In INDEX idx3, like in variant 1, you specify the table index
position before which you want to insert the entry in itab2.
itab2 cannot have the type HASHED or ANY TABLE
, since these tables have no defined index operations.
If you are using a
If the target table itab2 has the type SORTED TABLE
, it must be correctly sorted when you have finished adding entries.
Otherwise, a runtime error occurs.
If the target table is defined with a UNIQUE KEY, you must
ensure that this characteristic is preserved when you add more entries to it.
If you try to add duplicate records, a runtime error occurs.
You can restrict the number of lines taken from the source table
itab1 by using FROM idx1 and TO idx2 . If you omit
FROM idx1, the range begins at the first line of itab1. If you
omit TO idx2 , the range ends at the last line of itab1.
This means that if you omit both FROM and TO , the whole
table is inserted into the target table. If itab1 has the table type
HASHED or ANY TABLE , you may not use the
FROM or TO additions, since these table types have no defined
index operations.
return code
TYPES NAME(10) TYPE C.
DATA: NAME_TAB_1 TYPE STANDARD TABLE OF NAME WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 5,
NAME_TAB_2 TYPE STANDARD TABLE OF NAME WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 5.
APPEND 'Alice' TO NAME_TAB_1.
APPEND 'Martha' TO NAME_TAB_1.
APPEND 'Ruth' TO NAME_TAB_1.
APPEND 'Harry' TO NAME_TAB_2.
APPEND 'Walter' TO NAME_TAB_2.
INSERT LINES OF NAME_TAB_1 FROM 2 INTO NAME_TAB_2 INDEX 2.
Unlike variant 3, you can use this variant for any source or target table.
The way in which the lines from the source table itab1 are inserted
into the target table itab2 depends, as in variant 2, on the table type of itab2.
If the target table is defined with a UNIQUE KEY, you must
ensure that this characteristic is preserved when you add new entries. If you
try to add duplicate entries, a runtime error occurs. If the key is
non-unique, duplicates from the source table are inserted before the entries
in the target table. The sequence of the duplicates is the same as in the
source table.
Inserting a line into the middle of an internal table 100 bytes wide with 200
entries, requires around
Inserting a table 100 bytes wide with 500 entries into the middle of a
similar-sized table can be up to 20 times quicker.