Download as pdf or txt
Download as pdf or txt
You are on page 1of 47

S/4 HANA (DAY-51)

ODATA(Open Data Protocol)

UNDERSTANDING:

So imagine you have a big bag of candies that you want to share with your
friends. But there's a problem! Your friends have different preferences for
candies, and some of them are allergic to certain types. So, you need a set of rules
to make sure everyone gets the candies they like, without anyone getting sick.

Now, replace candies with data, and you with SAP. OData is like a set of rules
that SAP follows to share data with other applications and devices that connect
using the HTTP protocol. This means that any software or device that can speak
the HTTP language can communicate with SAP, read, write, and modify data in
an XML format, which is like a universal language for data.

But why is this important? Well, think of OData as a way to break down the
barriers that exist between different software applications, like silos that keep
data locked away from each other. With OData, developers can build cross-
platform web and mobile applications that can access and use data from different
sources, regardless of the programming language used.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-51)
ODATA(Open Data Protocol)

INTRODUCTION:

➢ OData is a widely-used open data protocol that enables the creation and consumption of RESTful web services
that expose data in a standardized format. In SAP, OData is used to expose data from SAP systems to other
applications and devices outside of the SAP ecosystem. This allows external applications to consume SAP data in
a standardized way, without having to use proprietary SAP protocols or technologies.

➢ OData is based on widely adopted web standards such as HTTP, REST, JSON, and AtomPub, which makes it
easy to consume OData services from virtually any technology stack or programming language that supports
these standards. OData can be consumed by various platforms, including Java, .NET, Node.js, and many others.

➢ One of the benefits of OData is its ability to facilitate the development of cross-platform applications that can
consume data from different sources. This means that OData can be used to enable interoperability between
different systems, allowing developers to build applications that seamlessly integrate data from various sources,
including SAP systems.

➢ In SAP, OData is implemented using the SAP Gateway service, which enables the creation and consumption of
OData services. SAP Gateway provides a set of tools and services that simplify the development and deployment
of OData services, making it easier for developers to expose SAP data to external applications.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-51)
ODATA(Open Data Protocol)

Production of Odata Services Consumer of ODATA

S
A
P
HTTP(s)
Database
Database N Internet
Database SAP or
W ODATA Non-SAP
G World
W

Application Layer Presentation Layer

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-51)
ODATA(Open Data Protocol)

Well, imagine you have a gateway, like the entrance to a cool amusement park.
Now, SAP Netweaver Gateway is like the entrance to a world of amazing SAP
applications and services.

In technical terms, SAP Netweaver Gateway is a technology that enables the


creation of easy-to-use, efficient and secure SAP-based applications that can be
accessed via a variety of devices, such as smartphones, tablets, and desktop
computers.

Using SAP Netweaver Gateway, developers can create interfaces that allow
external systems to communicate with SAP systems. These interfaces can be
created using various technologies like OData, REST, or SOAP. In simpler terms,
think of it as a bridge that connects different software systems together.

With SAP Netweaver Gateway, companies can build user-friendly and responsive applications that can be accessed by anyone,
anywhere, anytime. So, whether you are in your office, at home, or out and about, you can still access your SAP-based
applications and services.
So, just like a gateway to a cool amusement park, SAP Netweaver Gateway is the gateway to a world of amazing SAP-based
applications and services, making it easier for companies to connect with their customers and partners.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-51)
ODATA(Open Data Protocol)
Advantages of ODATA:

1. Cross-platform compatibility: OData is a web protocol that can be used to access data across different platforms and
devices, regardless of the programming language used. This allows for seamless integration and sharing of data between
different systems and applications.

2. Easy to use: OData is easy to use and understand, thanks to its RESTful architecture and support for popular data formats
like JSON and Atom/XML. This makes it easy for developers to build and consume OData services, without needing to learn
new technologies or programming languages.

3. Better security: OData supports industry-standard security mechanisms such as OAuth and SSL/TLS, which helps ensure
that data is transmitted securely over the network.

