ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Native SQL → ADBC - ABAP Database Connectivity → Examples of ADBC
ADBC, Query
This example demonstrates the execution of a query with ADBC.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA carrid TYPE sflight-carrid.
DATA cols TYPE adbc_column_tab.
cols = VALUE #( ( CONV adbc_name( 'CARRID' ) )
( CONV adbc_name( 'CONNID' ) )
( CONV adbc_name( 'FLDATE' ) ) ).
cl_demo_input=>request( CHANGING field = carrid ).
TRY.
DATA(result) = NEW cl_sql_statement( )->execute_query(
`SELECT carrid, connid, fldate ` &&
`FROM sflight ` &&
`WHERE mandt = ` && `'` && sy-mandt && `' AND` &&
` carrid = ` && `'` &&
cl_abap_dyn_prg=>escape_quotes(
to_upper( carrid ) )
&& `'` ).
result->set_param_table( itab_ref = REF #( result_tab )
corresponding_fields = cols ).
IF result->next_package( ) > 0.
SORT result_tab BY carrid connid fldate.
cl_demo_output=>display( result_tab ).
ENDIF.
CATCH cx_sql_exception INTO DATA(err).
cl_demo_output=>display( err->get_text( ) ).
ENDTRY.
Description
The method EXECUTE_QUERY from the class CL_SQL_STATEMENT is used to extract three columns of the database table SFLIGHT for the current client. 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.
Quotation marks are escaped in the user input. This prevents SQL injections.