ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP - Database Accesses → ADBC - ABAP Database Connectivity → Examples of ADBC
ADBC, Query
The example demonstrates the execution of a query with ADBC.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: sql TYPE REF TO cl_sql_statement,
result TYPE REF TO cl_sql_result_set,
err TYPE REF TO cx_sql_exception,
cols TYPE adbc_column_tab,
dref TYPE REF TO data.
APPEND 'CARRID' TO cols.
APPEND 'CONNID' TO cols.
APPEND 'FLDATE' TO cols.
CREATE OBJECT sql.
GET REFERENCE OF result_tab INTO dref.
TRY.
result = sql->execute_query(
`SELECT carrid, connid, fldate ` &&
`FROM sflight ` &&
`WHERE mandt = ` && `'` && sy-mandt && `' AND` &&
` carrid = ` && `'` && p_carrid && `'` ).
result->set_param_table( itab_ref = dref
corresponding_fields = cols ).
IF result->next_package( ) > 0.
SORT result_tab BY carrid connid fldate.
display( ).
ENDIF.
CATCH cx_sql_exception INTO err.
MESSAGE err TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
Description
Three columns of database table SFLIGHT for the current client are read using the method EXECUTE_QUERY of the class CL_SQL_STATEMENT. An appropriate internal table is bound to the result set using the method SET_PARAM_TABLE of the class CL_SQL_RESULT_SET. Using the method NEXT_PACKAGE all the rows of the result set are transported into the internal table.