Quantcast
Channel: Jive Syndication Feed
Viewing all articles
Browse latest Browse all 10881

Implementation of Query option in odata service

$
0
0

We have lots of Query option in OData service. When I started learning SAP gateway I couldn’t get half of the queries, so thought of writing a blog explaining the most used queries in the odata service for the people who are trying to learn gateway and also for my future reference

 

So first let us list the Query options in odata service that are often used and their uses.

 

Query Option

Description

Implementation Required

$format

Return the response in particular format(JSON/XML/ATOM) without access to request headers for standard content-type negotiation.

Example :

https://<server>:<port>/.../<service_name>/Products?$format=json

No

$count

Return the number of entries in the selection path.

Example:

https://<server>:<port>/.../<service_name>/Products?$count

No

$Select

Return the entities listed in the value of the select query.

Example:

https://<server>:<port>/.../<service_name>/Products?$select=Category,Name

No

$link

Returns the entities list for the navigation property specified in the link.

Example:

https://<server>:<port>/.../<service_name>/Products('1000')/$links/Category

No

$expand

Returns the entities list for the navigation property specified by the value of expand. We can specify multiple navigation property separated by comma or ‘/’.

Example :

https://<server>:<port>/.../<service_name>/Suppliers?$expand=Category,Products

No

$value

Return the raw value of a single entity without any formatting

Example :

https://<server>:<port>/.../<service_name>/Products('1000')/Name/$value

No

$top

Return the response with N entries of the entity set specified in the URI. Used for client side Paging

Example :

https://<server>:<port>/.../<service_name>/Products?$top=5

Yes

$skip

Return the response skipping N entries of the entity set specified in the URI. Used for client side Paging

Example :

https://<server>:<port>/.../<service_name>/Products?$skip=5&$top=10

Yes

$filter

Return the subset of entries from collection of entries depending on the Boolean expression specified in the URI.

Example:

https://<server>:<port>/.../<service_name>/Products?$filter=Category eq 'Notebooks'

Yes

$orderby

Return the entries ordered by the value specified in the URI. the sorting order asc/desc is specified in the URI. If not specified it will get sorted in ascending

Example:

https://<server>:<port>/.../<service_name>/Products?$orderby=Category desc

Yes

$inlinecount

Return the number of entries in the collection of entries after applying all the filters specified in the URI. The inlinecount accepts two values ‘allpages’ and ‘none’.

Example:

https://<server>:<port>/.../<service_name>/Products?$inlinecount=allpages

Yes

$skiptoken

Used for server side paging. The N entries specified in the URI would be returned from server side. The remaining entries would be returned on request.

Example:

https://<server>:<port>/.../<service_name>/Products?$skiptoken=20

Yes

 

Let us now see how to implement the Query options into our code. Whatever values we pass in the URI can be found in the import parameter “io_tech_request_context” of the method GET_ENTITYSET in the service implementation.

 

Implementation for $filter:


In the example below I have made the CARRID field as filterable field, so we can filter the result based on the CARRID in the odata query.

doc.png

doc.png

Implementation for $skip and $top:


doc.png

Implementation for $orderby:


doc.png

Implementation for $inlinecount:


doc.png


Viewing all articles
Browse latest Browse all 10881

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>