SAP EXEC ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• EXEC SQL ABAP_STATEMENT

EXEC SQL
Short Reference

ABAP_SYNTAX
EXEC SQL.
...
ENDEXEC.

What does it do?
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 specified there are passed to the Native SQL interface and processed there as follows:
SQL statements that are valid for the addressed database system can be listed between EXEC and ENDEXEC, in particular the DDL statements. These SQL statements are passed from the Native SQL interface to the database system largely unchanged. The syntax rules are determined by the database system, in particular the case sensitivity rules for database objects. If the syntax allows a separator between individual statements, multiple Native SQL statements can be included between EXEC and ENDEXEC. Generally, the semicolon (;) is used as the separator.
SAP-specific Native SQL language elements can also be specified between EXEC and ENDEXEC. These statements are not passed directly from the Native SQL interface to the database, but are converted appropriately. These SAP-specific language elements are:
Literals
Host variables
INTO clause
Statements for cursor processing
Database procedure calls
Statements for establishing database connections
All Native SQL statements bypass table buffering, and no implicit client handling is performed.
System Fields
The statement ENDEXEC sets the system fields sy-subrc and sy-dbcnt. When using the obsolete addition PERFORMING, it should be noted that implicit cursor processing is carried out and the system fields are set for every read. sy-subrcMeaning 0The statements between EXEC and ENDEXEC were executed successfully. 4The statements between EXEC and ENDEXEC were not successful. After implicit cursor processing with PERFORMING, sy-subrc always contains the value 4.
The statement ENDEXEC 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.



Latest notes:

Programs with Native SQL statements are generally dependent on the database system used and cannot be executed in all AS ABAP systems. This is especially true for the examples in this section, which were tested on a SAP HANA database, unless otherwise stated.
If insertions or modifications using the Native SQL statements INSERT or UPDATE would produce duplicate rows with respect to the primary table key, no exception is raised. Instead, sy-subrc is set to 4. However, if another operation, such as executing a Stored Procedure, would produce a duplicate row, an exception would be raised.
The client ID of a database table or a view must be specified explicitly. It should be noted that application programs should only use data from the current client. See also the associated security note and the programming guideline.