4. Simplifies data access: OData provides a standardized way to access data across different systems and applications, which
simplifies data access and eliminates the need for custom integration solutions.

5. Improves data quality: OData allows for the creation of complex queries that can be used to filter, sort and group data. This
helps to ensure that only high-quality data is accessed and processed, which in turn leads to better business insights and
decision making.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-51)
ODATA(Open Data Protocol)
Advantages of ODATA:

1. Cross-platform compatibility: OData is a web protocol that can be used to access data across different platforms and
devices, regardless of the programming language used. This allows for seamless integration and sharing of data between
different systems and applications.

2. Easy to use: OData is easy to use and understand, thanks to its RESTful architecture and support for popular data formats
like JSON and Atom/XML. This makes it easy for developers to build and consume OData services, without needing to learn
new technologies or programming languages.

3. Better security: OData supports industry-standard security mechanisms such as OAuth and SSL/TLS, which helps ensure
that data is transmitted securely over the network.

4. Simplifies data access: OData provides a standardized way to access data across different systems and applications, which
simplifies data access and eliminates the need for custom integration solutions.

5. Improves data quality: OData allows for the creation of complex queries that can be used to filter, sort and group data. This
helps to ensure that only high-quality data is accessed and processed, which in turn leads to better business insights and
decision making.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)
Let’s drive into more deeper in OData

UNDERSTANDING:
Imagine you're embarking on an exciting adventure in the land of SAP, and your mission is
to build a gateway to connect different systems. To begin your quest, you need a magical
tool called the SAP Gateway Service Builder. But how do you find it in this vast SAP world?

Well, remember it like this: Picture yourself entering a secret code into a mystical console.
You close your eyes and say, "SE38, take me on a gateway journey!" But wait, we're not
going to SE38, we're going on a grander adventure! Instead of 38, we add "GW" for
"GateWay" to create our very own gateway shortcut. So, behold the magical t-code for
today's topic: SEGW!

Now, as you enter the SEGW world, be ready to unleash your creativity and shape the
destiny of data flow. With the power of SEGW, you become the architect of connectivity,
forging paths between systems, and creating harmonious exchanges of information.
Remember, my friend, SEGW is not just a code, it's your magical key to unlock the gateway
to a world where data flows freely, systems communicate seamlessly, and business
processes flourish. So, embrace the adventure, let your imagination soar, and let SEGW be
your guide on this epic journey through the SAP universe!

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

Imagine you're in a coding playground called SEGW, where


Project name.
magic happens. You spot a "Create" icon, like a door to new
Example: ZGW_VISITOR_DETAILS
coding adventures. You click it and enter the details of your
project: a cool name, a brief description, and whether you
want to work with others or go solo.

Description

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

Project Type:

1. Basic Service: This project type is perfect when you're starting from
scratch and want to create a new OData service. It allows you to define
the structure, behavior, and data model of your service, giving you
complete control from the ground up.
2. Consumption Model: If you're looking to consume and interact with
existing OData services, this project type is for you. It enables you to
connect to external OData services and use their data and functionalities
in your own applications.
3. Service with SAP Annotations: This project type is specifically designed
for SAP systems. It allows you to create an OData service with predefined
SAP annotations, which provide additional information about the service
and its entities. These annotations enhance the interoperability and
compatibility of your service within the SAP ecosystem.
4. Service with Local Annotations: If you prefer to define custom
annotations for your OData service, this project type is the way to go. It
gives you the flexibility to create and manage your own annotations
locally, tailoring the service to your specific needs.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

Standard Strategy: This option refers to the traditional approach of developing


OData services following the SAP Gateway standards and guidelines. It provides a
comprehensive set of features and capabilities to design, implement, and consume
OData services. By selecting the Standard Strategy, you adhere to the established
best practices and guidelines recommended by SAP.

OData 4.0: This option represents the newer version of the OData protocol,
specifically OData version 4.0. OData 4.0 brings enhancements and additional
features compared to its predecessor versions. It introduces improved data
modeling capabilities, more flexible querying options, better support for complex
data types, and enhanced support for web and mobile application development.
Selecting OData 4.0 allows you to leverage the latest features and advancements
offered by the protocol.

