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.
** -- 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


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.

You must be Logged on to comment or reply to a post.