Developing Applications Running on SAP BTP Using SAP HANA Cloud

Exposing an OData Entity Set with ODATA

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Create a simple OData service, using ODATA to expose a single Entity Set

Exposing an Entity Set as OData service

Exposing an OData Entity Set

Exposing an OData Entity Set

At design time, within the srv folder, you create an .cds file where you indicate the exposed database object, for example, table, view, calculation view, and so on, and the name of the Entity Set in the service.

On build, the application provides an OData service, exposing the object content under the given entity set name.

Exposing an OData Entity Set with ODATA

Business Example

Business Example

Code File- Exposing an OData Entity Set with ODATA

Example

We create the service definition .We create a .cdsfile under srv folder.

We create cat-service.cds (name can be anything). Copy the below code.

In the code below we observe,

  • reference of our schema.cds byusing keyword and providing the location ../db/schema.
  • Annotation -@odata.draft.enabled This is used to provide the capability to save a draft version of the record created using our Fiori application(later) before it is written to the database
  • entity Exposed for OData

Code snippet
using hc450.officesupplies as officesupplies from '../db/schema';

service CatalogService {
    @odata.draft.enabled :true
    entity Products as projection on officesupplies.Products;
    entity Suppliers as projection on officesupplies.Suppliers;
};
Expand

Save progress to your learning plan by logging in or creating an account