Use an OData Service in Analytic Applications

You can define OData Services in SAP Analytics Cloud, analytics designer based on an existing on-premise SAP S/4HANA live connection in your system which was created using CORS (​​Cross-origin resource sharing) connectivity. Additionally, you can also define OData Services based on SAP BW systems, SAP HANA systems, and SAP Business Planning and Consolidation (BPC) systems (that were also created using CORS).

You can create an OData service, define the endpoint URL and trigger the execution of the action by using scripts.

OData services can be used to trigger transactional actions at the backend like filling out an order form or other forms.

In analytics designer, OData actions can be called from and executed in the backend system via scripting inside an analytic application. Furthermore, it is also possible to read and use the data of entity sets (exposed via OData services) by using APIs.

What you should know

  • OData actions are operations exposed by an OData service that may have side effects when invoked.
  • OData action imports, also called unbound actions are not associated with any OData entity set or entity. They generally expose simple parameters. All parameters are set via POST body.

  • OData bound actions are actions which may be invoked on a specific entity. They always contain a first parameter which is set via URL (to resolve the binding to the entity within the relevant entity set), and all other parameters are set via POST body.

    In general, actions can be bound on every type, but in analytics designer only binding on single entities is supported.

  • For OData you should configure the CORS (direct) connection at the backend. Please follow the instructions for the connection configuration in this chapter Live Data Connections to SAP S/4HANA.

    In the documentation chapter for the connection configuration (see link above) the CORS connection is referred to as direct connection.

    Note

    Note the following important additional configuration information:

    • The service path that you configure should correspond to the end-point URL of the OData service.

    • In addition to the service path listed in the documentation, you need to add another service path: /sap/opu/odata4/

    • The connection should also support if-match as allowed header.

Note the following restrictions::
  • Only parameters of simple types are supported. Actions with mandatory parameters of unsupported types are not available. For actions with optional parameters of unsupported types, the action itself is supported but those parameters are not.

  • In case of bound actions, actions which are bound to an entity collection are not supported. Only actions which are bound to a single entity are supported. It is only possible to set this binding parameter by specifying the key of the entity on which the action should be carried out.

  • Only the JSON format is supported

  • Only S/4HANA on-prem is supported

  • Only Direct (CORS) connections is be supported.

  • The following types are not supported:
    • Edm.Stream

    • Edm.Untyped

    • all Edm.Geography types

    • all types defined in different name space

Add an OData Service to Analytic Applications

To execute an OData action, you must first add an OData service with the corresponding actions to your application.

Prerequisites

Have ready the end-point URL of the OData service. You'll need to enter it manually when creating the service.

Procedure

  1. In the Scripting section of your analytic application, click (Add OData Services).

    A new entry with the default name ODataService_1 appears below the OData Services node. A side panel opens on the right.

  2. In the side panel, do the following:
    1. Change the default name of the new service to a meaningful name, if you want.
    2. Select the system from the list of available SAP S/4HANA systems whose connections were already created in SAP Analytics Cloud under Connections.
    3. Manually enter a valid end-point URL of the OData Service, in the format /some/end_point/url/.

      You need to know the URL because there is no browse catalog available.

  3. Click the refresh button next to Metadata to review the metadata of the new OData service.
  4. Click Done to close the panel.

Results

Now you can use the OData action. For further information, please see Example 1: Use OData Actions in an Application

Read Data from OData Services

With OData services you can not only can access OData actions, but also read and use the data of entity sets exposed via OData services.

This lets you use the data of the entity sets for any purpose except data visualization in a table or a chart. For example, you can read and display one member in a text widget. To access entity sets exposed via OData Services, you can use two APIs in your script:
  • getEntity: for retrieving a single OData entity from an entity set, by specifying the key to the entity. This is similar to selecting a single row from a SQL table via SELECT * FROM T1 WHERE ID = <id>.

  • getEntitiesFromEntitySet: for retrieving all entities from an OData entity set. This is similar to SELECT TOP <N> * FROM T1. With this API you can use the OData system query options filter, orderby, select, count, top and skip.
    Note

    The number of entities is limited to 1000 if no system query options have been used. If system query options are set, the number of retrieved entities is not limited, unless you set a value for the system query option top. top.

  • getEntitiesCountFromEntitySet: for retrieving the number of entities from an OData entity set. This API works like the getEntitiesFromEntitySet API and you can also use the OData system query options filter, orderby, select, count, top and skip.

Example
The parameters filter, orderby, and select have string values which will be 1:1 used in the OData request. This allows you to use all features supported by the query options. The parameters skip and top have integer values, that will be used in the OData request. The second parameter in both API methods is passed as object, in which the system query options can be combined in an arbitrary way.
Sample Code
// returns a list of entities, filtered by the given system query option(s)
ODataService_1.getEntitiesFromEntitySet("Departments", {filter: "contains(Sector,'Consulting')", orderby: "Sector asc" });
// returns a list of entities, not filtered
ODataService_1.getEntitiesFromEntitySet("Equipments");
// returns the number of entities in the entity set "TEAMS"
ODataService_2.getEntitiesCountFromEntitySet("TEAMS");
// returns the number of entities in the entity set "EMPLOYEES", filtered by the given system query option(s)
ODataService_2.getEntitiesCountFromEntitySet("EMPLOYEES", {skip: 5, top: 10}); 
Note
When you want to read data from OData services, note the following feature restrictions::
  • chaining from one entity set to another is not supported

  • expand (analogous to joining) is not supported

  • entity sets with parameters are not supported

  • entity sets with mandatory filters are not supported