ABAP Database Connectivity (ADBC)

ADBC is an ABAP Objects-based API that allows you to directly execute native SQL statements on the underlying database (such as SAP HANA), bypassing the usual Open SQL layer. This is especially useful for performance-critical scenarios or when using features not supported by Open SQL.

Typical Steps for Using ADBC in ABAP:

1. Establish a Database Connection

Use the static method of the connection class:

DATA(lo_conn) = cl_sql_connection=>get_connection( ).

2. Instantiate a Statement Object

Based on the connection, create an instance of the statement handler:

DATA(lo_stmt) = NEW cl_sql_statement( lo_conn ).

3. Prepare the Native SQL Statement

Ensure that the SQL syntax is compatible with the target DB (e.g., HANA). If the statement includes input parameters, register them:

DATA(lv_sql) = `SELECT * FROM ZTABLE WHERE FIELD = ?`.

3b. Register Input Parameters (Optional)

lo_stmt->set_param( 1, lv_input_value ).

4. Execute the SQL Statement

Use the appropriate execution method:

  • EXECUTE_QUERY – for SELECT statements or CALL to procedures

  • EXECUTE_UPDATE – for DML statements like INSERTUPDATEDELETE

  • EXECUTE_DDL – for DDL statements like CREATEALTERDROP

  • EXECUTE_PROCEDURE – specifically for calling stored procedures

DATA(lo_result) = lo_stmt->execute_query( lv_sql ).

5. Register Output Parameters (Optional)

Use the methods of the result set object if needed:

lo_result->set_param_table( ... ).

6. Retrieve the Result Set

Fetch data from the result object using methods like NEXTNEXT_PACKAGE, etc.

WHILE lo_result->next( ) = abap_true. lo_result->get_values( ... ). ENDWHILE.

7. Close the Result Set

lo_result->close( ).

8. Close the Database Connection

lo_conn->close( ).

Comments

Popular posts from this blog

Code-To-Data Paradigm

Native SQL

Getting Started with SAP HANA for ABAP Developers