Skip to Content
Author's profile photo Horst Keller

ABAP Geek 15 – ADBC

ADBC is the abbreviation for “ABAP Database Connectivity” that is a class-based API for the Native SQL interface of the Application Server ABAP. ADBC allows object orientated and dynamic access to the Native SQL interface and can always be used when access to a database via the Native instead of the Open SQL interface is necessary and static EXEC SQL is not sufficient (remember that dynamic token specification is not possible in EXEC SQL).

How to find the classes of ADBC?

The ADBC classes all begin with the prefix CL_SQL_ or CX_SQL_. The most important classes are

  • CL_SQL_STATEMENT for executing SQL statements
  • CL_SQL_PREPARED_STATEMENT for creating prepared SQL statements
  • CL_SQL_CONNECTION  for administering database connections
  • CX_SQL_EXCEPTION as an exception class

How to use ADBC?

In the most simple case you use instance methods of CL_SQL_STATEMENT to exceute SQL statements that are passed to the methods. You can create DML and DDL statements, carry out queries and execute stored procedures.

A simple example

PARAMETERS key TYPE scarr-carrid.

DATA: sql      TYPE REF TO cl_sql_statement,
result   TYPE REF TO cl_sql_result_set,
exc      TYPE REF TO cx_sql_exception,
stmnt    TYPE string,
carrid   TYPE scarr-carrid,
carrname TYPE scarr-carrname,
dref     TYPE REF TO data,
rc       TYPE i.

CONCATENATE `SELECT carrid, carrname `
`FROM scarr `
`WHERE carrid = ‘` key `’`  INTO stmnt.
result = sql->execute_query( stmnt ).
result->set_param( dref ).
GET REFERENCE OF carrname INTO dref.
result->set_param( dref ).
rc = result->next( ).
IF rc > 0.
WRITE: / carrid, carrname.
WRITE / ‘No entry found’.
result->close( ).
CATCH cx_sql_exception INTO exc.

A SELECT statement is passed to an object of CL_SQL_STATEMENT and the method EXECUTE_QUERY is invoked. With SET_PARAM the columns of the result set are accessed in order to bind data refeferences to the individual results.

More Information
(maybe also in SDN but I didn’t find it)

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Graham Robinson
      Graham Robinson
      Wow! I wish I had known about this one about 18 months ago. Would have made life much easier.

      Thanks for this blog.

      Graham Robbo

      Author's profile photo Former Member
      Former Member

           This is a Very useful blog for all categories of developers.


      Author's profile photo Former Member
      Former Member
      I have a quick question for ADBC.

      I want to use table parameter for MS SQL server 2008 but I don't know if it's working or not.

      Do you have any idea?



      Author's profile photo Horst Keller
      Horst Keller
      Blog Post Author

      I'm sorry, but I don't understand your question.
      (what do you mean with 'table parameter for MS SQL server 2008'?)

      Kind regards


      Author's profile photo Former Member
      Former Member
      I want to pass blob data by ADBC, but it always show error with following description. Could  anyone give me a hand? Thanks.

        CREATE OBJECT blob_ref
          exporting con_ref = lo_connection

            BLOB_REF = blob_ref ).

            XSTR  = lw_data-file_content ).