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.
URI : http://<server>/sap/opu/odata/sap/ZCRUDQ_SRV/CRUDQSet(‘800574’)?$filter=Zadrs eq ‘BANGALORE’&$format=json
Hope the above-furnished information is useful.
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.
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
Maybe your use case can be achieved via intent based Navigation?