ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → Native SQL → EXEC SQL - Embedded Native SQL → EXEC SQL
EXEC SQL - EXECUTE PROCEDURE
Other versions: 7.31 | 7.40 | 7.54
Syntax
EXEC SQL.
EXECUTE PROCEDURE proc ( IN p_in1, IN p_in2, ...
OUT p_out1, OUT p_out2, ...
INOUT p_inout1, INOUT p_inout2, ... )
ENDEXEC.
Effect
In database systems, procedures can be defined as stored procedures. Since the syntax for calling this type of procedure and the associated parameter passing can vary widely for various database systems, a uniform command exists in statically embedded Native SQL.
The statement EXECUTE PROCEDURE
calls a procedure proc
stored in the database. For all formal parameters of the procedure, the actual parameters must be specified,
separated by commas. IN
, OUT
, or INOUT
must be specified before every actual parameter, to indicate whether the parameter is an input, output, or input/output parameter. Literals or
host variables indicated by colons (:
) can be used for the actual parameters.
Notes
-
On the SAP HANA database, the stored procedures are
database procedures written in
SQLScript. In ABAP, these procedures can be managed and called using
ABAP Managed Database Procedures (AMDP) and the special statement
CALL DATABASE PROCEDURE
. This statement enables access using a secondary connection. -
EXECUTE PROCEDURE
can be used to call procedures with input and output parameters but cannot be used to call functions with return values. In SQL, functions are used directly in suitable operand positions (see Executable Example).
Example
Defines a procedure abap_docu_demo_incprice
using database-specific SQL statements
and by calling the procedure with the SAP-specific Native SQL statement EXECUTE
PROCEDURE. The execution of the program section raises the price of every flight for the current client in the table SFLIGHT by a specific amount. See also the corresponding executable
example for ADBC.
DATA incprice TYPE sflight-price VALUE '0.5'.
cl_demo_input=>request( CHANGING field = incprice ).
TRY.
EXEC SQL.
DROP PROCEDURE abap_docu_demo_incprice;
ENDEXEC.
CATCH cx_sy_native_sql_error.
ENDTRY.
TRY.
EXEC SQL.
CREATE PROCEDURE
abap_docu_demo_incprice ( IN inc DECIMAL(15,2),
IN clnt NVARCHAR(3) ) AS
BEGIN
UPDATE sflight SET price = price + inc
WHERE mandt = clnt;
END;
ENDEXEC.
EXEC SQL.
EXECUTE PROCEDURE abap_docu_demo_incprice ( IN :incprice,
IN :sy-mandt )
ENDEXEC.
CATCH cx_sy_native_sql_error INTO DATA(exc).
cl_demo_output=>write( exc->get_text( ) ).
ENDTRY.
cl_demo_output=>display( ).