# SAP OData V2 and V4 Query Options Cheat Sheet

> Source: https://netray.co/tools/sap-odata-v2-v4-query-options-reference
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

A lookup table of OData system query options, filter operators and functions, showing which work in V2, which in V4, and an example for each.

## Category

sap

## Erp

SAP S/4HANA

## Audience

- SAP integration developer
- SAP Fiori developer
- SAP BTP developer

## Tool

**Kind:** worksheet

**Mode:** reference

**Columns:**

#### Option or operator

**Key:** option

**Type:** text

#### V2

**Key:** v2

**Type:** text

#### V4

**Key:** v4

**Type:** text

#### Example

**Key:** example

**Type:** text

#### Notes

**Key:** notes

**Type:** text

**Rows:**

**Option:** $filter

**V2:** Yes

**V4:** Yes

**Example:** $filter=Plant eq '1010'

**Notes:** Restricts the entities returned

**Option:** $select

**V2:** Yes

**V4:** Yes

**Example:** $select=Material,Plant

**Notes:** Reduces payload, always use it on wide entities

**Option:** $expand

**V2:** Yes

**V4:** Yes

**Example:** $expand=to_Item

**Notes:** V4 supports nested options such as $expand=to_Item($select=Material)

**Option:** $orderby

**V2:** Yes

**V4:** Yes

**Example:** $orderby=CreationDate desc

**Notes:** Use asc or desc

**Option:** $top

**V2:** Yes

**V4:** Yes

**Example:** $top=100

**Notes:** Page size

**Option:** $skip

**V2:** Yes

**V4:** Yes

**Example:** $skip=100

**Notes:** Use with $top for client paging

**Option:** $inlinecount

**V2:** Yes

**V4:** No

**Example:** $inlinecount=allpages

**Notes:** V2 way to return the total count with the page

**Option:** $count (option)

**V2:** No

**V4:** Yes

**Example:** $count=true

**Notes:** V4 way to return the total count with the page

**Option:** $count (path segment)

**V2:** Yes

**V4:** Yes

**Example:** /A_SalesOrder/$count

**Notes:** Returns a plain number

**Option:** $format

**V2:** Yes

**V4:** Yes

**Example:** $format=json

**Notes:** Often replaced by the Accept header

**Option:** $search

**V2:** No

**V4:** Yes

**Example:** $search=pump

**Notes:** Free text search, depends on service support

**Option:** $metadata

**V2:** Yes

**V4:** Yes

**Example:** /$metadata

**Notes:** Service metadata document, appended to the service root

**Option:** $batch

**V2:** Yes

**V4:** Yes

**Example:** POST /$batch

**Notes:** Groups several requests; V2 uses multipart, V4 can use JSON

**Option:** $skiptoken

**V2:** Yes

**V4:** Yes

**Example:** $skiptoken=...

**Notes:** Server driven paging; use the next link the server returns

**Option:** $apply

**V2:** No

**V4:** Yes

**Example:** $apply=groupby((Plant))

**Notes:** Aggregation, only where the service supports it

**Option:** eq

**V2:** Yes

**V4:** Yes

**Example:** Plant eq '1010'

**Notes:** Equal

**Option:** ne

**V2:** Yes

**V4:** Yes

**Example:** Status ne 'C'

**Notes:** Not equal

**Option:** gt / ge

**V2:** Yes

**V4:** Yes

**Example:** Quantity gt 10

**Notes:** Greater than, greater or equal

**Option:** lt / le

**V2:** Yes

**V4:** Yes

**Example:** Quantity le 500

**Notes:** Less than, less or equal

**Option:** and / or / not

**V2:** Yes

**V4:** Yes

**Example:** Plant eq '1010' and Status eq 'A'

**Notes:** Use parentheses to group

**Option:** in

**V2:** No

**V4:** Yes

**Example:** Plant in ('1010','1020')

**Notes:** V4 only; in V2 chain eq with or

**Option:** substringof

**V2:** Yes

**V4:** No

**Example:** substringof('PUMP',Description)

**Notes:** V2 contains test, note the argument order

**Option:** contains

**V2:** No

**V4:** Yes

**Example:** contains(Description,'PUMP')

**Notes:** V4 replacement for substringof

**Option:** startswith

