ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Accesses →  Native SQL →  Static Embedding of Native SQL → 

EXEC SQL  Syntax Diagram

Short Reference

Syntax

EXEC SQL.
  ...
ENDEXEC.

Effect

These statements define an area in an ABAP program in which one or more Native SQL statements can be specified statically. The area between EXEC and ENDEXEC is not checked completely by the syntax check. The statements entered there are passed to the Native SQL interface and processed there as follows:

All Native SQL statements bypass SAP buffering. Automatic client handling is not performed.

System Fields

The statement ENDEXEC sets the system fields sy-subrc and sy-dbcnt. When using the obsolete addition PERFORMING, note that implicit cursor processing is carried out and the system fields are set for every read.

sy-subrc Meaning
0 The statements between EXEC and ENDEXEC were executed successfully.
4 The statements between EXEC and ENDEXEC were not successful. After implicit cursor processing with PERFORMING, sy-subrc always contains the value 4.

The ENDEXEC statement sets sy-dbcnt to the number of table rows processed in the last Native SQL statement. After implicit cursor processing with PERFORMING, sy-dbcnt contains the total number of rows read. If an overflow occurs because the number or rows is greater than 2,147,483,647, sy-dbcnt is set to -1.

Notes

Example

The following example demonstrates how a simple embedded Native SQL statement can be replaced by ADBC. The use of the instance operator NEW removes the need for a helper variable of type CL_SQL_STATEMENT when creating objects.

"Static Native SQL
EXEC SQL.
  COMMIT WORK
ENDEXEC.

"Dynamic Native SQL
NEW cl_sql_statement( )->execute_update( `COMMIT WORK` ).

Example

See the executable example for static Native SQL.

Exceptions

Catchable Exceptions

CX_SY_NATIVE_SQL_ERROR

Non-Catchable Exceptions




Continue
EXEC SQL - Literals
EXEC SQL - Host Variables
EXEC SQL - OPEN, CLOSE, FETCH
EXEC SQL - EXECUTE
EXEC SQL - CONNECT
ENDEXEC