Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  ABAP and SAP HANA →  Database Procedure Proxies for SQLScript Procedures 

CALL DATABASE PROCEDURE

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CALL DATABASE PROCEDURE 
    {  proxy       [CONNECTION con|(con_syntax)]  parameter_list }
  | { (proxy_name) [CONNECTION con|(con_syntax)] {parameter_list
                                                 |parameter_table} }.

Addition

... CONNECTION con|(con_syntax)

Effect

This statement calls a database procedure written in SQLScript (SQLScript procedure) on an SAP HANA database.

  • If the addition CONNECTION is not specified, the statement can only be executed in a system on the SAP HANA database.
  • If the addition CONNECTION is specified, the statement can be executed in every system with a secondary database connection to an SAP HANA database.

The SQLScript procedure is specified using a database procedure proxy defined for it. This proxy can either be specified directly as proxy or dynamically as the uppercase content of a parenthesized character-like data object, proxy_name. The actual parameters for the input and output parameters of the procedure are either specified statically using parameter_list or dynamically using parameter_table.


Notes

  • The names of the database procedure proxy and database procedure interface can be chosen at will. Usually, the database procedure interface has the name of the database procedure proxy with the prefix IF_, and any additional namespace prefix.
  • The attribute IS_IN_MEMORY_DB of the class CL_DB_SYS can be used to query whether the current system uses an SAP HANA database.
  • ABAP Managed Database Procedures (AMDP) are a recommended alternative to the statement CALL DATABASE PROCEDURE if the central database of AS ABAP is a SAP HANA database. From AMDP, any database procedures of the central database can be called. This makes the use of database procedure proxies superfluous as long as a secondary database connection is not used to access another SAP HANA database..

Addition

... CONNECTION con|(con_syntax)

Effect

The SQLScript procedure is not executed on the standard database but on the specified secondary database connection. The database connection can be specified statically with con or dynamically as the content of con_syntax, where the field con_syntax must belong to the type c or string. The database connection must be specified with a name that is in column CON_NAME in table DBCON.


Notes

  • The specified database procedure proxy for the database procedure of the secondary database connection must exist in the current system.
  • Entries in the database table DBCON can only be created and modified using the DBA Cockpit tool.
  • The use of CALL DATABASE PROCEDURE with the addition CONNECTION is recommended in all scenarios in which existing database procedures are used in an SAP HANA database that is not the central database of the current AS ABAP (side-by-side scenario).

Example

SQLScript Procedure

Take the following SQLScript procedure:

/********* Begin Procedure Script ************/
BEGIN
  out_items = select items.pos,
                     items.first_name,
                     items.last_name,
                     items.posting_date as date,
                     items.currency,
                     items.amount
                from zngd_items as items
                inner join :in_sel as sel
                 on ( items.first_name = sel.first_name and
                      items.last_name  = sel.last_name )
               where posting_date = :in_date;
END;
/********* End Procedure Script ************/

The input parameters are:

Parameter Database Type
in_sel Table Data Type
in_date Scalar

The components of in_sel are:

Component Database Type
FIRST_NAME NVARCHAR, Length 20
LAST_NAME NVARCHAR, Length 20

The output parameters are:

Parameter Database Type
out_items Table Data Type

The components of out_items are:

Component Database Type
POS INTEGER
FIRST_NAME NVARCHAR, Length 20
LAST_NAME NVARCHAR,Length 20
DATE INTEGER
CURRENCY NVARCHAR, Length 4
AMOUNT DECIMALS, Length 11, Scale 2

Database Procedure Proxy

The following mapping is defined in the associated database procedure proxy ..._PROXY:

Procedure Parameter ABAP Name ABAP Data Type
IN_SEL IN_SEL Internal table
IN_SEL, FIRST_NAME IN_SEL, FIRST_NAME c, length 20
IN_SEL, LAST_NAME IN_SEL, LAST_NAME c, length 20
IN_DATE IN_DATE d
OUT_ITEMS, POS OUT_ITEMS, POS i
OUT_ITEMS, FIRST_NAME OUT_ITEMS, FIRST_NAME c, length 20
OUT_ITEMS, LAST_NAME OUT_ITEMS, LAST_NAME c, length 20
OUT_ITEMS, DATA OUT_ITEMS, POSTING_DATE d
OUT_ITEMS, CURRENCY OUT_ITEMS, CURRENCY c, length 4
OUT_ITEMS, AMOUNT OUT_ITEMS, AMOUNT p, length 6, 2 decimal places

Note the name and type changes in the date fields.

Database Procedure Interface

The database procedure interface IF_..._PROXY is generated with the following type declarations:

