cancel
Showing results for 
Search instead for 
Did you mean: 

$filter with multiple substringof functions seperated by AND/OR operator

subhajit
Active Participant

Hello Colleagues,

I am trying to implement an API call with the below URI :

$filter=substringof('ABC',FirstName) and substringof('XYZ',LastName) and (substringof('DEF',FirstName) or substringof('STW',LastName))

I am aware that IO_TECH_REQUEST_CONTEXT->GET_FILTER( )->GET_FILTER_SELECT_OPTIONS( ) would be empty.

Only parameters that I am receiving being filled are IO_TECH_REQUEST_CONTEXT->GET_REQUEST_HEADERS( ) and IO_TECH_REQUEST_CONTEXT->GET_FILTER_EXPRESSION_TREE( ).

I followed this blog by Andre(Option1) as well. But I would like to know is there any other way to fetch the filter parameters.

I am left with the option to scan the request headers but want to seek advice on any other solution if available.

Regards,

Subhajit

Accepted Solutions (1)

Accepted Solutions (1)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Hi Subhajit,

not sure why you want this.

But there would be a way to retrieve the filter string as an osql where clause

data(osql_where_clause) = io_tech_request_context->get_osql_where_clause( ).

I tested it with the following request

/sap/opu/odata/sap/ZSALESORDER_SRV/SalesOrderSet?$filter=substringof('ABC',Salesorder)
and substringof('XYZ',Customer) and (substringof('DEF',Salesorder) or
substringof('STW',Customer))
<br>

and got the following value for osql_where_clause.

( ( SALESORDER LIKE '%ABC%' AND CUSTOMER LIKE
'%XYZ%' ) AND ( SALESORDER LIKE '%DEF%' OR CUSTOMER LIKE '%STW%' ) )<br>

Please note, there is also the method

io_tech_request_context->get_osql_where_clause_convert( )

available that would deliver the filter values after having applied conversion exits.

What you could also do is the following.

1. Read all data from the backend without applying the filter condition that stems from substringof

2. Apply osql_where_clause to the resultset et_entityset before returning it.
But this would only work in systems later than SAP NetWeaver 752 where Open SQL can be applied on internal tables.

This way you wouldn't have to parse the osql_where_clause but the resultset might become to big.

Kind regards,

Andre

subhajit
Active Participant
0 Kudos

Hi Andre,

Thanks for the prompt response and apologize for the delay in counter response.

Though its strange as I tried :

get_osql_where_clause( ) , get_osql_where_clause_convert( ), get_osql_with_placeholders(), get_search_string( ), get_request_headers( ), get_filter( ), get_filter_expression_tree( ),get_filter_expression_tree_con( )

But somehow I could only get Headers and Filter_expression_tree

I will try it one more time by rechecking with the URI and respond back.

Regards,

Subhajit

subhajit
Active Participant

Thanks Andre as usual and apology for the delayed response.

That actually worked.

Had to customize my query a bit to fit it into the belt.

Answers (0)