SAP INSERT DBTAB ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID INSERT-DBTAB
• INSERT dbtab ABAP_STATEMENT_OSQL
• INTO INSERT dbtab
• VALUES INSERT dbtab
• FROM INSERT dbtab

INSERT dbtab
Short Reference

ABAP_SYNTAX
INSERT ${ INTO target $[ connection$] VALUES @wa $|@( expr ) $}
$| ${ target $[ connection$] FROM @wa$|@( expr ) $}
$| ${ target $[ connection$] FROM TABLE @itab$|@( expr ) $}
$| ${ target $[ connection$] FROM ( SELECT subquery_clauses $[UNION$|INTERSECT$|EXCEPT ...$] ) $}
$[MAPPING FROM ENTITY $].

ABAP_VARIANTS:
1 INSERT INTO target VALUES @wa$|@( expr ).
2 INSERT target FROM @wa$|@( expr ).
3 INSERT target FROM TABLE @itab$|@( expr ).
4 INSERT target FROM ( SELECT subquery_clauses $[UNION $|INTERSECT$|EXCEPT ...$] ).

ABAP Addition
... MAPPING FROM ENTITY

What does it do?
The AB-SQL statement INSERT inserts one or more rows into the DDIC database table
BEGIN_SECTION VERSION 5 OUT or DDIC table view
END_SECTION VERSION 5 OUT specified in target. The rows to be inserted are taken from a work area wa, an internal table itab, or the result set of an embedded subquery SELECT subquery_clauses .
BEGIN_SECTION VERSION 5 OUT The addition connection can be used to specify a secondary connection .
END_SECTION VERSION 5 OUT
If VALUES is used, INTO must be specified between INSERT and target. If FROM is used, INTO must not be specified.
System Fields
The statement INSERT sets the values of the system fields sy-subrc (see below) and sy-dbcnt. sy-dbcnt is set to the number of rows that are inserted. If an overflow occurs because the number of rows is greater than 2,147,483,647, sy-dbcnt is set to -1. If sy-subrc is 2 when inserting a LOB handle structure with a component for writer streams, sy-dbcnt is also set to -1 (meaning undefined).



Latest notes:

The inserted rows are included permanently in the table in the next database commit. Until then, they can still be removed by a database rollback. The current isolation level defines whether the inserted data can be read into other database LUWs before or only after the database commit.
The number of rows that can be inserted into the tables of a database within a database LUW is limited on a database-dependent level, since a database system can only manage a limited amount of locks and data in the rollback area.
Once rows have been inserted into a global temporary table, this table must be emptied again explicitly before the next implicit database commit using the AB-SQL statement DELETE FROM without WHERE or using an explicit database commit or database rollback, otherwise the runtime error COMMIT_GTT_ERROR is produced.
The statement INSERT cannot be applied to the system table TRDIR.
The statement INSERT sets a database lock as an exclusive lock until the next database commit or rollback.
NON_V5_HINTS
If used incorrectly, this can produce a deadlock.
ABAP_HINT_END

ABAP_VARIANT_1 INSERT INTO target VALUES @wa|@( expr ).

ABAP_VARIANT_2 INSERT target FROM @wa|@( expr ).

What does it do?
These two variants insert a single row contained in a work area wa. Both variants have the same behavior and only their syntax is different.
System Fields
These variants of the statement INSERT set the value of the system field sy-subrc as follows: sy-subrcMeaning 0The row specified in the work area in wa was inserted. 2When a LOB handle structure was specified with a component for writer streams, the non-LOB handle components were not yet written to the database, and are passed, at the latest, when the stream is closed instead. Whether this situation occurs or not depends on the database. See LOB handles. 4The row specified in the work area in wa was not inserted, since a row with the same primary key or a unique secondary index already exists in the DDIC database table.

ABAP_EXAMPLE_VX5
Insertion of two individual rows into a DDIC database table.
ABEXA 00331
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
A host expression with the value operator VALUE can be used instead of an explicit work area.
ABEXA 00332
ABAP_EXAMPLE_END

ABAP_VARIANT_3 INSERT target FROM TABLE @itab$|@( expr ).

What does it do?
This variant inserts the rows contained in an internal table itab.



Latest notes:

There is no syntax variant with VALUES for internal tables.
NON_V5_HINTS
ABAP_HINT_END
System Fields
This variant of the statement INSERT can raise exceptions if an attempt is made to insert rows from the internal table for which there are already rows with the same key in the DDIC database table. If no exception is raised, the value of the system field sy-subrc is set as follows: sy-subrcMeaning 0All rows of the internal table itab were inserted or the internal table is empty. 4The addition ACCEPTING DUPLICATE KEYS is specified and not all rows of the internal table were inserted, since a row with the same primary key or a unique secondary index already exists in the DDIC database table.
For more information about exceptions when inserting rows from internal tables, see TABLE itab.

ABAP_EXAMPLE_VX5
Insertion of two individual rows into a DDIC database table.
ABEXA 00333
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
A host expression with the value operator VALUE can be used instead of an explicit internal table.
ABEXA 00334
ABAP_EXAMPLE_END

ABAP_VARIANT_4 INSERT target FROM ( SELECT subquery_clauses $[UNION$|INTERSECT$|EXCEPT ...$] ).

What does it do?
This variant inserts the rows of the result set of an embedded subquery SELECT subquery_clauses, where multiple result sets can be joined with UNION, INTERSECT , or EXCEPT.
System Fields
This variant of the statement INSERT sets the value of the system field sy-subrc as follows: sy-subrcMeaning 0All rows of the result set of the embedded subquery were inserted. 4 The result set of the embedded subquery is empty and no rows were inserted.



Latest notes:

The statement INSERT with subquery cannot be used if logging is enabled for the table to be filled.
If a row cannot be inserted when the result set of the embedded subquery was inserted, since a row with the same primary key or the same unique secondary index already exists, a catchable exception of the class CX_SY_OPEN_SQL_DB is always raised and the system field sy-subrc is not set.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Insertion of all rows of the DDIC database table DEMO_JOIN1 into the table DEMO_JOIN3.
ABEXA 00335
ABAP_EXAMPLE_END

ABAP Addition

What does it do?
The addition MAPPING FROM ENTITY is used to handle structures and internal tables that are typed with BDEF derived types. Find more information in the topic ABAP SQL Statements with MAPPING FROM ENTITY.

Return to menu