$count Query option counts the number of entries in the table.
https://services.OData.org/v3/OData/OData.svc/Products/$count
The above URL renders the result of total no of products ‘11’ in the browser.
$count Query option counts the number of entries in the table.
https://services.OData.org/v3/OData/OData.svc/Products/$count
The above URL renders the result of total no of products ‘11’ in the browser.
The four important SAP Transaction codes for ODATA Service
/nSEGW –> This Transaction is used to create an OData service in the Backend.
/n/IWFND/MAINT_SERVICE –> Register the OData service in the frontend.
/n/IWFND/GW_CLIENT –> Execute the HTTP Method in the frontend.
/n/IWFND/ERROR_LOG –> To view the Error logs in the OData Service.
They are useful in performing predefined actions in the system. Function imports are implemented when the implementation cannot be done using the CRUD-Q Methods
Entity container: It contains all the entity sets.
Entity set: It represents a table. It is based on the entity type.
Entity type: All the fields(properties) and the primary keys are mentioned.
Property: It represents the fields along with data type.
Entity: It describes a line of record in the data table.
Association: It connects the primary and foreign key fields. It represents the cardinality of the relationship (1:1, 1: n).
Navigation: The two different entity sets can be related and represented through the navigation.
The OData service defines a structure for every entity set. It also mentions about Datatype for each field. The Entity set is based on tables. This structure is called as entity type in OData service. The Entity types are mentioned in the metadata document.
The metadata document exposes all the metadata of the OData service. It includes Data model, Types, Relations, and semantic information.
The metadata document is viewed through the following URL, which has the addition $metadata at the end of the URL.
http://services.OData.org/v3/OData/OData.svc/$metadata
In addition to the entity types, fields are also mentioned. They are called as properties. The data type and primary key of the table is also mentioned.
OData service document represents a service which includes entity sets, uniform resource identifier (URI)
It can be opened through the browser with the URI / URL
For example, let us consider the following OData service.
http://services.odata.org/v3/OData/OData.svc/
If you open this URL in browser, it shows up the different entity sets.
As you can see in the above image, the entitysets in this OData service are Products, Productdetails, Categories, Suppliers, Persons, PersonDetails, Advertisements. So it includes totally seven entitysets. The entityset ‘Category’ includes information about all categories.
If the categories is added to the above URL like
http://services.odata.org/v3/OData/OData.svc/Categories
The above url in the browser would list down all the categories.
Similarly if you wish to see all the Products. Then follow this link
http://services.odata.org/v3/OData/OData.svc/Products
URL is case sensitive. So the first letter ‘P’ in Products must be written in Capital. Otherwise it does not work.
It is much similar to the Transaction SE11 (ABAP Dictionary) where we give the Table name. The Data contents can be displayed for this table.
The URLs mentioned above executes the HTTP-Get methods, which in turn calls the Read-OData method. In the background, the data would be retrieved and the result is sent back.
Let us look into an example of retrieving data records with single primary key.
Specific line of record can also be retrieved by specifying the primary key value in the URL.
http://services.odata.org/v3/OData/OData.svc/Products(5)
In the above URL, the products with the ID 5 will be retrieved.
Retrieving data records with two primary keys.
/Entityset( p_key1 = ‘Value1’, p_key2 = ‘Value2’ )
In the above case, both the primary key fields are of datatype string. So the value is mentioned in quotes. If the datatype is integer, then quotes should not be used.
Retrieving data records with WHERE clause.
All the products with a particular category ID can also be retrieved. To achieve this, it must be predefined in the services. We can also navigate from one entity set to another. For example, in the below URL, only the data from the product entity set are displayed.
https://services.OData.org/v3/OData/OData.svc/Categories(5)/Products
Retrieving data records from two different entity sets
This option is much like the JOIN query in SQL. The data from two different entity sets are displayed with a WHERE condition.
https://services.OData.org/v3/OData/OData.svc/Categories(2)?$expand=Products
OData services works through entity sets and entities. Data is represented in the form of Tables.
Tables are referred as Entity sets and the lines of record are referred as entities.
The Data is accessed through the following OData methods. These OData methods are referred as CRUD methods.
OData Method | Http Method | Description and its relation to sql command |
Create | POST | It creates a new record. It is similar to INSERT command in SQL |
Read | GET | It reads the records. It is similar to SELECT command in SQL. The Read method from OData can be further classified. For example, the Read method is used to read only one record. The Query method is used to read more lines of record. |
Update | UPDATE | It updates the records. It is similar to UPDATE command in SQL |
Delete | DELETE | It deletes the records. It is similar to DELETE command in SQL |