OData
17 January 2024
23:48
OData data model The OData data model provides a generic
way to organize and describe data.
OData protocol The OData protocol lets a client make
requests to and get responses from an
OData service. In essence, it’s just HTTP-
based RESTful CRUD interactions along with
an OData-defined query language. Data sent
by an OData service can be represented
either in the XML-based format or in JSON.
OData client libraries The OData client libraries facilitate the
creation of software that accesses data via
the OData protocol. Using a specific client
library (e.g., from Microsoft) isn’t strictly
required, but it does make life a lot easier for
developers. However, a developer is always
free to create an OData client from scratch—
it’s just code.
OData services Finally, OData services are what implement
the OData protocol and expose an endpoint
that allows access to data. In effect, OData
services use abstractions of the OData data
model to translate data between its
underlying form into the format sent to the
client.
Structure of an OData Service document: A service document
Service represents a service by exposing all
resources that can be accessed through the
service, their URIs, names, and operations.
Service metadata document: The service
metadata document exposes all metadata of
a service. It exposes the model, types,
actions, relations, and detailed semantics
information of that part of the model.
Entity Entity is a Realtime object which consist of
some Properties
Entity type Entity type is name structure with key.
Entity set It’s a kind of internal table. Entity Sets are
collection of same entity types.
Property It contains entity type details like fieldname,
key field, label, EDM core type etc.
Navigation property It is used to navigate one side association to
other association.
Association In odata we can establish the relationship
between two entitites.
Odata Operations Create_entity- It can perform create
operation in the service.
update_entity- It can perform update
operation in the service.
delete_entity- It can perform delete operation
in the service.
get_entity- It can fetch data based on the key
field in the service.
get_entityset- It can fetch all the data in the
service.
REST commands POST- create an entity
GET- read an entity
PUT- update an entity
DELETE- delete an entity
GET- query on entity Set
PATCH- updating only certain field
MERGE- If the data is there it will update, if
its not there it will be create.
OData Query Options
Filtering $filter and $select
Sorting $orderby
Paging $top, $skip and $inlinecount
Counting $count
Inlining $expand
Formatting $format
Odata v2 vs v4 1. In odata v2 it supports the data in xml
format but in odata v4 it supports both
xml and json format.
2. In odata v4 it fetches huge amount of
data but in odata v2 it became slow.
3. In odata V4 supports more complex
queries, sorting and filter
Methods for Creating an Service generation:
OData Service
Mapping to 1. Remote
a data function call
source (RFC)/Busine
ss Object
Repository
(BOR)
function
modules
2. Search help
(only READ
and QUERY
method)
3. Core Data
Services
(CDS) views
(only READ
and QUERY
method)
Redefinitio Allows you to define a
n service based on an
existing data
source or an existing
SAP Gateway service.
Reference Allows you to define a
d data service based on a CDS
sources view.
(RDS):
Creating Generate an OData
CDS views service without
with the Service Builder by
Eclipse creating CDS views using
Eclipse and setting the
OData.publish:true
option.
Service Creation three main phases:
Process data model definition-
It contain entity type, association,
entityset.
Through this data model it can be
import ddic table, bapi, cds, and also it
can be create create entity type,
entityset, complex entity etc.
service implementation
it performs SADL framework operation
manually, without writing any logic.
in this we can do create, update,
delete operation.
service maintenance
It can contain the odata service, in
service maintenance we can register
our service, need to pass the system,
client and registration status details,
then through this gateway client button
it we can see all the details.
GET_EXPANDED_ENT It’s displayed our data in header AND item
ITY, format.
GET_EXPANDED_ENT
ITYSET
CREATE_DEEP_ENTIT It can be create header and item data at one
Y place.
EXECUTE_ACTION Whenever you want to perform operation in
entity that time you can used function import.
Ex- we can perform oeration like approve or
reject.
Dev Process
Entity Set Attributes
Flag Annotation Description/Example
Creatable sap:creatable Creation of entries of the related
entity type is supported.
Creates are handled via HTTP
POST requests.
For example, you can create a
business partner entry.
Updatable sap:updatable Updates of entries of the related
entity type are supported.
Updates are handled via HTTP PUT
requests addressing the
entry resource you want to update.
For example, you can update a
product with the product ID
“123”.
Deletable sap:deletable Deletions of entries of the related
entity type are supported.
Deletions are handled via HTTP
DELETE requests address ing the
entry resource you want to delete.
For example, you can delete a sales
order line item with
the key OrderId=’50000’,Item=’10’.
Pageable sap:pageable Client-side paging of this entity set is
supported. Client side paging works
via the query parameter. The client
can define the page size and the
number of entries to be skipped.
Addressable sap:addressable This indicates whether the related
entity set can be
addressed directly via the URI (e.g.,
ProductSet) or
whether you have to use a
navigation property to address
it via a different entry—for example,
SalesOrder Set(‘1’)/Items.
SalesOrderItemSet wouldn’t be
directly addressable
because it makes no sense to read
all order items across all
sales orders without the respective
order header.
Searchable sap:searchable This indicates whether the service
implementation (QUERY
method) supports a search string. A
search string doesn’t
filter on any properties as such but
provides the search
string via the URI search parameter
—for example,
ProductSet?search=’box’.
Subscribable N/A This indicates if a consumer can
subscribe to changes of
the underlying entities. Subscription
and notification han dling require
corresponding system configuration
(e.g.,
bgRFC) as well as user exit
implementations or event link ages
to send a notification based on a
backend event.
Requires sap:requires-filter This indicates whether a query
Filter requires a filter or not. If a
filter is required, you can’t execute a
query without a filter.
For example, BusinessPartnerSet
fetches all business
partners available in the system,
which can be quite a lot.
Therefore, it makes sense to force a
consumer to provide a
filter.