OData – Back to basics?

The title is somewhat misleading – but nevertheless it’s a great way to kickstart OData.
This are the notes on “Back to basics: OData – the Open Data Protocol” by DJ Adams.

For an overview on OData see: SAP Community: Daniel Purucker – Howto OData – High level overview
Community-Site: https://community.sap.com/topics/gateway
CAP: https://cap.cloud.sap/docs/
OData specification: https://www.odata.org/
MS Learn OData: https://learn.microsoft.com/en-us/odata/

Part 1 – Introduction

Repo: https://github.com/SAP-samples/odata-basics-handsonsapdev

npm install

Check the installation:

git version
node -v
ui5 --version
cf --version
cds --version

If needed install the missing components:

npm install --global @ui5/cli
npm install --global @sap/cds-dk

Then, after deploying to a local SQLite database, start the service up:

cds deploy --to sqlite
cds run

Consider using a dev-container:

My Repo: https://github.com/dapuru/devcontainer
My Doku: https://blog.daniel-purucker.com/vscode-devcontainer-part-1/
Or use: https://github.com/features/codespaces as well as https://www.gitpod.io/

Part 2 – Basics operations

Open OData-service in: http://localhost:4004

Useful Plugins (included in the dev-container):
CDS graphical modeler in VSCode
CDS graphical modeler in BAS
OData CDSL modeler – to visualize edmx-files

Important files:
– /db/data/schema.cds
defines the entities
– /srv/main.cds
says: using northwind from ‘../db/schema’;
The service is definded as “service NorthwindModel” – CAP creates a service named northwind-model from this.

Requests in UI5 when calling the odata-service

  • GET
  • the model metadata

  • HEAD
  • CSRF-Token for CORS

  • POST
  • $batch to request the data GET *bundled*. – Oposite than single requests, when “groupId”: “$direct” is set in the UI5 manifest.jsonfor the model.

Link: Details on HTTP-Protocol… to come

Operations – CRUD+Q:
– *Read*: select a single entity (old style and new style – 3 is the id here)


– *Query*: select multiple entities (top 3) or filter


Part 3 – System query options

Look at the oasis-open.org specification

Examples for system query options:

– $count=true
get the number of returned records included in the result set
– url/entity/$count
get the number of records as integer
– url/entity/item/$value
get the “raw” data-value
– $top and $skip
server-side paging
– url/entity?$expand=item
show relations inline – in the same resource representation
eg.: /Products(1)?$expand=Category
– $filter

See a definition of all system query options:
Specification – URL conventions

System query options vs. custom query options:


Part 4 – All things $filter


Part 5 – actions and functions


– Function
read-only, quote from the sepc: “functions **MUST NOT** have observables side effects”. http: GET.
Types: bound vs. unbound (see: [https://cap.cloud.sap/docs/cds/cdl#actions](https://cap.cloud.sap/docs/cds/cdl#actions))
Functions are *defined* at service level.

function randomProduct() returns Product;

Functions are *implemented* at service level eg. in java-script. Here in srv/main.js
Call via: url/service/function-name()
here: http://localhost:4004/northwind-model/randomProduct()

– Action
does something – CreateUpdateDelete on the server, quote from the spec: “actions **MAY** have observable side effects”. http: POST.
Definition and Implementation same as in Functions.

Part 6 – Wrapping up


Exploring Annotations

How to control the level of metadata:


(What controls the level of metadata in an OData response?

Consume on-prem ABAP-based OData service

– using the Cloud connector
– eg use ES5 system as described in this Cloud connector Code Jam (Archive)

Consuming an on-prem ABAP-based OData service
How to guide – Connectivity Setup with ABAP and SAP Cloud Connector

Consume cloud ABAP OData service

You may also like...

1 Response

  1. November 22, 2022

    […] The last blog-posts laid the theoretical foundation for the OData protocol: https://blogs.sap.com/2022/01/22/howto-odata-high-level-overview/ https://blog.daniel-purucker.com/odata-back-to-basics/ […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.