INSERT in a sorted table with unique key
* Entries: 1000, Duplicates: 250
* Line width: 100, Key width: 20
* ITAB2 takes 750 entries with unique key K
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
INSERT WA INTO TABLE ITAB2.
IF SY-SUBRC <> 0.
" ...
ENDIF.
ENDLOOP.
INSERT in a hashed table with unique key
* Entries: 1000, Duplicates: 250
* Line width: 100, Key width: 20
* ITAB2 takes 750 entries with unique key K
REFRESH ITAB2.
LOOP AT ITAB1 INTO WA.
INSERT WA INTO TABLE ITAB2.
IF SY-SUBRC <> 0.
" ...
ENDIF.
ENDLOOP.
Documentation
You can use the same syntax (generic INSERT ... INTO TABLE ...) for
different types of tables (SORTED, HASHED).
Filling a sorted table is equivalent to building it up by "READ BINARY
SEARCH" and "INSERT ... INDEX SY-TABIX" but it is slightly faster and
more elegant to use the generic "INSERT ... INTO TABLE ...". See the
example for building a unique standard table, if you need no access
to the table while it is build up.
Filling a hash table is faster than for a sorted table. You can access
single entries very fast, but partial sequential loops are more
expensive than for sorted tables (see the separate example).