ABAP Keyword Documentation → ABAP - Reference → Processing External Data → ABAP - Database Accesses → Object Services → Query Service
Query Service
This example demonstrates the use of an object oriented query.
Other versions: 7.31 | 7.40 | 7.54
Source Code
    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: carrid TYPE s_carr_id,
          connid TYPE s_conn_id.
    DATA: tmp TYPE REF TO object.
    DATA: exc TYPE REF TO cx_root,
          text TYPE string.
    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 ).
        IF ( LINES( connections ) > 0 ).
          READ TABLE connections INTO tmp INDEX 1.
          connection ?= tmp.
          carrid = connection->get_carrid( ).
          connid = connection->get_connid( ).
          text = |{ text-001 } { carrid } { connid }|.
        ELSE.
          text = text-002.
        ENDIF.
        MESSAGE text TYPE 'I'.
      CATCH cx_root INTO exc.
        text = exc->get_text( ).
        MESSAGE text TYPE 'I'.
    ENDTRY.
Description
A reference is assigned a reference to the class actor of the persistent class CL_SPFLI_PERSISTENT is
assigned to the reference variable agent. It is created once using the static
constructor of the CA_SPFLI_PERSISTENT class. Using the method GET_QUERY_MANAGER of the CL_OS_SYSTEM
class, a Query Manager is called, and with the CREATE_QUERY method and stating the filter, a query is
created. The query is executed using the interface method GET_PERSISTENT_BY_QUERY of the IF_OS_CA_PERSISTENCY interface and the first flight that is found is displayed.