ERPClimb logoERPClimb
OData V2
RAP / CDS / ODataintermediate 7 min read

OData V2 Part 1: The Classic OData V2 Service Model

Free sample lesson · open to everyone

Key takeaway

Understand the classic OData V2 service model you will meet in existing SAP landscapes: service document, $metadata, entity sets, associations and navigation, V2 query syntax, JSON format and how V2 differs from V4.

In this lessonShow sections

Visual overview

OData V2 Part 1: The Classic OData V2 Service Model — learning sheetIn one line: Understand the classic OData V2 service model you will meet in existing SAP landscapes: service document, $metadata, entity sets, associations and navigation, V2 query syntax, JSON format and how V2 differs from V4.ERPClimb.com / RAP / LESSON 1/3 / LEARNING SHEETOData V2 Part 1: The Classic OData V2 Service Model1 · IN ONE LINEUnderstand the classic OData V2 service model you will meet in existing SAP landscapes:service document, $metadata, entity sets, associations and navigation, V2 query syntax, JSONformat and how V2 differs from V4.2 · KEY IDEAS EXPLAINEDWhere You Meet V2Services built with transaction SEGW (GatewayService Builder).Many SAP-delivered Fiori apps and older custom UI5apps (sap.ui.model.odata.v2.ODataModel).URL And ContractService root: /sap/opu/odata/sap/ZPURCHREQ_SRV/(SEGW) or the binding URL for RAP V2.$metadata: EntityType, EntitySet, Association,AssociationSet, NavigationProperty, FunctionImport— and SAP annotations (sap:label, sap:creatable…V2 Query Options$select, $filter, $orderby, $top, $skip, $expand —like V4 but simpler ($expand without nestedoptions).$inlinecount=allpages — total count in theresponse (V4: $count=true).JSON FormatResponses (with $format=json or Accept:application/json) are wrapped in "d":3 · DO · AVOIDBest practice!Common mistakeKnow which protocol a consumer uses beforewriting requests.Read $metadata and SAP annotations(sap:creatable, sap:filterable) first.Use MERGE/PATCH for partial updates.✕Using V4 syntax against V2 services (contains,$count).✕Forgetting the "d" wrapper whenparsing V2 JSON.✕Using PUT for partial updates (overwritesunspecified fields).4 · IN A REAL PROJECTA new developer familiar only with RAP V4 tried to add a filter to an old SEGW-based integration usingcontains(Description,'chair') and $count=true. The service returned errors, and he suspected a broken backend.A colleague showed him the V2 equivalents — substringof and $inlinecount=allpages — and the "d"…Original ERPClimb learning sheet • Verify against your SAP release and edition

Expert visual walkthrough

RAP · CDS · ODATA ACADEMY · Integration pathERPClimb.com

The Classic OData V2 Service Model

OData V2 · Chapter-specific technical teaching map

Integration path

1Concept

API client

2Concept

OData contract

3Concept

Gateway / RAP runtime

4Concept

HTTP response

Tutor's chapter takeaway

Understand the classic OData V2 service model you will meet in existing SAP landscapes: service document, $metadata, entity sets, associations and navigation, V2 query syntax, JSON format and how V2 differs from V4.

In a real project

A new developer familiar only with RAP V4 tried to add a filter to an old SEGW-based integration using contains(Description,'chair') and $count=true. The service returned errors, and he suspected a broken backend. A colleague…

Watch out for

• Using V4 syntax against V2 services (contains, $count). • Forgetting the "d" wrapper when parsing V2 JSON. • Using PUT for partial updates (overwrites unspecified fields). • Not requesting JSON ($format=json / Accept…

Conceptual study map, not an SAP configuration screenshot or a guaranteed runtime sequence. Consult the lesson for implementation prerequisites and exceptions.

The situation: a real project scenario

A new developer familiar only with RAP V4 tried to add a filter to an old SEGW-based integration using contains(Description,'chair') and $count=true. The service returned errors, and he suspected a broken backend.
A colleague showed him the V2 equivalents — substringof and $inlinecount=allpages — and the "d" wrapper in responses. The integration worked immediately. The team then added a V2/V4 cheat sheet to their wiki, since both protocols would coexist for years.

Explanation

This series covers OData V2 across three parts: this lesson covers the classic OData V2 service model; Part 2 covers deep insert, batch and navigation design; and Part 3 covers production troubleshooting with gateway logs and metadata. The SAP Gateway series, covering the runtime behind V2 services, is a related read.

V2 shows up in quite a few places still: services built with transaction SEGW, the Gateway Service Builder; many SAP-delivered Fiori apps and older custom UI5 apps built on sap.ui.model.odata.v2.ODataModel; integrations written years ago; and RAP service bindings of type "OData V2 – UI" or "OData V2 – Web API" for consumers that simply can't use V4.

The URL and contract follow a distinct pattern: the service root sits at something like /sap/opu/odata/sap/ZPURCHREQ_SRV/ for a SEGW service, or at the binding URL for a RAP V2 service. $metadata describes EntityType, EntitySet, Association, AssociationSet, NavigationProperty and FunctionImport, along with SAP-specific annotations like sap:label, sap:creatable and sap:filterable. Keys are addressed as /PurchaseRequestSet('4711') or, for composite keys, /PurchaseRequestSet(RequestID='4711',Year='2026').

V2 query options look similar to V4 but simpler: $select, $filter, $orderby, $top, $skip and $expand all work, though $expand has no nested options the way V4's does. $inlinecount=allpages returns the total count in the response, where V4 uses $count=true instead. Functions differ too — substringof('chair',Description) in V2 corresponds to contains(...) in V4, alongside startswith and endswith. Dates in filters use a format like datetime'2026-09-01T00:00:00'.

The JSON format wraps everything in a "d" property: a list response looks like { "d": { "results": [ … ], "count": "57" } }, while a single entity looks like { "d": { … } }, carrying its own "metadata" with uri, type and etag.

Operations cover the full CRUD set: GET, POST, PUT for a full update, MERGE or PATCH for a partial update, and DELETE. Function imports handle operations that V4 would expose as actions or functions. And writes still require a CSRF token, exactly as in V4.

Comparing V2 and V4 directly: V4 offers cleaner JSON, contains(), $count, nested $expand options, bound actions, and better batch support, while V2 benefits from mature tooling and a large base of existing apps, using function imports in place of actions. Migrating a consumer from V2 to V4 means changing both the UI5 model and the request syntax, and is worth planning as its own project rather than a quick swap.

In practice: open an existing V2 service in /IWFND/GW_CLIENT, or a browser, and read its $metadata; run the V2 queries shown in the code example; and compare the same query against the equivalent RAP V4 service. With that, any SAP OData V2 service can be read and queried confidently.

Code example

ABAP Code
### {v2} = /sap/opu/odata/sap/ZPURCHREQ_SRV        (SEGW service)### RAP V2 binding: /sap/opu/odata/sap/ZUI_PURCHREQ_O2/ ### ContractGET {v2}/$metadata ### List with fields, filter, sort, paging and total count (V2 syntax)GET {v2}/PurchaseRequestSet?$select=RequestID,Description,TotalAmount,Currency    &$filter=Status eq 'S' and substringof('chair',Description)    &$orderby=TotalAmount desc&$top=20&$skip=0    &$inlinecount=allpages&$format=json ### Response (V2 JSON: wrapped in "d")# { "d": { "__count": "57",#          "results": [ { "__metadata": { "uri": ".../PurchaseRequestSet('4711')",#                                         "type": "ZPURCHREQ_SRV.PurchaseRequest",#                                         "etag": "W/\"datetime'2026-09-24T09%3A00%3A00'\"" },#                         "RequestID": "4711", "Description": "Office chairs", ... } ] } } ### Single entity and navigationGET {v2}/PurchaseRequestSet('4711')?$format=jsonGET {v2}/PurchaseRequestSet('4711')/ToItems?$format=jsonGET {v2}/PurchaseRequestSet('4711')?$expand=ToItems&$format=json ### Date filter in V2GET {v2}/PurchaseRequestSet?$filter=CreatedOn ge datetime'2026-09-01T00:00:00' ### Function import (V2 "operation")POST {v2}/ApproveRequest?RequestID='4711'X-CSRF-Token: <token> ### V2 -> V4 cheat sheet# $inlinecount=allpages  -> $count=true# substringof('x',F)     -> contains(F,'x')# {"d":{"results":[]}}   -> {"value":[]}# function import        -> bound action / function# MERGE                  -> PATCH

Watch out

Common mistakes

  • Using V4 syntax against V2 services (contains, $count).
  • Forgetting the "d" wrapper when parsing V2 JSON.
  • Using PUT for partial updates (overwrites unspecified fields).
  • Not requesting JSON ($format=json / Accept header).
  • Building new RAP services as V2 without a consumer reason.

Do this

Best practices

  • Know which protocol a consumer uses before writing requests.
  • Read $metadata and SAP annotations (sap:creatable, sap:filterable) first.
  • Use MERGE/PATCH for partial updates.
  • Offer V2 bindings for RAP services only when consumers need them.
  • Plan V2→V4 migrations deliberately.

Apply it: production case clinic

Two decisions · one practical outcome

Use a fictional SAP incident to practise choosing the next safe investigation. This is a worked diagnostic exercise, separate from the lesson's existing knowledge-check questions.

ERPClimb SAP case file · ODATA V2

Distinguish an OData V2 entity-set contract from the V4 payload and query model.

Incident brief

An ECC-era SAP Gateway integration returns an object with a d/results envelope. A developer assumes the service is OData V4 and rewrites the client.

Evidence available

  • Service root uses /sap/opu/odata/sap/ZSALES_SRV/
  • A successful V2 collection response contains a d/results wrapper
  • Client expects an OData V4 value array

Decision 1 of 2

What should be checked before changing the server?

Apply in a permitted SAP DEV / test environment

Use an approved Gateway test client to read the service document, $metadata and one small entity-set query; write down the key, navigation and actual response envelope.

Evidence of success: A V2-aware client parses the sample correctly and uses keys listed in $metadata.

Release consideration: V2 examples can vary with JSON format negotiation and SAP Gateway release; do not assume the same wrapper in all representations.

Consult official SAP guidance (opens new tab)

Local, self-directed practice only. No SAP system is connected, no persistent grade is awarded, and no production changes are made.

In the interview

Interview angle

Questions: "What are differences between OData V2 and V4?", "Where do SAP OData V2 services come from?", "How do you get a total count in V2?"
Strong answer: V2 services come from SEGW, standard apps and RAP V2 bindings, under /sap/opu/odata/sap/; syntax differences: $inlinecount=allpages vs $count, substringof vs contains, "d"-wrapped JSON, function imports vs actions, MERGE vs PATCH, simpler $expand. New RAP services should use V4 unless a consumer requires V2.

Practice this lesson

Quick check

0 of 3 questions attempted

Question 1 of 3

Which V2 filter finds entities whose Description contains "chair"?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1What are the main differences between OData V2 and V4 for an SAP developer?

2Which Gateway tools do you use to troubleshoot OData V2 incidents, and for what?

See it in code

Each example starts from a requirement, shows the design, then the code step by step with a plain-language explanation of every part.

Was this lesson helpful?

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.