Both options have their merits, and the selection depends on factors such as your project requirements, system landscape, and compatibility
with existing services. If you are starting a new project or have the flexibility to adopt the latest standards, OData 4.0 is a recommended choice
to take advantage of its enhanced capabilities. On the other hand, the Standard Strategy is a reliable and well-established option for
maintaining compatibility with existing services or following specific guidelines.
In summary, the General Category dropdown in SEGW provides you with the flexibility to choose between the traditional Standard Strategy or
embrace the newer OData 4.0 version, enabling you to develop OData services that best suit your project needs and align with the evolving
standards in the SAP Gateway ecosystem.
www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

Empty

UNDERSTANDING:
Think of it like building a house - you need a blueprint to show the contractors what
you want the house to look like, how many rooms it should have, where the kitchen
and bathrooms will be, and how everything should be laid out. Similarly, in OData,
you need a data model to show other applications how your data is organized, what
types of entities are available, and how they can be accessed.
In SEGW, you create your data model by defining entities, relationships, properties,
and other elements that represent your data. This data model is then used to
generate the OData service that will expose your data to other applications or
services.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

An entity set in OData is like a


Entity types in OData represent
collection or a group of similar things.
different types of objects or entities in
Just like a folder on your computer that
your data model. They define the
holds multiple files, an entity set holds
structure and properties of these
multiple entities.
entities.
An entity, in this case, is a
Think of entity types as templates for
representation of a single item or
creating instances of entities. For
object. For example, if you have an
example, if you have an entity type
entity set called "Books," each book
called "Product," it would define
would be represented as an entity
properties like "name," "price," and
within that set.
"description" for each product.
So, think of an entity set as a container
Entity types help standardize how data
that stores multiple entities of the
is organized and accessed in OData
same type. It helps organize and
services. They make it easier for clients
manage related data, allowing you to
to understand and interact with the
easily work with and retrieve specific
data.
groups of entities when needed.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

3
Structure

Structure’s Fields

Table

Operations

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

To add properties for entity types might be boring,


So, try some import features. How? Let’s go for next slide.
1

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

Choose the fields which you want to be part of your structure/entity

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)
2

Choose your primary key for structure

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-52)
ODATA(Open Data Protocol)

Click on the Generate icon and then click on OK. Next,


provide the package and transport number, or simply save
it as a local object. Once done, you should receive a
success message displayed on the screen. After continue,
We’ll get technical name of OData.

Keep in mind that the Technical Service Name represents


the specific service that the external system should call.
When creating the OData service, two classes are
generated: the Model Provider Class (MPC) and the Data
Provider Class (DPC). These classes, along with the Base
and Extended classes, play important roles in the
functioning of the service.

We’ll cover the more about DPC, MPC


and OData in upcoming post.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
ODATA(Open Data Protocol)

After click on generate button, We’ll get these Runtime Artifacts

Data Provider Class

Data Provider Class Extended

Model Provider Class

Model Provider Class Extended

Meta Data Language Extension

Service Implementation

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
ODATA(Open Data Protocol)

UNDERSTANDING:

Today we'll explore the two essential classes generated along with the Base and Extended Class, namely, the Data Provider
Class (DPC) and Model Provider Class (MPC).

Think of the DPC as the star player in the OData game. It is responsible for fetching data from SAP and translating it into OData.
You can think of it as a translator who speaks both the language of SAP and OData, ensuring that data is accurately conveyed to
external systems. The DPC is responsible for performing Create, Read, Update, and Delete (CRUD) operations. Without the DPC,
external systems would not be able to interact with SAP data in an OData-compliant manner.

Now let's move on to the MPC, the supporting cast of the OData game. The MPC is responsible for defining the metadata for
the OData service. You can think of metadata as a "data about data," that describes the structure of the OData service. The
MPC defines the Entity Sets, Entity Types, and Associations that make up the OData service. It also maps the Entity Types to the
Data Provider Class (DPC). Without the MPC, the external systems would not know how to interact with the OData service.

