ABAP database connectivity (ADBC)
The aim of this lesson is:
- understand ADBC (ABAP Database Connectivity)
- use ADBC to execute native SQL statements
ADBC is an object based API. ADBC allows native SQL access providing:
- Flexibility
- where used list
- error handling
Main classes in ADBC are:
- CL_SQL_CONNECTION
- CL_SQL_STATEMENT
- CL_SQL_RESULT_SET
Sequence of reading data with ADBC
- Choose database connection(only when accessing secondary DB) – call method get_connection() of class CL_SQL_CONNECTION
- Create a statement object – Instantiation of class CL_SQL_STATEMENT
- Fill string variable with SQL syntax – use either CONCATENATE or string templates/expressions
- Issue native SQL call – call method execute_query() of class CL_SQL_STATEMENT
- Assign target variable of result set – call method set_param() or set_param_table() of class CL_SQL_RESULT_SET
- Retrieve result set – call method next_package() of class CL_SQL_RESULT_SET
- Close query and release resources – Method close() of class CL_SQL_RESULT_SET

ADBC: Important things to keep in mind
No syntax check for native SQL statements
(Make sure to handle exception cx_sql_exception)
No hashed or sorted table allowed as target
(Use standard table (usually hashed or sorted secondary key))
No automatic client handling
(Make sure to specify client explicitly in WHERE clause, join conditions etc.)
No guarantee of release of allocated resources on DB
(Do not forget to close the query)