Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
horst_keller
Product and Topic Expert
Product and Topic Expert


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.

TRY.
CREATE OBJECT sql.
CONCATENATE `SELECT carrid, carrname `
`FROM scarr `
`WHERE carrid = '` key `'`  INTO stmnt.
result = sql->execute_query( stmnt ).
GET REFERENCE OF carrid INTO dref.
result->set_param( dref ).
GET REFERENCE OF carrname INTO dref.
result->set_param( dref ).
rc = result->next( ).
IF rc > 0.
WRITE: / carrid, carrname.
ELSE.
WRITE / 'No entry found'.
ENDIF.
result->close( ).
CATCH cx_sql_exception INTO exc.
MESSAGE exc TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.


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

http://help.sap.com/abapdocu_70/en/ABENADBC.htm

http://www.sappro.com/article.cfm?id=3375
(maybe also in SDN but I didn't find it)

5 Comments