Explaining Data Services

Objectives

After completing this lesson, you will be able to:

  • Explain the OData protocol
  • Operate an OData Service for handling data
  • Operate SAP Gateway for handling data

OData Standard

One important aspect of the architecture of the World Wide Web is the use of abstract interfaces for component communication. These abstract interfaces are presented as connectors. A client and a server each use a connector component. There is a contract between both connectors that defines the application protocol. It defines the documents, their format, and the behavior. Any protocol can be chosen. By using the connector concept, both client and server are largely independent and exchangeable. Each connector translates the documents exchanged on the communication channel to the internal representations both on the server and on the client side, and vice versa.

The OData protocol defines such a contract by specifying a uniform protocol that has the necessary qualities. For instance, a connector attached to an SAP back-end system translates between ABAP APIs and OData entities. SAP Gateway is such a connector.

On the other side, a client connector translates between OData entities and the APIs of the consumer platform. The connector is specified here. As a consequence, any client platform with libraries supporting the contracted OData format can communicate with any server supporting the same contract.

OData follows the Representational State Transfer (REST) architecture design paradigm in the sense that the protocol transfers representations of the state of resources. The term resource denotes data that is addressable and accessible. The standard address representation or resource is the Uniform Resource Identifier (URI). A client requests a resource from a server by sending a request to a URI. The server processes the request by translating the URI to internal address data to access or manipulate the data, and then assemble the response.

Open Data Protocol

Let's try to understand what is open data protocol.

OData is an open standard originally developed by Microsoft but now managed by the Oasis Organization. It is based on the Atom Publishing and Atom Syndication standards, which, in turn, are based on XML (Extensible Markup Language) and HTTP(S) (HyperText Transfer Protocol (Secure)). JSON (JavaScript Object Notation) is an alternative to XML to structure data.

The objective of the OData protocol is to provide a vendor-neutral, web-based API that fully complies with the design principles of Representational State Transfer (REST). OData provides database-like access to server-side resources. In this context, OData is also called ODBC for the Web.

Note

Open Database Connectivity (ODBC) is a widespread database access method.

OData is also extensible. This enables SAP to supplement the data types used by OData with extra information from the ABAP Data Dictionary. Another example is metadata-driven development for Web and mobile like SAP Fiori elements.

OData is available in version 2 (V2), version 3 (V3), and version 4 (V4). The versions are built on each other extending the previous version by adding new features. The majority of OData services are based on V2. SAP Gateway supports OData V2 since AS ABAP 7.00 and OData V4 since AS ABAP 7.50. OData V3 was skipped in SAP Gateway and is therefore not supported.

OData Model

In current real-life applications, JSON (JavaScript Object Notation) is used instead of Atom and XML for structuring data. It needs considerably less meta-information, which reduces the amount of data transferred greatly. Atom and XML, in contrast, are used precisely because of the extensive meta-information when it comes to development.

To consume an OData service for read, you just need a browser and the OData service base URI. The service document is the highest-level description of an SAP Gateway service. It shows the basic information about the available data. From here, it is possible to call further information on the service, and of course the data itself, by adding URI parameters.

To get data from the service, add the name of an entity set of the service to the base URI. You get a list of entities of that type, which could be the content of a database table.

The entities of an OData service are defined in an Entity Data Model (EDM). Entity types define properties and navigations to other entity types. These associations define relation constraints based on key properties of the entity types. A navigation property is then used to actively navigate between entities during runtime. For every entity type, at least one entity set is defined. These are shown in the service document and used to request data from the OData service.

By adding the OData option $metadata to the service root URI, the metadata document of the service is shown. The whole EDM is defined here and available at runtime. Application developers and all the wizards in development environments create their applications based on this information.

Note
The metadata document is only available as XML.

Time for a Checkpoint on OData model.

How to Examine the Data Model of an OData Service

Business Example

You want to examine the data model of an OData service in a web browser.

Watch the video to see how to examine the data model of an OData Service.

OData Operations

One of the main features of OData is that it uses the existing HTTP verbs GET, PUT, POST, and DELETE at addressable resources identified in the URI. Conceptually, OData is a way of performing database-style create, read, update, and delete operations on resources through HTTP verbs.

By building URIs based on the rules of OData, a wide variety of data requests can be performed. These requests can often be mapped directly to SQL requests accessing data in a database.

Calling the service URI of an OData service in a GET request, results in the service document. Adding the name of an entity set to the base URI, results in a list or set of all entities. This is called a query request.

Adding the unique key of an entity in brackets to a query request, results in a single entity having this key. Character-based keys must be put in apostrophes. This is called a read request.

Adding a navigation property of the entity type to a read request separated by a slash, results in a single entity or a set of entities depending on the multiplicity of the association. This is called a navigation request.

Let's check your understanding of code related to navigation query.

OData Query Language

OData specifies a simple, yet powerful query language that allows a client to request arbitrary filtering, sorting, paging and so on. A client is able to express, via query string parameters, the amount and order of the data that an OData service returns for the resource identified by the URI. The names of all query string parameters defined by OData are prefixed with a "$" character.