To put it simply, the DPC is the quarterback of the team, translating SAP data into OData, while the MPC is the coach, who
defines the rules of the game, and the structure of the OData service. Together, they form a formidable team that enables
SAP data to be easily consumed by external systems.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

In SAP OData, the DPC (Data Provider Class) and DPC_EXT (Data Provider Class Extension) are two important runtime artifacts
that are responsible for handling the data requests and processing the data.

The DPC is responsible for handling all the CRUD (Create, Read, Update, Delete) operations on the data entities defined in the
data model. It contains methods that handle all the HTTP requests sent by the client application. These methods are
automatically generated by the SAP Gateway Service Builder (SEGW) when the OData service is generated.

The DPC_EXT, on the other hand, is used for adding custom business logic to the OData service. It allows developers to add
additional methods to the DPC that can be used to perform complex operations on the data entities, such as validation,
calculation, and transformation. These methods can be called by the client application using the same HTTP requests that are
used for CRUD operations.

The DPC and DPC_EXT work together to provide a complete data processing solution for the OData service. While the DPC
handles the basic CRUD operations, the DPC_EXT can be used to add complex business logic to the service. Together, they
provide a flexible and powerful platform for developing OData services in SAP.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

Click

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC
To write your own logic in the DPC_EXT (Data Provider Class Extension) for the GetEntitySet operation, you can follow these
steps:
1. Open the DPC_EXT class in the ABAP Development Tools (ADT) or the ABAP Workbench (SE80).
2. Locate the GET_ENTITYSET method in the class. This method is responsible for retrieving a collection of entities based on
the provided parameters.
1

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC
3. Inside the GET_ENTITYSET method, you can write your custom logic to fetch the data from the backend system or any
other data source. You can use ABAP code to perform database queries, access external services, or retrieve data from other
systems.

Pre-defined Comments,
Implement your code and active the class.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

Example:

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC
4. Define the necessary input parameters for the GET_ENTITYSET method. These parameters typically include the filter,
sorting, and pagination parameters to determine which entities should be returned.

Filtering when we are getting it_filter_select_options

Sorting when we are getting it_order

Paging when we are getting it_paging

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC
Let us check the output. Go to t-code /n/IWFND/MAINT_SERVICE or /n/IWFND/GW_CLIENT.

Add Service which is created with Runtime Artifacts.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

3
1

Get this

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

URI stands for Uniform


Resource Identifier. It's like a
web address that helps you
find and interact with
resources in the system

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

3 1

URI stands for Uniform


Resource Identifier. It's like a
web address that helps you
find and interact with
resources in the system

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-53)
DPC

Success Status Code

Output

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-54)
Read Operation in OData

URI(Uniform Resource Identifier) UNDERSTANDING:

Imagine you're embarking on a cosmic journey through the


vast universe of OData. Your spaceship, known as a URI, has
three essential components:
Service root URI: It's like the launching pad for your space
adventure. It sets the stage and tells your spaceship where to
start exploring.
Resource path: Think of it as the interstellar highway that
leads you to specific destinations within the OData universe.
It's like zooming through different galaxies and star systems.
Query string options: These are like cosmic coordinates you
can tweak to fine-tune your journey. Want to see only blue
planets or filter out asteroids? Use the query string options
to customize your experience.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-54)
Read Operation in OData
But wait, there's more! As you navigate the OData cosmos, you might stumble upon additional cosmic phenomena like
fragments. These fragments are like mysterious space anomalies or hidden wormholes. While they might exist in the URI, the
OData specification doesn't assign any special meaning to them. Consider them as cosmic curiosities, waiting for intrepid
explorers like you to unravel their secrets.

So, buckle up, space explorer! Launch your URI spaceship, follow the resource path, play with the query string options, and
who knows what cosmic wonders you'll discover along the way. May your OData adventure be filled with excitement,
discovery, and a touch of interstellar charm!

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-54)
Read Operation in OData

For all URI queries details, Visit this blog:


