The OData $filter system query option filters a subset of the entries from the collection that are addressed in the request URL. SAP Gateway provides filter APIs which can be used to query in the SAP backend. Filter expression tree is a tree representation of OData filter system query option provided in the request URI. A visitor interface /IWBEP/IF_MGW_EXPR_VISITOR has been provided to process the filter expression tree. You have the option to:
To get the filter expression tree, invoke the /IWBEP/IF_MGW_EXPR_NODE API in the GET_ENTITYSET method of the Data Provider class (DPC).
01.Data: lo_filter_tree TYPE REF TO /iwbep/if_mgw_expr_node. lo_filter_tree = io_tech_request_context->get_filter_expression_tree( ).
To get the Open SQL WHERE clause, use the code below in the GET_ENTITYSET method of the DPC of an OData service:
01.DATA: lv_osql_where_clause TYPE string. *----get Open SQL WHERE Clause from $filter-----* lv_osql_where_clause = io_tech_request_context->get_osql_where_clause( ).
Only a subset of the possible filter expressions can be converted into a WHERE clause.
The system query option $filter is supported on navigation properties.
Information about $filter on navigation is provided via the filter expression tree in the backend system for the affected data provider.
SalesOrder?$filter=TwinEntity eq 'null'
SalesOrder?$filter=TwinEntity/property eq 'xyz'
SalesOrders?$filter=EditState ne 2 or (EditState eq 2 and TwinEntity eq null)
SalesOrder?$filter=TwinEntity/<next_navigation>/...<last_navigation> eq 'null'
The navigation or complex properties appearing in the $filter query option will be provided as follows in the filter expression tree::
<property name without '-'>:
Name of a simple property or a navigation. In case of navigation the property value can only be 'null' and the operator is '=' or '<>'.
<property name containing one or more '-'>:
Name before '-': This name can be the name of a complex property or a navigation.
Name after '-': This name can be the name of a simple property or a complex property or a navigation.