Show TOC

$filter System Query Option APIsLocate this document in the navigation structure

The OData $filter system query option filters a subset of the entries from the collection that are addressed in the request URL. SAP NetWeaver 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:

  • Implement the visitor interface /IWBEP/IF_MGW_EXPR_VISITOR in your own way to process the filter expression tree.
  • Use the /IWBEP/IF_MGW_REQ_ENTITYSET API which is an implementation of the visitor interface /IWBEP/IF_MGW_EXPR_VISITOR to get the ABAP Open SQL WHERE clause.
    Note While implementing a query for an entity, you can do a query on the database using Open SQL SELECT syntax if you have direct access to persistency.
Implementing the Visitor Interface /IWBEP/IF_MGW_EXPR_VISITOR
Use the method GET_FILTER_EXPRESSION_TREE of the interface /IWBEP/IF_MGW_REQ_ENTITYSET to get the filter expression tree and then implement the visitor interface /IWBEP/IF_MGW_EXPR_VISITOR to process the filter expression tree as per your requirement. You should implement the visitor interface using Visitor design pattern.

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( ).
Using the Interface /IWBEP/IF_MGW_REQ_ENTITYSET
Use the method GET_OSQL_WHERE_CLAUSE of the interface /IWBEP/IF_MGW_REQ_ENTITYSET to get an Open SQL WHERE clause. The Open SQL WHERE clause can be used do a query in the backend directly using ABAP SELECT syntax.

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( ).