Ansicht
Dokumentation

ABAPINSERT_DBTAB - INSERT DBTAB

ABAPINSERT_DBTAB - INSERT DBTAB

BAL Application Log Documentation   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.
SAP E-Book

INSERT dbtab

Short Reference



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

Variants:

1. INSERT INTO target VALUES wa.

2. INSERT target FROM wa.

3. INSERT target FROM TABLE itab.

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

5. ... MAPPING FROM ENTITY.

Effect

The statement INSERT inserts one or more rows into the DDIC database table or DDIC table view 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. The addition connection can be used to specify a secondary connection.

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 or 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).

Notes

  • 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.
  • The statement INSERT cannot be applied to the system table TRDIR.

Variant 1

INSERT INTO target VALUES wa.


Variant 2

INSERT target FROM wa.


Effect

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-subrc Meaning
0 The row specified in the work area in wa was inserted.
2 When 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.
4 The 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.

Example

Insertion of two individual rows into a DDIC database table.

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

Variant 3

INSERT target FROM TABLE itab.


Effect

This variant inserts the rows contained in an internal table itab.

Note

There is no syntax variant with VALUES for internal tables.

System Fields

This variant of the statement INSERT can raise exceptions if an attempt is made to insert rows from the internal table for rows with the same key already exist in the DDIC database table. If no exception is raised, the value of the system field sy-subrc is set as follows:

sy-subrc Meaning
0 All rows of the internal table itab were inserted or the internal table is empty.
4 The 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.

Example

Insertion of two individual rows into a DDIC database table.

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

Variant 4

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


Effect

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-subrc Meaning
0 All 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.

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 because a row with the same primary key or the same unique secondary index exists, a catchable exception of the class CX_SY_OPEN_SQL_DB is always raised and the system field sy-subrc is not set.

Example

Insertion of all rows of the DDIC database table DEMO_JOIN1 into the table DEMO_JOIN3.

Variant 5

... MAPPING FROM ENTITY.


Effect

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.






Addresses (Business Address Services)   General Material Data  
This documentation is copyright by SAP AG.

Length: 14028 Date: 20240623 Time: 184447     sap01-206 ( 165 ms )