Preface – This post is part of the SAP ABAP OData Tutorial series.
Table of Contents
In previous articles, we have discussed What is an OData and how to create an OData in SAP. We have also shown how to test an OData if it is working fine or not. Now, we need to learn how to read a table using an OData Query and also perform operations like Insert, Update and Delete on that table. In this article we will also learn basic queries of reading data.
How it works
In case of OData, there are three phases of data transfer. These are:
1. Sending Data from Frontend
2. Taking Data from Frontend
At OData we receive data from Frontend using data provider (Code implemented in CRUD Operation section)
io_data_provider->read_entry_data(IMPORTING es_data= ls_entity).
3. Sending Data to Frontend
From OData we send data to UI using et_entityset or er_entity after data manipulation (Code implemented in CRUD Operation section)
The above steps are shown in the image below:
Operations in ODATA
In this section, we will explore all the methods generated automatically, once you generate an OData. In last article, we have already instructed to write all your CRUD operations related code in DPC_EXT class. Hence, we will follow the same concept here.
SAP ABAP OData provides different methods for CRUD operations, these are:
|GET_ENTITY||Select||This method is used to read a single data based on table keys|
|GET_ENTITYSET||Select||This method is used to read entire data of a table|
|CREATE_ENTITY||Insert||This method is used to create/insert a new data in table|
|UPDATE_ENTITY||Update/Modify||This method is used to update an existing data in table|
|DELETE_ENTITY||Delete||This method is used to delete an existing data in table|
Query in SAP OData
In this section, we will explore all the Query we can perform while reading data from OData. In above section, we have learnt how to do read calls using GET_ENTITY and GET_ENTITYSET. Sometimes, we need to filter out data according to our requirement, or to get total number of data counts or to get data in specific order. These all SAP OData Queries are explained below:
Here, let us suppose <your service name> = https://isd.sap.com/<OData Service Name>
|$metadata||It gives the metadata detail of your service. By metadata we mean it will provide information about all the entity sets with their field names and their attributes||<your service name>/$metadata|
|$FILTER||It is mainly used during Read Entity Set call. During Read, we can send some filter value in backend that can be later used in where condition of Select queries||<your service name>/$FILTER|
|$top and $skip||It is mainly used to get limited data in the UI, in case you are reading all the data, and the table is having a very large data||<your service name>/$top and $skip|
|$orderby||This is used to order the data in ascending or descending order for a specific key||<your service name>/$orderby|
|$format=json||This returns the data in form of JSON format. By default, the result is in XML format.||<your service name>/$format=json|
|$inlinecount||This returns the number of data of a table that will appear in the UI||<your service name>/$inlinecount|
|$expand||This is used to bind the association and navigation data together||<your service name>/$expand|
|$value||This is used to return the media data||<your service name>/$value|