https://www.odata.org/documentation/odata-version-2-0/uri-
conventions/#:~:text=A%20URI%20used%20by%20an,meaning%20to%20such%20additional%20constructs.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-54)
Read Operation in OData
READ Operation (GET_ENTITY method) in OData SAP:

In OData SAP, the READ operation is used to retrieve the data of a single entity from the OData service. It is performed using the
GET_ENTITY method. Let's dive into some key points about this operation:

Purpose: The READ operation allows you to fetch the data of a specific entity based on its unique identifier. It is similar to
performing a "GET" request in HTTP.
Syntax: The GET_ENTITY method is typically implemented in the service provider class. It takes the entity key as a parameter
and returns the corresponding entity data.
Usage: To perform a READ operation, you need to provide the entity key, which is usually passed as a part of the URL or as a
parameter in the method call. The OData service retrieves the entity data based on the provided key and returns it in the
response.
Response: The response of the READ operation includes the data of the requested entity, which is typically returned in the
OData format (e.g., JSON or XML). The response may also include additional metadata or related entities, depending on the
service implementation.
Error Handling: If the requested entity does not exist or if there is any error during the retrieval process, the service should
handle and communicate the appropriate error response to the client.
Security: Like any other operation in OData, the READ operation should adhere to the security measures defined by the OData
service provider. This includes authentication, authorization, and data access restrictions to ensure data confidentiality and
integrity.
www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-54)
Read Operation in OData
The READ operation (GET_ENTITY method) is fundamental in OData SAP for retrieving specific entity data from the service. By
implementing this operation correctly, you can effectively fetch the required information and build robust OData services in
SAP.
A hand-on example: https://abapskill.com/odata/get-operation-odata-service-part-4/

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

UNDERSTANDING:
Imagine you're in a magical world of OData adventures, where entities are like characters in a story, and associations and
navigation are the secret paths that connect them. Let's embark on this fun journey:

Association:
In our OData realm, associations are like invisible threads that connect entities together. They're like the friendships and
relationships between characters. Just like in real life, associations define how many friends each character can have. Some
characters have just one best friend (one-to-one), while others have many companions (one-to-many) or even a whole squad
of friends (many-to-many). These associations make the OData world rich and interconnected.

Navigation:
Now, picture navigation as a magical ability that allows characters to explore the OData world and discover new realms. With
navigation, characters can take a leap and jump from one entity to another, just like traveling through portals or secret
doorways. It's like a treasure hunt, where characters follow clues (navigation properties) to find hidden gems of related data.
They can effortlessly hop between entities, finding valuable information without having to go through long and tedious
searches. It's like a shortcut to accessing the desired data.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

Together, associations and navigation create an enchanting experience in the OData universe. They connect entities like never
before, enabling characters (client applications) to unravel the interconnected web of data. They make the OData journey
exciting, intuitive, and full of surprises. So, grab your imaginary map, follow the associations, and navigate through the OData
world to unlock the secrets and unveil the wonders that lie within!

Associations in OData are like connections between entities, defining how they
relate to each other. Navigation is the ability to move between entities based
on these connections. Associations establish relationships, while navigation
allows easy exploration of those relationships.

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

3 4

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

Navigation Property

www.linkedin.com/in/think-dot-code
S/4 HANA (DAY-55)
ASSOCIATION & NAVIGATION

For Hand-On Example: http://www.techippo.com/2016/08/association-navigation-sap-odata-service.html

INTERVIEW QUESTIONS:

1. What is an association in OData?


2. How do you define associations between entities in OData?
3. What is the purpose of navigation properties in OData?
4. Explain the difference between a unidirectional and bidirectional association in OData.
5. How do you navigate from one entity to another using navigation properties in OData?
6. What is the significance of the "partner" property in an association in OData?
7. Can an entity have multiple navigation properties to the same target entity? If yes,
explain how it can be achieved.
8. How do you handle recursive associations in OData?
9. What is the use of the $expand option in OData and how does it relate to navigation?
10. How can you control the depth of navigation in OData to avoid infinite loops?

www.linkedin.com/in/think-dot-code

You might also like