cancel
Showing results for 
Search instead for 
Did you mean: 

How to Parse IV_FILTER_STRING in GET_ENTITYSET

and23_julius
Participant
0 Kudos

Hi Experts,

Can anyone advise me on how IV_FILTER_STRING is parsed to become select option format? I have been reading a lot but the solution is either unclear or obsolete (Class Missing). Appreciate if someone can help or point to the right direction.

Best Regards

Andre Julius

Accepted Solutions (1)

Accepted Solutions (1)

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

Hi Julius,

It might happen that the statement

 io_tech_request_context->get_filter()->get_filter_select_options().

doesn't return any result. Reason is that not all OData filter clauses can be converted into select options.

The inconsistency in the API you observed has historical reasons. That's why we introduced the use of the io_tech_request_context object.

You should not use the parameters IV_FILTER and so on because they do not support conversion.

With io_tech_request_context you have for example the option to use

io_tech_request_context->GET_OSQL_WHERE_CLAUSE_CONVERT( )

For select options the handling of conversions is a little bit trickier but explained very comprehensively in thomas.nitschke blog

https://blogs.sap.com/2017/01/23/conversions-in-sap-gateway-foundation-part-2/ where he explains how to use the method

CONVERT_SELECT_OPTION

Regards,

Andre

and23_julius
Participant
0 Kudos

Hi andre.fischer

Thanks for the detailed response, right now I am using lv_wstrg = lo_filtr->GET_FILTER_STRING( )

where they return me the where condition in ABAP-field name convention, I hope it works out of the box all the time 😄


Best Regards


Andre Julius

0 Kudos

Hi andre.fischer,

Lets say io_tech_request_context->GET_OSQL_WHERE_CLAUSE_CONVERT( ) has WHERE clause on 2 or more fields that needs to be applied on 2 different SELECT queries?

Do we have to write custom logic as shown in the below blog.

https://blogs.sap.com/2012/12/29/gateway-odata-calls-convert-ivfilterstring-to-itfilterselectoptions/

Please provide your feedback.

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

io_tech_request_context->GET_OSQL_WHERE_CLAUSE_CONVERT( ) always only returns the SQL String that fits to the OData entityset.

How to map this to "real" SQL Queries or calls to backend API's is part of the work of the developer.

But if you are able to perform 2 SELECT queries I am wondering whether you wouldn't be able to map this to an CDS view.

In this case the framework would perform all the heavy lifting for you.

For any more detailed question please post the same in the Q&A section.

Answers (2)

Answers (2)

rajasinha717
Member

Class "CL_CLB2_TOOLS" Method "ODATA_FILTER2SELECT_OPTION" can be used to pass the filter string and get the selection option whenever data is missing in IT_FILTER_SELECT_OPTIONS but present in IR_FILTER_STRING.

RalfHandl
Product and Topic Expert
Product and Topic Expert
  io_tech_request_context->get_filter( )->get_filter_select_options( ).
and23_julius
Participant
0 Kudos

Hi ralf.handl ,

Thanks for the direction. I've tried that but the result is empty.

  io_tech_request_context->get_filter()

This code above returns me something though. It contains the where condition in MV_FILTER_STRING and select options in MT_SIMPLE_PROPERTY instead of MT_FILTER_SELECT_OPTIONS (which is why GET_FILTER returns blank I guess)


I wonder why....can you advise?

Best Regards

Andre Julius

and23_julius
Participant
0 Kudos

If I use lv_wstrg = lo_filtr->GET_FILTER_STRING( ) then I get the WHERE statement directly... what bothers me is the inconsistencies...if I use 1 parameter, it's in IT_FILTER_SELECT_OPTIONS. else it's in where string...is it supposed to be like this?