This page adds the protocol-level details of OData V2 vs V4 that the other pages do not cover. It builds on: CORE ABAP › 08 · OData (SAP Gateway) (feature table), SAPUI5 › 04 · Data, Binding & Navigation (V2 vs V4 model), SAP Fiori › 03 · SAP Fiori Elements (two stacks) and RAP › 03 (which binding to choose). Every fact below is taken from the OData standard (OASIS / odata.org) or the SAPUI5 documentation; the source is named under each part.
Part 1 – Versions and HTTP headers
Client and service negotiate the protocol version through HTTP headers. V4 renamed them and dropped the minimum-version header: the service simply uses the highest version both sides support.
Purpose | OData V2 | OData V4 |
|---|---|---|
Version of this request / response |
| OData-Version |
Highest version the client accepts | MaxDataServiceVersion | OData-MaxVersion |
Lowest version the client accepts | MinDataServiceVersion (V3) | removed |
Id of a created entity | DataServiceId (V3) | OData-EntityId |
Source: OASIS – What's New in OData V4.0 (2.3.4, 2.3.5); V2 header example: odata.org V2 JSON format.
Part 2 – JSON payload shape
The most visible difference when you debug a service: V2 'verbose JSON' wraps everything in d, V4 JSON is flat and uses @odata. control information.
2.1 OData V2 (verbose JSON)
- Every response is wrapped in an outer object named
d– the payload is valid JSON but not valid JavaScript, so it can't be executed via XSS. - Collections:
{"d": {"results": [ … ]}}; collection metadata sits next toresultsas__count(with$inlinecount) and__next(server paging). - Each entry carries
__metadatawithuri, optionaltypeand optionaletag.
{ "d": {
"results": [
{ "__metadata": { "uri": ".../SalesOrders('4711')", "type": "...SalesOrder" },
"SalesOrder": "4711" }
],
"__count": "42",
"__next": ".../SalesOrders?$skiptoken=10"
} }2.2 OData V4 (JSON)
- No
dwrapper. A collection is the array in the name/value pairvalue. @odata.context(the metadata URL of the payload) must be the first property if present.@odata.count= total count (Edm.Int64),@odata.nextLink= next page of a partial result,@odata.etag= ETag of an entity or collection.- Instance annotations are properties whose name starts with
@and contains a dot. In 4.0 control information carries the prefix odata.; 4.01 payloads should omit it for control information (e.g. @context, @id).
{ "@odata.context": "$metadata#SalesOrders",
"@odata.count": 42,
"value": [
{ "@odata.etag": "W/\"…\"", "SalesOrder": "4711" }
],
"@odata.nextLink": "SalesOrders?$skiptoken=10" }Source: odata.org V2 JSON format (sections 3, 6, 7); OASIS OData JSON Format 4.01 (3.1, 4.2, 4.4, 4.5).
Part 3 – Data types: dates, times and numbers
Date/time handling is the classic V2 → V4 migration pitfall: V4 removed Edm.DateTime and Edm.Time and introduced separate types for a date, a time of day and a duration.
Topic | OData V2 | OData V4 |
|---|---|---|
Date + time |
|
|
Date only | no own type (DateTime at midnight) | Edm.Date |
Time of day | Edm.Time |
|
Duration | – | Edm.Duration |
Single-precision float | Edm.Float | removed (use |
Int64 / Decimal in JSON | JSON strings ( | JSON numbers by default; request strings with |
Source: odata.org V2 JSON format (section 4); OASIS – What's New in V4.0 (4.2.1–4.2.4); OASIS JSON Format 4.01 (3.2).
Part 4 – Query options and filter functions
Topic | OData V2 | OData V4 |
|---|---|---|
Inline total count |
| $count=true |
Count only | /SalesOrders/$count |
|
Substring test |
|
|
Collection conditions | not available | lambda operators |
Free-text search | no standard option (SAP: | $search |
Hierarchy depth | – |
|
Projection of expanded data |
|
|
Watch the argument order when you migrate a filter: substringof(a, b) becomes contains(b, a). any is false for an empty collection, all is true for an empty collection. $it (the current instance) can be used everywhere in V4, not only inside lambdas.
Source: odata.org V2 URI conventions (3.1, 4.5, 4.9); OASIS – What's New in V4.0 (2.6, 3.2); OASIS URL Conventions 4.01 (5.1.1).
Part 5 – Operations, references and updates
Topic | OData V2 | OData V4 |
|---|---|---|
Custom operations | service operations / function imports, called by URI with query-string parameters | actions (side effects, |
Unbound entry points | function import |
|
Links between entities | Categories(1)/$links/Products |
|
Partial update |
|
|
Upsert | – |
|
Single-part key in URL | SalesOrders('4711') | same; canonical form is the value only, without the property name |
In $batch, V4 requests inside a change set need a Content-ID, and by default processing stops at the first error. Response codes are explicit: 204 for a null value, 404 for a missing entity.
Source: odata.org V2 URI conventions (3.2, 3.3, 6); OASIS – What's New in V4.0 (2.6.7, 2.7, 2.9, 3.1, 4.7); OASIS URL Conventions 4.01 (4.3.1).
Part 6 – Model features new in V4
- Singletons – a single entity addressed directly by name from the service root (no key).
- Containment – contained entities are addressed through their container: container entity + containment navigation + key.
- Enumeration types and type definitions (a named primitive type with fixed facets).
- One entity container per service.
- Navigation properties are one-directional; a
Partnerattribute makes a pair bidirectional. - Delta / change tracking via the
Prefer: odata.track-changesheader, and asynchronous requests viaPrefer: respond-async. - Annotations only through vocabularies – arbitrary custom XML elements and attributes in
$metadataare gone; V4 has standard vocabularies such as Core, Capabilities and Measures. Example:Core.OptimisticConcurrencyControlreplaces the oldConcurrencyMode.
Source: OASIS – What's New in V4.0 (2.2, 2.3.3, 4.2.5–4.2.7, 4.3.4, 4.4.3, 4.8, 4.10); OASIS URL Conventions 4.01 (4.3.2).
Part 7 – Moving a UI5 app from the V2 to the V4 model
SAP's own reasons for the separate V4 model: protocol incompatibility between OData V4 and V2, API clean-up and simplification, and alignment with the V4 naming standards. What changes for the developer:
Topic | V2 model | V4 model |
|---|---|---|
Binding parameters |
| the real query option names: |
Reading data |
| not available – use the binding context API |
CRUD | model methods | no such methods – implicit through list/context bindings |
Operations | callFunction | operation binding ( |
Batch control | model-wide (deferred / change groups) | per binding via group parameters; |
Aggregation / trees |
|
|
Data cache | global entity cache in the model | no global cache – data is kept per binding |
Metadata | metadata loaded with the model; |
|
Source: SAPUI5 documentation – Transition from OData V2 to OData V4.
Part 8 – Sources
- OASIS – What's New in OData Version 4.0
- OASIS – OData JSON Format Version 4.01
- OASIS – OData Version 4.01 Part 2: URL Conventions
- odata.org – OData Version 2.0 JSON Format
- odata.org – OData Version 2.0 URI Conventions
- SAPUI5 documentation – Transition from OData V2 to OData V4
odata.org's V2 page states that OData Version 4.0 is the current recommended version.
Part 9 – Interview questions
Q1. How do you recognise V2 vs V4 from a JSON response?
V2 verbose JSON wraps everything in d; collections are in d.results, entries carry __metadata, the count is __count. V4 has no wrapper: the collection is value, control information is @odata.context, @odata.count, @odata.nextLink, @odata.etag. The response header is DataServiceVersion in V2 and OData-Version in V4.
Q2. What happens to Edm.DateTime when you move to V4?
It is removed. A timestamp becomes Edm.DateTimeOffset (with time zone), a pure date Edm.Date, a time Edm.TimeOfDay (Edm.Time is also removed). V2 sends DateTime as /Date(ms)/; client code that parses that format must change.
Q3. How do you migrate a substringof filter?
substringof('Mill', CustomerName) becomes contains(CustomerName, 'Mill') – the arguments swap. For conditions on a collection, V4 offers any / all, e.g. Items/any(i: i/Quantity gt 100).
Q4. Function import vs action vs function?
V2 has function imports. V4 splits them: an action has side effects and is called with POST, a function has none and is called with GET; both can be bound to an entity or collection, and functions can appear in $filter and $orderby. In RAP, BDEF actions become V4 actions.
Q5. What changes when a UI5 app moves from the V2 to the V4 model?
No model CRUD methods or callFunction – everything goes through bindings, contexts and operation bindings; parameters use the real names $expand / $select; batching is controlled per binding ($direct, group IDs); there is no global cache; aggregation uses $$aggregate; metadata comes from ODataMetaModel.