Documentation View

We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!

ABAPINSERT_FROM_SELECT - INSERT FROM SELECT

ABAPINSERT_FROM_SELECT - INSERT FROM SELECT

RFUMSV00 - Advance Return for Tax on Sales/Purchases   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.
SAP E-Book

INSERT, MODIFY dbtab, subquery_clauses

Short Reference





Effect

Possible clauses and additions of a subquery after the addition FROM of the statements INSERT and MODIFY. These clauses define a result set, which is used as a data source of the INSERT or INSERT statement.

Apart from the client column, the result set of the subquery must have at least as many columns as the primary key of the database table or the DDIC table view that is filled using the INSERT statement or modified using the MODIFY statement. It cannot, however, have more columns than the target DDIC database table or view .

The following special rules apply:

  • FROM clause
  • If the DDIC database table or DDIC view processed using the INSERT or MODIFY statement is client-dependent, at least one data source of the subquery must be client-dependent.

  • If the subquery uses default client handling or if client handling is switched using USING CLIENT, implicit client handling in the INSERT statement or MODIFY statement cannot be switched using CLIENT SPECIFIED.

  • SELECT clause
  • Any SELECT lists of the subquery specified as comma-separated lists must define one column of the result set for at least every column of the primary key of the DDIC database table or DDIC view to be filled.

    If the subquery uses default client handling or switches client handling using USING CLIENT, no client column can be specified as the first column in the SELECT list. In other positions, client columns are not interpreted as client columns.

    If implicit client handling is switched in the subquery using USING $[ALL$] CLIENTS $[IN$], the first column of the SELECT list must be a client column.

  • In a SELECT list of the subquery specified using *, the result set produced for at least every column of the primary key of the DDIC database table or DDIC view to be filled must contain a column.

    If the subquery uses default client handling or switches client handling using USING CLIENT, the client column of the result set is ignored.

    If implicit client handling is switched in the subquery using USING $[ALL$] CLIENTS $[IN$], the client column of the result set is respected.

  • ORDER BY clause

  • An ORDER BY clause in a subquery is not supported by all databases. This means a syntax check warning from the extended program check can occur that can be hidden using the pragma ##db_feature_mode[limit_in_subselect_or_cte]. If this is detected at runtime on a database that does not support the pragma, a catchable exception of the class CX_SY_SQL_UNSUPPORTED_FEATURE is raised.

A further subquery within the subquery cannot access the table or view processed using the INSERT or MODIFY statement.

Notes

  • In an ABAP program, it is possible to use the method USE_FEATURES of the class CL_ABAP_DBFEATURES to check whether the current database system or a database system accessed using a secondary connection supports ORDER BY clauses in subqueries. This requires the constant LIMIT_IN_SUBSELECT_OR_CTE of this class to be passed to the method in an internal table.
  • Implicit client handling of the subquery is not specified by client handling of the INSERT statement or MODIFY statement. An addition USING or CLIENT SPECIFIED of the INSERT statement or MODIFY statement is ignored by the subquery. The subquery uses either the current client ID or a client specified in the subquery using USING. When the result of the subquery is written, however, implicit client handling of the INSERT statement or MODIFY statement applies by default. This can be controlled using the additions USING CLIENT or CLIENT SPECIFIED.
  • The use of a subquery in the statement MODIFY and the use of USING CLIENT or an access in the subquery to the DDIC database table or DDIC view that is filled with an INSERT statement results in the strict mode as of Release . If used, USING $[ALL$] CLIENTS $[IN$] applies strict mode from Release .

Example

Insertion of columns of a result set formed by an inner join in a database table.






BAL_S_LOG - Application Log: Log header data   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Length: 8654 Date: 20221203 Time: 163314     sap01-206 ( 137 ms )