In this part, we will discuss the Query operation and along with various query parameter exist in the OData.Basically, Query operation is for getting all the records, which is also known as Feed.

For each entity set, there is a method called <entityset name>_GET_ENTITYSET . in the previous part (part 4), we covered the GET_ENTITY method which is returning response as single records(in ABAP word it is just like a workarea or structure 😉 ) but for GET_ENTITYSET will return multi/single record in the form of a table.

To implement the logic, we need to redefine the GET_ENTITYSET method. as below screenshot

Redefining Get_entityset method
Redefining Get_entityset method
GET_ENTITYSET implemenation
in this image if you see the exporting parameter ET_ENTITYSET is a table type of the entity. that means the response would be an internal table

So let’s test the result. URI : /sap/opu/odata/SAP/ZXYZ_SAMPLE_ODATA_SRV/OrderrHeaderSet

GET_ENTITYSET response
as we have fetched up 100 rows in the logic so the response would of 100 records if found.

Query Option / URI Option Let’s discuss various query options like $select, $filter, $top,$skip,$inlinecount, $count , $orderby etc. Before discussing all the query options. Let’s check how the URL component will look like in general

URI Parameters
Source OData.org – Point to be noted that all the query option starts with $ sign and multiple query option can be used with the help of &

$select

URI : /sap/opu/odata/SAP/ZXYZ_SAMPLE_ODATA_SRV/OrderrHeaderSet?$select=Vbeln,Vkorg,Vtweg

$select
This required no backend logic to be implemented in DPC_EXT class. This query is completed handled by the framework

Similarly, there is another query option called $format, which is used for formating the response that can be used along with this.

URI: /sap/opu/odata/SAP/ZXYZ_SAMPLE_ODATA_SRV/OrderrHeaderSet?$select=Vbeln,Vkorg,Vtweg&$format=json

$select & $format
As you can see the output is in the form of JSON and the default format was XML.

$filter

Filter is used to filter the records – like where clause in the select statement. Unlike $select(handled by the framework), $filter is solely the programmer’s responsibility to handle the code in the DPC_EXT. Let’s take an example to suppose we need to get the selected list of Vbeln instead of all in the response, in that we need to use the $filter.

/sap/opu/odata/SAP/ZXYZ_SAMPLE_ODATA_SRV/OrderrHeaderSet?$filter=Vbeln eq ‘32316’ or Vbeln eq ‘18317’

this is just like select …. where Vbeln in (‘32316’,18317). In the GET_ENTITYSET method, there are few importing parameters useful for Filter like

$filter parameter
we have already covered the IO_TECH_REQUEST_CONTEXT in the previous part in this case u can use the method like Get_Filter( )
$filter parameter importing
$filter parameter in debugging

Once you get the information in the DPC_EXT class then sky is the limit, you can formulate the logic accordingly. There are various options like dynamic select or range etc. Give a try 😉

$count

URI : /sap/opu/odata/SAP/ZXYZ_SAMPLE_ODATA_SRV/OrderrHeaderSet/$count

$count
Just Keep in mind that unlike other query options $count won’t take ‘?’ after the resource path

We will cover the $top, $skip, $inlinecount,$orderby in the upcoming blog.

Previous Part: Get Operation in OData Service – Part 4 – ABAP Skill

Next Part : Paging in OData Service ($top,$skip)- Part 6- ABAP Skill SAP


3 Comments

Get Operation in OData Service – Part 4 - ABAP Skill · July 14, 2021 at 7:35 am

[…] Next Blog: Query Operation(GET_ENTITYSET) in OData – Part 5-ABAP Skill […]

Paging in OData Service ($top,$skip)- Part 6- ABAP Skill SAP · July 18, 2021 at 7:30 am

[…] and skip are used for get_entityset method ( Part 5 for more details ). Before implementing the logic there is a concept called offset and up to rows […]

Create(Create_entity) Method in OData SAP-Part 7-ABAP Skill · July 22, 2021 at 2:11 pm

[…] our previous parts, we are dealing with sales header information (Part 5), in the same fashion, we will create new sales order in the system by using create_entity. And the […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *