... { {VALUES wa}
| {FROM wa|{TABLE itab [ACCEPTING DUPLICATE KEYS]}} }.
1. ... {VALUES wa} | {FROM wa} ...
2. ... FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...
After FROM and VALUES,
you can specify a non-table-type data object wa. After
FROM, you can also specify an internal table
itab. The contents of the row(s) to be inserted are taken from these data objects.
... {VALUES wa} | {FROM wa} ...
If you specify a non-table-type work area wa, a row is created from its contents for insertion in the database table. The content of the row to be inserted is taken from the work area wa without taking its data type into consideration and without conversion from left to right according to the structure of the database table or the view. The work area has to meet the prerequisites for use in Open SQL statements.
The new row is inserted in the database table if this does not already contain a row with the same primary key or the same unique secondary index. If it does, the row is not inserted and sy-subrc is set to 4.
If a view is specified in target that does not include all columns in the database table, these are set to the type-related initial value or to the null value in the inserted rows. The latter applies only if, for the relevant database column, the attribute initial value is not selected in the ABAP Dictionary.
Inserting a new airline company in the database table SCARR.
DATA scarr_wa TYPE scarr.
scarr_wa-carrid = 'FF'.
scarr_wa-carrname = 'Funny Flyers'.
scarr_wa-currcode = 'EUR'.
scarr_wa-url = 'http://www.funnyfly.com'.
INSERT INTO scarr VALUES scarr_wa.
... FROM TABLE itab [ACCEPTING DUPLICATE KEYS] ...
If you specify an internal table itab, several rows are created from its content for insertion in the database table. A row for insertion into the table is taken from each row of the internal table according to the same rules as for a single work area Einfügenwa. The line type of the internal table has to meet the prerequisites for use in Open-SQL statements.
If a row witht he same primary key or a same unique secondary index does not already exist in the database table for any of the rows to be inserted, all rows are inserted and sy-subrc is set to 0. If the internal table is empty, sy-subrc is also set to 0. The system field sy-dbcnt is always set to the number of rows that were actually inserted.
If a row with the same primary key or a same unique secondary index already exists in the database table for one or more of the rows to be inserted, these rows cannot be inserted. In this situation, there are three possibilities:
If the runtime error is prevented because an exception is being treated, instead of using addition ACCEPTING DUPLICATE KEYS, if required, you have to initiate a program-controlled database rollback.