Query Options

An OData request consists of a server address, service URI, entity set, and additional query options. There are many combinations of query options possible. A full documentation is available at http://www.odata.org.

How to Query Data of an OData Service

Business Example

You want to query data of an OData service in a web browser using query options.

Watch the video to see how to query data of an OData Sevice.

SAP Gateway Foundation

SAP offers a variety of OData providers. SAP Gateway (up to the end of 2014 known as SAP NetWeaver Gateway) provides a single entry point to access business data of ABAP-based systems such as the SAP Business Suite or SAP S/4HANA. The SAP HANA Extended Applications Services (XS) has the same role in SAP HANA – just to name another important OData provider.

Caution

SAP Gateway must not be confused with the kernel’s gateway process used for communication via RFC.

By using OData, business data can be shared among multiple environments and platforms. SAP knowledge is not required for the consumption of the data. Usually client-based applications consume SAP Gateway services and interact directly with the user. Applications in a Web browser are a common example.

However, it is also possible for an SAP Gateway service to be used as an API (Application Programming Interface) by a server-based application. Additional servers can be added to the communication path to enhance the possibilities for client and server. For mobile devices, the SAP Mobile Services add additional value to the applications.

For AS ABAP 7.00 to 7.31, SAP Gateway consists of individual add-ons that provide the OData functionality. These can be divided into the following areas:

Runtime
Provides the OData and thus the SAP Gateway service externally via the URI.
Design Time

Contains the development environment and programs for processing the requests to the service.

First introduced in AS ABAP 7.40 and finalized in AS ABAP 7.51, all add-ons are merged in the software component SAP_GWFND (SAP Gateway Foundation). This offers everything needed for the OData runtime and design time.

Note
Some SAP Gateway add-ons may still exist in an AS ABAP 7.51 after an upgrade. These are deprecated and should be uninstalled. Either their functions are now part of software component SAP_GWFND or they are no longer supported.

SAP Gateway Deployment Options

There are three possible deployment options for SAP Gateway (hub is a synonym for front-end server (FES)):

Hub deployment with development in back-end server (BES)
Hub deployment with development in front-end server (FES)
Embedded deployment

SAP Gateway Tools

Let's look at the three gateway tools:

  • SAP Gateway Service Maintenance (OData V2)
  • SAP Gateway Service Administration (OData V4)
  • SAP Gateway Client

Operate SAP Gateway Tools

Business Example

You want to examine and test an SAP Gateway service using SAP Gateway Service Maintenance and the SAP Gateway Client.

Note
This exercise requires an SAP Learning system. Login information are provided by your system setup guide.

Task 1: Check the registration of the OData V2 service ZEPM_REF_APPS_SHOP_SRV.

Steps

  1. Log on to your SAP S/4HANA (S4H) system using SAP GUI.

    1. In the SAP Business Client or SAP Logon, select the SAP GUI SNC system entry of your S4H.

    2. Choose Log On.

  2. Examine the service registration of the OData V2 service ZEPM_REF_APPS_SHOP_SRV in the SAP Gateway Service Maintenance on your S4H.

    1. On the SAP Easy Access screen, search for Activate and Maintain Services or start transaction /IWFND/MAINT_SERVICE.

    2. Choose Filter.

    3. In the Technical Service Name field, enter *epm_ref* and choose Continue.

    4. Choose the Technical Service NameZEPM_REF_APPS_SHOP_SRV.

    5. Confirm that the status of the ICF Node ODATA is green.

    6. Confirm that the Processing Mode is Co-deployed only and no system alias is assigned.

Task 2: Test the OData V2 service ZEPM_REF_APPS_SHOP_SRV.

Steps

  1. Call the service document of the OData V2 service ZEPM_REF_APPS_SHOP_SRV in the SAP Gateway Client on your S4H.

    1. In the ICF Nodes panel, choose SAP Gateway Client.

    2. Choose Execute.

    3. Examine the HTTP Response screen.

  2. Call the service metadata document of the OData V2 service ZEPM_REF_APPS_SHOP_SRV in the SAP Gateway Client on your S4H.

    1. In the SAP Gateway Client, choose Add URI Option.

    2. Double-click the URI Option$metadata.

    3. Choose Execute.

    4. Examine the HTTP Response screen.

  3. Display all products of the OData V2 service ZEPM_REF_APPS_SHOP_SRV in the SAP Gateway Client on your S4H.

    1. In the SAP Gateway Client, choose EntitySets.

    2. Double-click the EntitySet NameProducts.

    3. Choose Execute.

    4. Examine the HTTP Response screen.

  4. Display the first two products in the format JSON of the OData V2 service ZEPM_REF_APPS_SHOP_SRV in the SAP Gateway Client on your S4H.

    1. In the SAP Gateway Client, choose Add URI Option.

    2. Double-click the URI Option$format=json.

    3. Choose Add URI Option.

    4. Double-click the URI Option$top=2.

    5. Choose Execute.

    6. Examine the HTTP Response screen.

Log in to track your progress & complete quizzes