Lesson 1 of 5
OData concepts
9 min
Listen to this lesson
OData (Open Data Protocol) is an open standard, maintained at OASIS, for reading and changing data over HTTP in a REST style. SAP uses it everywhere: every SAP Fiori app talks to its back end through OData, and many of SAP S/4HANA's released APIs are OData services. If you integrate, extend or test SAP S/4HANA, OData is the protocol you will meet most often.
At Contoso Motor Co., the FleetLink customer portal lets fleet customers such as Great Lakes Fleet Services see their orders and deliveries. After the conversion to SAP S/4HANA, FleetLink reads sales orders through a released OData API instead of the custom RFC calls it used against ECC. Kenji, the ABAP development lead, and Theo, the integration lead, own the change; Priya's team tests it.
The building blocks
The $metadata document is the contract. It is machine-readable XML that names every entity type, its key, its properties with data types and lengths, and its navigation properties. Client developers generate code from it, and testers use it to know exactly which fields and operations the service offers. When an upgrade changes $metadata in an incompatible way, clients break.
Addressing and query options
Everything in OData is a URL. The service root plus an entity set returns a collection; adding a key in parentheses returns one entity; adding a navigation property returns related data. Query options, which start with $, shape the result:
| Option | Does | Example from FleetLink |
|---|---|---|
$filter | Restricts the result by a condition | $filter=SoldToParty eq '17100001' (Great Lakes Fleet Services) |
$select | Returns only the listed properties | $select=SalesOrder,TotalNetAmount,OverallSDProcessStatus |
$expand | Includes related entities inline | $expand=to_Item to get the items with each order |
$orderby | Sorts the result | $orderby=CreationDate desc |
$top / $skip | Pages through large results | $top=50&$skip=100 for the third page of 50 |
$count | Returns or includes the number of matching entities | V4: $count=true; V2 uses /$count or $inlinecount=allpages |
Common OData query options. Which options a service supports is stated in its documentation and metadata.
Changing data
OData maps create, read, update and delete to HTTP methods. GET reads. POST to an entity set creates an entity and, on success, returns 201 Created. PATCH updates only the properties you send; the OData standard prefers it for updates, while PUT replaces the entity (OData V2 services also accept MERGE, an older form of partial update). DELETE removes an entity and returns 204 No Content. A $batch request bundles several operations in one HTTP call; operations inside a change set succeed or fail together.
| Topic | OData V2 | OData V4 |
|---|---|---|
| Standard status | Older version; still very common in SAP | Current OASIS standard version |
| Default payload | Atom XML or JSON (request JSON with $format=json) | JSON |
| Partial update | MERGE or PATCH | PATCH |
| Counting | /$count and $inlinecount | $count |
| Operations beyond CRUD | Function imports | Actions and functions, bound or unbound |
| In SAP S/4HANA | Many established released APIs and SAP Gateway Service Builder services | Newer released APIs and the default for new RAP services |
What would you do?
FleetLink loads Great Lakes' order list slowly. The developer's request is <code>GET .../A_SalesOrder?$expand=to_Item</code> with no other options. Which change helps most?
- OData is an open REST protocol; SAP Fiori and many SAP S/4HANA APIs use it.
- Services expose entity sets of typed entities with keys, properties and navigation; $metadata is the contract.
- Query options such as $filter, $select, $expand, $top and $skip shape reads.
- POST creates, PATCH updates, DELETE removes; $batch change sets succeed or fail together.
Check your understanding · not graded
Lesson check
1. Which document describes every entity type, key and property of an OData service?
2. Which query option returns only the fields you list?
3. What does a successful POST to an entity set normally return?
4. What is true of operations inside one $batch change set?