Skip to Content
1
Jun 12, 2019 at 03:01 PM

SAP Cloud SDK - Get and Convert Filter Expression not working

12757 Views Last edit Jun 12, 2019 at 03:03 PM 2 rev

Hi all,

we've created a CDS based OData service in Cloud Foundry with CAP to call an OData exposed by a SAP ECC and as we read on this blog:

https://blogs.sap.com/2019/02/28/sap-s4hana-cloud-sdk-version-2.12.0-is-available/

we should be able to convert the filter expression retrieved from the QueryRequest object into the filter expression that can be used in the filter method of the ODataQueryBuilder object.

We've modified the following dependency version in the pom.xml file:

<dependency>

<groupId>com.sap.cloud.s4hana</groupId>

<artifactId>sdk-modules-bom</artifactId>

<version>2.18.0</version>

<scope>import</scope>

<type>pom</type>

</dependency>

So when we start our service and try to invoke GET method with filter property set as show:

/odata/v2/Search1LService/Mmain?$filter=('Maufnr' eq '0001')

we get an exception because of the filter format.

Apparently the queryRequest.getQueryExpression() provides the right filter data but when we try to convert this object into the FilterExpression object something goes wrong.

As you can see the String value is: " eq %27Maufnr%27" instead of "%27Maufnr%27%20eq%20%270001%27".

The FilterExpression object (fe2) has obviously the same issue, so the execute call ends with an exception, because the OData filter we are passing to the backend system has a wrong format.

In the blog the author passes the FilterExpressionConverter.queryRequest.getQueryExpression() object to UncheckedFilterExpression costructor to buid the filter input parameter:

myService.getAllSomething()

.filter(new UncheckedFilterExpression<>(

FilterExpressionConverter.convertTo(

queryRequest.getQueryExpression())))

.execute();

In our class this code causes a syntax error because the filter doesn't accept this UncheckedFilterExpression object as input:

The method filter(FilterExpression) in the type ODataQueryBuilder is not applicable for the arguments (new UncheckedFilterExpression<>(FilterExpressionConverter.convertTo(queryRequest.getQueryExpression())))Java Debug

Can someone please help with the issue? Is there something wrong to get the expression or is there a bug in the Cloud SDK to convert the Expression?

Best regards

Attachments

debug01.png (133.4 kB)
debg02.png (71.5 kB)