Generic GET_ENTITY

The generic GET_ENTITY method is a method that can be used in a gateway service to retrieve a single entity from the database. It is a generic method, so it can be used for any entity. The method is generated by the gateway service builder and can be found in the DPC_EXT class.

METHODS read_entity_generic
    IMPORTING
        iv_table                TYPE string
        it_map                  TYPE /iwbep/t_mgw_tech_pairs OPTIONAL
        io_tech_request_context TYPE REF TO /iwbep/if_mgw_req_entity
    EXPORTING
        es_response_context     TYPE /iwbep/if_mgw_appl_srv_runtime=>ty_s_mgw_response_entity_cntxt
        er_entity               TYPE any
    RAISING
        /iwbep/cx_mgw_busi_exception
        /iwbep/cx_mgw_tech_exception.

METHOD read_entity_generic.

    DATA: lv_property_selected TYPE string.

    DATA(lt_keys) = io_tech_request_context->get_keys( ).
    DATA(lt_select_table) = io_tech_request_context->get_select( ).
    DATA(lv_where) = ||.

    LOOP AT lt_keys ASSIGNING FIELD-SYMBOL(<fs_key>).
        IF sy-tabix <> 1.
        lv_where = |{ lv_where } AND|.
        ENDIF.
        DATA(lv_key) = <fs_key>-name.
        IF line_exists( it_map[ name = <fs_key>-name ] ).
        lv_key = it_map[ name = <fs_key>-name ]-value.
        ENDIF.

        lv_where = |{ lv_where } { <fs_key>-name } = '{ <fs_key>-value }'|.
    ENDLOOP.

    LOOP AT lt_select_table INTO DATA(lv_select).
        IF lv_property_selected IS INITIAL.
        lv_property_selected = lv_select.
        ELSE.
        lv_property_selected = |{ lv_property_selected }, { lv_select }|.
        ENDIF.
    ENDLOOP.

    IF lv_property_selected IS INITIAL.
        lv_property_selected = '*'.
    ENDIF.

    SELECT SINGLE (lv_property_selected)
    FROM (iv_table)
    WHERE (lv_where)
    INTO CORRESPONDING FIELDS OF @er_entity.

ENDMETHOD.

Example of usage:

    read_entity_generic(
       EXPORTING
         iv_table                = 'ZFLIGHT'
         io_tech_request_context = io_tech_request_context
       IMPORTING
         er_entity               = er_entity
         es_response_context     = es_response_context ).