INTERFACE if_..._proxy PUBLIC.
  TYPES: BEGIN OF in_sel,
           first_name     TYPE c LENGTH 20,
           last_name      TYPE c LENGTH 20,
         END OF in_sel.
  TYPES: in_date          TYPE d.
  TYPES: BEGIN OF out_items,
           pos  TYPE i,
           first_name     TYPE c LENGTH 20,
           last_name      TYPE c LENGTH 20,
           posting_date   TYPE d,
           currency       TYPE c LENGTH 4,
           amount         TYPE p LENGTH 6 DECIMALS 2,
         END OF out_items.
ENDINTERFACE.

Database Procedure Call

The following ABAP program section calls the SQLScript procedure using the name of the database procedure proxy; actual parameters typed using the database procedure interface are used.

DATA:
  in_date   TYPE if_..._proxy=>in_date,
  in_sel    TYPE STANDARD TABLE
                 OF if_..._proxy=>in_sel
                 WITH EMPTY KEY,
  out_items TYPE STANDARD TABLE
                 OF if_..._proxy=>out_items
                 WITH EMPTY KEY.

in_date = '20120329'.
in_sel = VALUE #( ( first_name = 'Dolores'    last_name = 'Oh' )
                  ( first_name = 'Benjacomin' last_name = 'Bozart' )
                  ( first_name = 'Johanna'    last_name = 'Gnade'   ) ).

IF cl_db_sys=>is_in_memory_db = abap_true.
  CALL DATABASE PROCEDURE ..._proxy
     EXPORTING in_date   = in_date
               in_sel    = in_sel
     IMPORTING out_items = out_items.
ENDIF.


Example

The example Database Procedure Call uses a database procedure proxy created in the program to call a SQLScript procedure created using ADBC.

Exceptions


Catchable Exceptions

Except for CX_SY_DB_PROCEDURE_SQL_ERROR, all the following exception classes are subclasses of the abstract superclass CX_SY_DB_PROCEDURE_CALL.

CX_SY_DB_PROCEDURE_SQL_ERROR

  • Cause: Error on the database when executing an SQLScript function.
    Runtime Error: DBPROC_SQL_ERROR

CX_SY_DB_PROCEDURE_CONNECTION

  • Cause: The specified secondary database connection was not found in the database table DBCON.
    Runtime Error: DBPROC_CONNECTION

CX_SY_DB_PROCEDURE_NOT_FOUND

  • Cause: The specified database procedure proxy does not exist.
    Runtime Error: DBPROC_PROXY_NOT_FOUND

CX_SY_DB_PROCEDURE_NOT_SUPP

  • Cause: The database does not support SQLScript.
    Runtime Error: CALL_DATABASE_NOT_SUPPORTED

CX_SY_DB_PROCEDURE_OVERFLOW

  • Cause: The value range of a parameter was exceeded.
    Runtime Error: DBPROC_OVERFLOW

CX_SY_DB_PROCEDURE_PARAMETER

Cause: One of the following exceptions was raised (abstract superclass).

  • CX_SY_DB_PROCEDURE_DYN_IN_OUT
Cause: Input and output parameters were switched in the dynamic call.
Runtime Error: DBPROC_DYNAMIC_IN_OUT1, DBPROC_DYNAMIC_IN_OUT2
  • CX_SY_DB_PROCEDURE_DYN_MISSING
Cause: Actual parameter missing for a formal parameter in a dynamic call.
Runtime Error: DBPROC_DYNAMIC_MISSING
  • CX_SY_DB_PROCEDURE_DYN_NOT_FND
Cause: Formal parameter specified incorrectly in a dynamic call.
Runtime Error: DBPROC_DYNAMIC_NOT_FOUND
  • CX_SY_DB_PROCEDURE_TYPE_ERROR
Cause: Invalid type of an actual parameter in a static or dynamic call.
Runtime Error: DBPROC_ILLEGAL_TYPE, DBPROC_DYNAMIC_NO_SCALAR, DBPROC_DYNAMIC_NO_TABLE


Non-Catchable Exceptions

  • Cause: The column KIND of the parameter table ptab contains an invalid value.
    Runtime Error: DBPROC_DYNAMIC_UNKNOWN_KIND
  • Cause: The column KIND of the parameter table ptab contains the value "C" for input/output parameters. This is not yet supported.
    Runtime Error: DBPROC_DYNAMIC_NO_INOUT
  • Cause: The actual parameter associated with an output parameter cannot be modified.
    Runtime Error: DBPROC_OUT_NOT_WRITABLE

Continue

CALL DATABASE PROCEDURE - parameter_list

CALL DATABASE PROCEDURE - parameter_table

SAP HANA, Database Procedure Proxy - Example