ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP Database Accesses → Object Services → query service
Query Service
This example demonstrates how an object-oriented query is used.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA: airpfrom TYPE s_fromairp VALUE 'FRA',
airpto TYPE s_toairp VALUE 'SIN'.
DATA: query_manager TYPE REF TO if_os_query_manager,
query TYPE REF TO if_os_query.
DATA: connections TYPE osreftab,
connection TYPE REF TO cl_spfli_persistent,
agent TYPE REF TO ca_spfli_persistent.
DATA: BEGIN OF result,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
END OF result,
results LIKE TABLE OF result WITH EMPTY KEY.
DATA exc TYPE REF TO cx_root.
cl_demo_input=>add_field( CHANGING field = airpfrom ).
cl_demo_input=>request( CHANGING field = airpto ).
agent = ca_spfli_persistent=>agent.
TRY.
query_manager = cl_os_system=>get_query_manager( ).
query = query_manager->create_query(
i_filter = `AIRPFROM = PAR1 AND AIRPTO = PAR2` ).
connections =
agent->if_os_ca_persistency~get_persistent_by_query(
i_query = query
i_par1 = airpfrom
i_par2 = airpto ).
LOOP AT connections ASSIGNING FIELD-SYMBOL(<connection>).
connection = CAST #( <connection> ).
result-carrid = connection->get_carrid( ).
result-connid = connection->get_connid( ).
APPEND result TO results.
ENDLOOP.
cl_demo_output=>display( results ).
CATCH cx_root INTO exc.
cl_demo_output=>display( exc->get_text( ) ).
ENDTRY.
Description
A reference to the class agent of the persistent class CL_SPFLI_PERSISTENT is assigned to the reference
variable agent
. It is created once by the static constructor of the CA_SPFLI_PERSISTENT
class. A query manager is called using the method GET_QUERY_MANAGER of the class CL_OS_SYSTEM and a
query created using the method CREATE_QUERY and a specified filter. The query is executed using the interface method GET_PERSISTENT_BY_QUERY of the interface IF_OS_CA_PERSISTENCY and the flights found are displayed.
Since the predefined parameters PAR1, PAR2 from a parameter list are used here, anSQL injection is not possible in this example.