ABAP EXEC SQL

“EXEC SQL” statement is used for performing native SQL commands in ABAP programs.

Syntax:

EXEC SQL [PERFORMING <form>].

ENDEXEC.

 

While executing the native SQL commands within the EXEC SQL block, the system field sy-subrc will be filled with the following values.

  • sy-subrc=0 (native SQL commands executed successfully)
  • sy-subrc=4 (Native SQL commands not executed)

The main runtime errors for this statement execution are

  • DBIF_DSQL2_CONNECTERR
  • DBIF_DSQL2_CONNECTSTR_ERROR
  • DBIF_DSQL2_INVALENV_ERROR
  • DBIF_DSQL2_INVALID_CURSOR
  • DBIF_DSQL2_KEY_ALREADY_EXISTS
  • DBIF_DSQL2_KEY_NOT_FOUND
  • DBIF_DSQL2_NO_MEMORY
  • DBIF_DSQL2_OBJ_EXISTS
  • DBIF_DSQL2_OBJ_UNKNOWN
  • DBIF_DSQL2_SQL_ERROR
  • EXSQL_CONNECTION_LIMIT
  • EXSQL_DSQL_CURSOR_LIMIT
  • EXSQL_DSQL_CURSOR_NOT_FOUND
  • EXSQL_DSQL_DUPLICATE_CURSOR
  • EXSQL_DSQL_NOROLL
  • EXSQL_DSQL_WRONG_IVAR_TYPE
  • EXSQL_ILLEGAL_CONNECTION
  • EXSQL_ILLEGAL_DISCONNECTION
  • EXSQL_TOO_MANY_VARS
  • EXSQL_UNKNOWN_CONNECTION
  • EXSQL_UNSTRUCTURED_INTO
  • EXSQL_WRONG_TYPE_FOR_LOB

Other important notes about ABAP EXEC SQL statement

  • The statement block with EXEC SQL statement should always closed with ENDEXEC statement.
  • A complete syntax check for the commands within this statement block wont performed, instead of it will pass to native SQL interface.
  • It will bypass SAP buffering

Automatic client handling won’t happen for Native SQL commands.

Also Read : View Other ABAP Keywords & Syntax -> ABAP Transaction codes