**V2:** Yes

**V4:** Yes

**Example:** startswith(Material,'FG')

**Notes:** Prefix match

**Option:** endswith

**V2:** Yes

**V4:** Yes

**Example:** endswith(Material,'01')

**Notes:** Suffix match

**Option:** tolower / toupper

**V2:** Yes

**V4:** Yes

**Example:** tolower(Name) eq 'acme'

**Notes:** Case folding, many SAP services are case sensitive

**Option:** datetime literal

**V2:** datetime'2026-01-31T00:00:00'

**V4:** 2026-01-31T00:00:00Z

**Example:** CreationDate ge datetime'2026-01-01T00:00:00'

**Notes:** Date literal syntax differs between versions

**Option:** guid literal

**V2:** guid'...'

**V4:** plain value

**Example:** ID eq guid'00000000-0000-0000-0000-000000000000'

**Notes:** V4 drops the guid prefix

**Option:** string literal

**V2:** 'text'

**V4:** 'text'

**Example:** Name eq 'O''Brien'

**Notes:** Escape a single quote by doubling it

**Notes:** Behavior depends on the service implementation. SAP Gateway services built with SEGW support only part of the full OData standard, so confirm each option in the service metadata and by testing in the Gateway Client (transaction /IWFND/GW_CLIENT).

## Content

**Intro:** OData is the default way to read and write S/4HANA data from outside SAP, but V2 and V4 differ in small ways that break requests. This cheat sheet lists the query options and operators with the version differences marked.

**Sections:**

#### How to use this cheat sheet

**Body:** Search for an option or operator and read the V2 and V4 columns. Copy the example into your URL and replace field names with the ones from the service's $metadata. Export the table if you want a local version for your team's wiki.

#### V2 versus V4 in SAP landscapes

**Body:** Most released S/4HANA APIs on the SAP Business Accelerator Hub are still OData V2, while newer RAP based services and many cloud APIs use V4. A project often needs both. The usual breakers are $inlinecount versus $count, substringof versus contains, and different date literal formats. Always read the metadata first so you know the version and which operations the entity set allows.

#### Paging and performance

**Body:** Use $select and $filter on every call. For big reads, prefer server driven paging with the next link over large $skip values, because deep skips get slower. Avoid $expand across several to-many associations in one call since the response can multiply in size. Group writes using $batch with a change set so related changes succeed or fail together.

**Bullets:**

- Set a sensible $top, many services cap results anyway
- Never rely on default ordering, add $orderby when paging
- Fetch an X-CSRF-Token with a GET before any POST, PATCH or DELETE

#### Common mistakes

**Body:** Forgetting to URL encode spaces and quotes, using double quotes around strings, and comparing a key with the wrong leading zeros are the usual causes of HTTP 400 responses. Material numbers and customer numbers often need their internal format with leading zeros.

**Cta:** If your integration team writes many one-off OData calls, Netray can set up a private assistant that drafts and explains queries against your own ERP, with human review before anything is written back.

**Faq:**

#### Why does my $count=true return nothing in OData V2?

**Answer:** The $count query option belongs to V4. In V2 you use $inlinecount=allpages to get the total with the page, or call the entity set path with /$count to get a plain number. Check which version your service endpoint uses before choosing.

#### How do I filter on a date in an SAP OData V2 service?

**Answer:** Use the datetime literal, for example CreationDate ge datetime'2026-01-01T00:00:00'. Some services expose dates as Edm.DateTime and others as strings, so look at the property type in the metadata. V4 services use ISO format without the datetime prefix.

#### Can I use contains in V2?

**Answer:** Not in standard V2. Use substringof('text',Property) instead, with the search text first. Some Gateway services do not implement it at all, in which case use startswith or filter on the server side with a custom function import.

#### What is the X-CSRF-Token for?

**Answer:** SAP Gateway protects changing requests against cross-site request forgery. Send a GET with the header X-CSRF-Token set to Fetch, read the token from the response header, and include it in the following POST, PUT, PATCH or DELETE using the same session cookies.

## Search terms

sap odata query options, odata $filter examples sap, odata v2 vs v4 differences, sap gateway odata $expand, odata $inlinecount vs $count, sap odata $top $skip paging, sap odata $batch, odata filter functions substringof contains

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
