SAP INSERT SOURCE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• TABLE INSERT dbtab
• ACCEPTING DUPLICATE KEYS INSERT dbtab
• ( SELECT ... ) INSERT FROM

INSERT dbtab, source
Short Reference

ABAP_SYNTAX
... @wa$|@( expr )
$| ${ TABLE @itab$|@( expr ) $[ACCEPTING DUPLICATE KEYS$] $}
$| ( SELECT subquery_clauses $[ UNION$|INTERSECT$|EXCEPT ...$] ) ...

ABAP_ALTERNATIVES:
1 ... @wa$|@( expr ) ...
2 ... TABLE @itab$|@( expr ) $[ACCEPTING DUPLICATE KEYS$] ...
3 ... ( SELECT subquery_clauses $[UNION$|INTERSECT$|EXCEPT ...$] ) ...

What does it do?
Data sources of the ABAP SQL INSERT statement:
After the additions VALUES and FROM, a non-table-like data object can be specified as a host variable @wa or host expression @( expr ).
After FROM TABLE, an internal table can be specified as a host variable @itab or host expression @( expr ).
After FROM TABLE, a subquery can be specified.
The content of the row or rows to be inserted is taken from these data objects or from the result set of the subquery.



Latest notes:

NON_V5_HINTS
Host variables without the escape character @ are obsolete. The escape character @ must be specified in the strict modes of the syntax check from ABAP_RELEASE ABAP_740_SP05 .
ABAP_HINT_END

ABAP Alternative 1 ... @wa$|@( expr ) ...

What does it do?
After VALUES and FROM, a non-table-like work area can be specified as a host variable @wa or as a host expression @( expr ), from whose content a row is created for insertion into the DDIC database table. The work area must meet the prerequisites for use in AB-SQL statements.
When specifying a work area that does not contain any reference variables for LOB handles, the content of the row to be inserted is taken from the work area wa while ignoring its data type and from left to right in accordance with the structure of the DDIC database table
BEGIN_SECTION VERSION 5 OUT or the view
END_SECTION VERSION 5 OUT . No conversion is made to the ABAP type that is assigned to a column using its dictionary type.
When a LOB handle structure is specified, it must be constructed exactly like the structure of the DDIC database table, in accordance with the prerequisites. The components of the work area that are not LOB Handle components are assigned directly to the corresponding columns of the new row. In the case of a LOB handle component of a read stream type, this type is created. In the case of a type for a locator, this must exist and is used as a source. For details, see LOB handles.
The new row is inserted into the DDIC database table if it 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. When the row is inserted, the content of the work area assigned to the individual columns of the DDIC database table is mapped by the database interface to its data types and converted if necessary. If content is not suitable, overflows or invalid values may raise exceptions.
BEGIN_SECTION VERSION 5 OUT
If a view is specified in target that does not include all columns in the DDIC database table, these are set to either their type-dependent initial value or the null value in the inserted rows. The latter is only the case if the property NOT NULL is not selected in the database for the columns in question in the DDIC database table.
END_SECTION VERSION 5 OUT