Using OData Resources

Objectives

After completing this lesson, you will be able to:

  • Create a data resource to an OData Service
  • Access the OData data resource from your app

OData Resource

An OData resource is a connection to a data store that adheres to the OData protocol. It is not so important to understand OData in detail; therefore, we will cover the most important points to know when connecting from SAP Build Apps.

An OData service defines a set of entities. These entities represent real-world things like customers, products, locations, and employees. Since OData services must provide metadata about the service, once you provide the URL to the service, SAP Build Apps will know what entities there are, their fields, and data types.

Each entity will define a set of fields, where each field represents a piece of information about that entity. For example, for customers, you might have the following fields:

  • CustomerID
  • CompanyName
  • ContactName
  • ContactTitle
  • Address
  • City
  • Region
  • PostalCode
  • Country
  • Phone
  • Fax

So far, we have defined the nature of the data we want to store. However, eventually, we will store actual data in our OData service entity, and that data is represented as a set of rows, with each row having a value for each of the fields. So, we might have the following data:

More information about OData including the mock system with the Northwind example to test the usage can be found here: https://www.odata.org/

Example Data

CustomerIDCompanyNameContactNameContactTitleAddress
ALFKIAlfreds FutterkisteMaria AndersSales RepresentativeObere Str. 57
ANATRAna Trujillo Emparedados y heladosAna TrujilloOwnerAvda. de la Constituci\u00f3n 2222

OData Resource Creation

Business Scenario

This procedure demonstrates how to create an OData resource.

Note that this procedure is oriented towards the standard example OData service, Northwind.

Steps

  1. Create an OData Resource.

    1. In a new SAP Build Apps project, open the Data tab.

    2. Go to SAP Build Apps classic data entitiesCREATE DATA ENTITYOData Integration.

    3. For the Base API URL, enter https://services.odata.org/v4/northwind/northwind.svc/and then choose VERIFY URL

      At this point, SAP Build Apps reads all the metadata and displays a list of entities contained in the service.

    4. Toggle the switch next to Customers.

      This creates a connection to this entity. If you want to connect to other entities, you can toggle those entities.

Access Data from OData Resource

Business Scenario

In this procedure, you will learn the steps to connect it or retrieve any data.

Steps

  1. Access Data from the OData Resource.

    1. Go back to the UI canvas.

      There should be a title and text component.

    2. Choose the title component, and in the Properties pane, change the Content to Customers.

    3. Choose Variables.

  2. Create a Data Variable.

    Now we will create a data variable that will store the data from the back-end and will contain logic for retrieving it.

    1. Choose Data Variables, and then Add Data Variable.

    2. Choose Customers as the data resource on which to base the data variable.

    3. Choose View to go back to the UI canvas.

    4. Choose on the text component and we will configure it to show the customer names.

    5. In the Properties pane, choose the icon under Repeat with, then select Data and Variables then Data Variable.

    6. Select Customers and choose Save.

      The text component will now display four times to indicate it is repeated (the four times does not indicate the amount of data, it will always be four times).

    7. In the Properties pane, choose ABC under the Content field, and select Data item in repeat.

    8. Select current, and then select CompanyName.

    9. Choose Save.

    10. Choose Save (upper right).

  3. Run the app.

    You will see a list of customers retrieved from the back-end.

Generate the Data of a Colleague with OData

Business Scenario

Use interfaces for the social page to obtain the first and last name and associated city of a fictitious random colleague, obtained by the Event of loading the page from an OData service.

Exercise Options

To start the exercise, choose Start Exercise in the figure below.

A pop-up opens. You have the following options:

  • Start: the simulation starts. Follow the simulation to learn how to generate the data of a colleague with OData.
  • Open PDF Document: a pdf opens. Based on the steps described in this document, you can perform the exercises in your own system landscape.

Generate the Meals by Button Logic and OData

Business Scenario

In the context of the social event of the two colleagues, configure a button in such a way that two different food options are generated and will display in relation to each other. This is done by choosing each from a list using the OData service. Thereby you can manipulate the font with text.

Exercise Options

To start the exercise, choose Start Exercise in the figure below.

A pop-up opens. You have the following options:

  • Start: the simulation starts. Follow the simulation to learn how to generate the meals by button logic and OData.
  • Open PDF Document: a pdf opens. Based on the steps described in this document, you can perform the exercises in your own system landscape.

Log in to track your progress & complete quizzes