Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  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'.

      )->add_field( CHANGING field = airpfrom
      )->add_field( CHANGING field = airpto )->request( ).

    TYPES: BEGIN OF result,
             carrid TYPE s_carr_id,
             connid TYPE s_conn_id,
           END OF result,
           results TYPE TABLE OF result WITH EMPTY KEY.

        DATA(query) = cl_os_system=>get_query_manager( )->create_query(
          i_filter   = `AIRPFROM = PAR1 AND AIRPTO = PAR2`
          i_ordering = `CARRID ASCENDING CONNID ASCENDING` ).

        DATA(agent) = ca_spfli_persistent=>agent.
          VALUE results(
            FOR <connection>
            IN agent->if_os_ca_persistency~get_persistent_by_query(
              i_query   = query
              i_par1    = airpfrom
              i_par2    = airpto )
              ( carrid = CAST cl_spfli_persistent(
                               <connection> )->get_carrid( )
                connid = CAST cl_spfli_persistent(
                               <connection> )->get_connid( ) ) ) ).
      CATCH cx_root INTO DATA(exc).
        cl_demo_output=>display( exc->get_text( ) ).


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 and sort conditions. 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, an SQL injection is not possible in this example.