Skip to Content

Filter System Query Option ($filter) in GET_ENTITY

As we all know how to add filters in GET ENTITY SET (Query) operation, But I got a Requirement in the real-time business scenario to add a filter in the GET (READ) operation for a non-key field to create a user based on the filter value with the combination of GET(read) operation.

Here the sample service with few key steps which are to be followed:

Create a new project :

Import your structure and generate the Runtime objects.

 

Redefine method “CRUDQSET_GET_ENTITY“.

  METHOD crudqset_get_entity.
** -- Data Declarations
    DATA:lv_opt              TYPE /iwbep/s_cod_select_option.
** -- Field Symbols
    FIELD-SYMBOLS:<fs_request_details> TYPE any,
                  <fs_filter_so>       TYPE /iwbep/t_mgw_select_option,
                  <fs_property>        TYPE string,
                  <fs_sel_opt>         TYPE /iwbep/t_cod_select_options.
    ASSIGN mr_request_details->* TO <fs_request_details>.
    IF <fs_request_details> IS ASSIGNED.
      ASSIGN COMPONENT 'FILTER_SELECT_OPTIONS' OF STRUCTURE <fs_request_details> TO <fs_filter_so>.
      IF <fs_filter_so> IS ASSIGNED.
        LOOP AT <fs_filter_so> ASSIGNING FIELD-SYMBOL(<fs_filter>) .
          ASSIGN COMPONENT 'PROPERTY' OF STRUCTURE <fs_filter> TO <fs_property>.
          ASSIGN COMPONENT 'SELECT_OPTIONS' OF STRUCTURE <fs_filter> TO <fs_sel_opt>.
          IF <fs_property> IS ASSIGNED AND <fs_sel_opt> IS ASSIGNED.
            CASE <fs_property>.
** -- Address
              WHEN 'Zadrs'.
                READ TABLE <fs_sel_opt> ASSIGNING FIELD-SYMBOL(<fs_opt>) INDEX 1.
                IF <fs_opt> IS ASSIGNED .
                  lv_opt-low = <fs_opt>-low.
                ENDIF.
            ENDCASE.
          ENDIF.
        ENDLOOP.
      ENDIF.
    ENDIF.
** -- Get Employee Details based on Employee Id
    READ TABLE it_key_tab INTO DATA(ls_key_tab) WITH KEY name = 'Zempid'.
    IF sy-subrc EQ 0.
** -- Get Employee Details based on Employee Id  and Employee Address
      SELECT SINGLE * FROM zodata_crudq INTO er_entity WHERE zempid = ls_key_tab-value.
if zadrs  = lv_opt-low.
** Do some Validations
endif.
                                                             
    ENDIF.


  ENDMETHOD.

Output :

URI : http://<server>/sap/opu/odata/sap/ZCRUDQ_SRV/CRUDQSet(‘800574’)?$filter=Zadrs eq ‘BANGALORE’&$format=json

 

Hope the above-furnished information is useful.

3 Comments
You must be Logged on to comment or reply to a post.
  • Hi Sreenu,

    first it was not clear to me why you would want to filter on single entry.

    But probably this is something that in OData V4 could be addressed via advertised actions?

    So depending on the value you found for the employee there you could offer an Action to be active or not.

    https://help.sap.com/viewer/DRAFT/96880755e4e64fcd96c12694f430fece/Internal/en-US/b54f7895b7594c61a83fa7257fa9d13f.html

    Best regards,

    Andre

     

     

    • Hi Andre,

      Thanks for your comment.

      Actually my requirement is, to get the user details from read/GET_ENTITY operation,if we didn't have user then am getting flag from UI in the filter based on that flag am creating user by calling RFC FM.

      This is a just sample service how filter will be  in GET_ENTITY operation

       

      Thanks,

      Sreenu

      • Maybe your use case can be achieved via intent based Navigation?

        https://blogs.sap.com/2016/01/17/best-build-fiori-apps-rule-7-always-use-intent-based-navigation-to-navigate-within-an-app-and-between-apps/