Skip to Content

SAP Cloud SDK - Get and Convert Filter Expression not working

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

debug01.png (133.4 kB)
debg02.png (71.5 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Jun 13, 2019 at 09:16 AM

    Hi Christoph,

    we found the solution for the problem.

    -> the filter expression was wrong

    The question can be closed.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 13, 2019 at 06:52 AM

    Hi Marvin,

    in your first described use case, can you please add the stack trace of the exception you received? My assumption would be that the escaping should take place later in the call chain, not in the toString() method.

    Regarding the second use case: The UncheckedFilterExpression is intended to be used with the OData VDM of the "SAP Cloud SDK", which is built on top of e.g. the ODataQueryBuilder of the "SAP Cloud Platform SDK for service development" that you are using. This means you cannot use our UncheckedFilterExpression within the ODataQueryBuilder (and shouldn't need to).

    Using our OData VDM you can hide all those String properties into a type-safe facade that does all the heavy lifting for you. For further details have a look here and here.

    Greetings

    Chris

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jun 13, 2019 at 08:16 AM

    Hi Christoph,

    thank you for your help. You're right the second use case was just a try to make it work. The real problem here is we call the first OData service with a Filter:

    $filter=('Maufnr' eq '0001')

    Then we want to extract this Filter Value Maufnr eq 0001, so we use queryRequest.getQueryExpression(), that returns the object with correct value.

    As next step we try to call the next OData service with the filter value, here we need a FilterExpression Object but the method FilterExpressionConverter.convertTo(queryRequest.getQueryExpression()))

    - returns only 'eq Maufnr' instead of something like 'Maufnr eq 0001'

    Is this correct it looks like there is only the key but where is the value 0001?

    There is no stack trace from the Java App -> because there is only an exception thrown from the backend service like -> wrong filter expression

    Thanks

    Marvin

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 23, 2020 at 09:39 AM

    Hi Marvin,

    how did you solve it?

    thanks

    Johannes

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.