SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Accesses → Open SQL → Open SQL - Write Accesses → INSERT dbtab →
INSERT dbtab - source
Syntax
... wa
| {TABLE itab [ACCEPTING DUPLICATE KEYS] }.
Alternatives:
1. ... wa ...
2. ... TABLE itab [ACCEPTING DUPLICATE KEYS] ...
Effect
You can specify a non-table-like data object wa after FROM
and VALUES. 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.
... wa ...
Effect
After VALUES and FROM you can specify a non-table-like work area wa, from whose content a row is created for insertion in the database table. The work area must fulfill 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 ABAP Dictionary.
By default, an automatic client handling is performed, which means that a client identifier specified in wa is not considered, but the current client is used instead. This has no effect on wa. You can switch off automatic client handling using the addition CLIENT SPECIFIED.
Notes
Example
Inserting a new airline 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.
... TABLE itab [ACCEPTING DUPLICATE KEYS] ...
Effect
You can specify an internal table itab after FROM, from whose content multiple rows are created for insertion in the database table. The row type of the internal table must fulfill the prerequisites for use in Open SQLstatements.
The content of each row of the internal table is composed using the same rules as for a single work area wa with the exception that when inserting from an internal table locators operate as the source but no write streamscan be created.
If no row with the same primary key or with the same unique secondary index exists 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, no rows are inserted. However sy-subrc is still set to 0. The system field sy-dbcnt is set to the number of rows that are inserted.
If a row with the same primary key or the same unique secondary index 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:
Notes