cancel
Showing results for 
Search instead for 
Did you mean: 

Odata Query not working when using '=' symbol

ricky_shaw
Contributor
0 Kudos

Hi,

I have an Odata Query which is working (getting data) fine when i use 'eq' as below:

/sap/opu/odata/SAP/Z*****_01/BPInputsSet?$format=json&$filter= Account eq '800000012341' and Prodtyp eq 'EWR' &$expand=NavtoData1,NavtoData2&$format=json

But when i replace 'EQ' with '='  its throwing error like " 400 : Invalid token detected at position.".etc

How to correct this error?

Accepted Solutions (1)

Accepted Solutions (1)

NabiZamani
Contributor
0 Kudos

This is not an error, it’s how it works as per OData spec.

ricky_shaw
Contributor
0 Kudos

Oh really! I see '=' works only for Get Entity queries.

Lets wait for more replies before accepting your answer.

NabiZamani
Contributor
0 Kudos

Imagine these two:

  • $filter= Account eq '800000012341' and Prodtyp eq 'EWR' 
  • $filter= Account = '800000012341' and Prodtyp = 'EWR'

Now think about writing a parser for the second option 😉 Also don't forget how URL params work in your browser.

You could also check the spec to learn that $filter doesn't not allow a '=' (scroll to the section): 4.5. Filter System Query Option ($filter)

Answers (1)

Answers (1)

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

You need to know, that query parameters (also called CGI parameters, based on an old standard of the 90s) have a special format, where the characters '?', '&', '+', '%' and '=' have a special meaning. Roughly speaking, the format of a URL with query parameters is:

http://hostname:port/path?name1=value1&name2=value2

The ? separates the query parameters from the rest of the URL, the & separates two query parameters from each other, and the = separates the query-name from the query-value. A % sign is used to indicate an "escape sequence" and a +-sign can be used to represent a space inside a name or value. For example a parameter "street" with value "Alan Turing Avenue 42" would be encoded as

?street=Alan+Turing+Avenue+42

That means, if you want to use any of these special characters (and some others) inside the name or value of a query parameter, you need to "URL-encode" it. See HTML URL Encoding Reference (w3schools.com)

In our example, we have a query parameter with the name "$filter" and the value "Account = '800000012341' and Prodtyp = 'EWR'". The = sign needs to be encoded as %3D, leading to the following correct query:

?$format=json&$filter=Account%20%3D%20'800000012341'%20and%20Prodtyp%20%3D%20'EWR'&$expand=NavtoData1%2DNavtoData2

(Note that the algorithm used here, encoded space characters as %20 instead of as a + sign, which is also ok. In general, every character can be encode ("escaped") by %xy, where xy is the hexadecimal value of its ASCII code or its UTF-8 code.)