Skip to Content
Technical Articles

OData with SAP HANA Cloud | Hands-on Video Tutorials

With this blog series we provide an update with the latest information on getting started with SAP HANA Cloud on the SAP Cloud Platform.

  1. About SAP HANA Cloud
  2. SAP HANA Cloud Getting Started
  3. SAP HANA Cloud and SAP Business Application Studio
  4. HDI with SAP HANA Cloud
  5. Cloud Foundry Advanced (space travel, multiple instances, defining schema names)
  6. SAP HANA Cloud, JWT Provider, and Certificate Collection with Purpose JWT
  7. Data masking and data anonymization
  8. Predictive Analysis Library (PAL) and Automated Predictive Library (APL)
  9. Remote data sources and virtual tables
  10. OData with SAP HANA Cloud
  11. SAP HANA Cloud Graph
  12. Role Attributes
  13. SAP HANA Cloud and Smart Data Integration

For more information about the free trial, see

For the new features overview posts, see

Questions? Post as comment.

Useful? Give us a like and share on social media.

Thanks!

/wp-content/uploads/2016/02/sapnwabline_885687.png

Hands-On Video Tutorials

Philip MUGGLESTONE just added another video tutorial to the SAP HANA Cloud series. In this blog, you will find the video embedded with some additional information and resources. Following along in the patented zero-to-hero format, you will be ready to start working with OData with minimal effort and no time wasted.

You can watch the video tutorial in a little under 10 minutes. What you learn is

  • How to use a Yeoman app generator to create a sample multi-target app (MTA) which automatically creates the OData services for a chosen schema in SAP HANA Cloud
  • How the code works and what apps, services, and database catalog objects get created
  • How to use Postman to GET, POST, and DELETE data using the OData Services

As development environment we use the SAP Business Application Studio and the free 90-day SAP Cloud Platform trial environment for which you can sign up here:

To follow along you will need some basic understanding of the SAP Cloud Platform concepts and be familiar with global and subaccounts, Cloud Foundry, destinations, subscriptions, identity provider, SAP HANA Cloud, and HDI. In case you are new to the SAP Cloud Platform or could use an update, please first join our onboarding program:

As we know your time is precious, this will be a low-code affair as we will be using Yeoman to provide the scaffolding for our app supplemented with sample code from SAP HANA Academy GitHub repository:

Ready? Let’s make some REST calls!

/wp-content/uploads/2016/02/sapnwabline_885687.png

What Exactly is OData (again)? 

According to Microsoft (where the technology is coming from), as documented in Welcome to OData

OData (Open Data Protocol) is an ISO/IEC approved, OASIS standard that defines a set of best practices for building and consuming REST APIs. It enables creation of REST-based services which allow resources identified using Uniform Resource Locators (URLs) and defined in a data model, to be published and edited by Web clients using simple HTTP messages.

In more digestible terms, it is a way to interact with data sources over the web.

See Understanding OData in 6 steps for a bit more background from odata.org or (when you have bit more time), see blog series

 

/wp-content/uploads/2016/02/sapnwabline_885687.png

How Hard Can It Be? 

Working with OData using the SAP HANA XS classic model is not that difficult.

Create a file with the .xsodata file extension in your favourite IDE, say SAP HANA Web-based Development Workbench, and enter the service definition.

As documented,

However, this technology is deprecated and no longer available for SAP HANA Cloud.

service namespace "my.namespace" {
         "sample.odata::table" as "MyTable";
}

 

Working with OData using SAP HANA XS Advanced model and the SAP Cloud Platform Cloud Foundry environment for SAP HANA Cloud is a bit more challenging in particular when you need the current OData v4 version or have a larger selection of tables and views to configure. Let’s say this approach has some limitations.

An alternative and more recent approach involves the Cloud Application Programming (CAP) model but this provides a bit of a learning curve as it assumes a certain familiarity with CAP, Core Data and Services (CDS), Cloud Foundry, SAP HANA HDI, and OData.

/wp-content/uploads/2016/02/sapnwabline_885687.png

In Comes Yeoman

What if we would have a generator that writes the entire project including the CAP CDS modeling and also performs the SAP HANA configuration – so you can have OData up and running on all the tables and views of a given classical SAP HANA schema in about 5 minutes?

For free?

yo Saphanaacademy Odata

/wp-content/uploads/2016/02/sapnwabline_885687.png

OData on a Classical Schema

In this video tutorial, we install the yeoman OData generator and run it to scaffold the project. We can choose to include support for OData v2 (in addition to v4), add authentication and authorization, and directly build and deploy the app. After adding a role collection and inspecting the apps and services in SAP Cloud Platform cockpit, we interact with some of the OData services using Postman. The tutorial ends with a code walkthrough.

0:00 – Introduction

0:30 – SAP HANA Cloud > Advanced Settings: Allowed connections: Allow all IP addresses

0:45 – SAP HANA database explorer and execute sample schema, table, and view (source: travel_OData.sql)

1:30 – SAP Business Application Studio, create SAP Cloud Business Application dev space, and connect to the Cloud Foundry environment (trial org and space)

2:00 – open Terminal and install a Yeoman generator

npm i -g generator-saphanaacademy-odata

2:30 – Run the yo command and select Saphanaacademy Odata template: enter the app name, SAP HANA Cloud endpoint, database user, password, schema, OData v2 support, authentication and authorization, build and deploy.

3:45 Go to SAP Cloud Platform cockpit > subaccount Security > Trust Configuration: <e-mail> and assign the desired role collection

  • myappodata_read
  • myappodata_write

4:00 Run the application (app router) and the OData service is displayed with all tables and views.

4:45 – for OData v2 append /v2 to the URL, e.g. /v2/srv/Customers

5:00 – Open Postman

5:30 – Authorization: OAuth 2.0 > Get New Access Token:

grant type = password credentials

username = <e-mail trial account)

clientid, clientsecret, and url are defined as environment variables for the app router.

cf env myappodata-app

6:50 – Change URL to srv (instead of app)

7:00 – Use HTTP POST to insert data using JSON format specifying in the header

Content-Type = application/json/IEEE754Compatible=true

7:55 – Code walkthrough

Running travel_OData.sql script in SAP HANA database explorer

Running Yeoman generator in SAP Business Application Studio

Assigning role collection using SAP Cloud Platform cockpit.

 

Postman access token configuration

/wp-content/uploads/2016/02/sapnwabline_885687.png

Share and Connect 

Questions? Post as comment.

Useful? Give us a like and share on social media. Thanks!

If you would like to receive updates, connect with me on

For the author page of SAP Press, visit

For the SAP HANA Cloud e-bite, see

19 Comments
You must be Logged on to comment or reply to a post.
  • Dear Denys,

    what a great blog and I have a question.

    Is that possible to expose the data using XML format as a standard return from Odata?

    because from this tutorial we only get the JSON format when we put the resource path

     

    Thank you,

    Zacky

  • Hi Denys,

    I am in contact with you, because I have seen that your link on: OData with SAP HANA Cloud can solve a problem that I currently have.

    I have managed to carry out all the steps that you indicate in the blog, except the change of the ulr, where it says "app"
    by the value "srv".
    My service is deployed in foundry and when it generates the url, it does not create it with the value "app".

    https://cep---xxxxxxxxxx--s-a--dbcex-spacecex-db-xxxxxx.cfapps.eu20.hana.ondemand.com/

    Would you know how this problem can be solved?

    His blog is very interesting and very well explained

    Thank you very much and greetings.

    • Hi Fernando,

      Checked with Philip but it is not clear to us what might cause this issue.

      The approuter obtains an access token and with this token we can call the back-end (srv) module(s).

      Maybe you can write out the steps and add some illustrations where needed so we can reproduce the issue.

      Thx

  • Thanks for your prompt response.

    Say for example when I created the project, I had 2 tables in the schema . The application also shows 2 entityset for 2 tables respectively.
    Now another table is added to the schema, still 2 entity set are there.
    My query is, do I have to update the schema.cds ,cat-service.cds files manually ? Is there a command which can update them.

    Creating a new project with the schema fetches all the tables which are present at that moment.

    Hope I am able to explain what I am trying to do.

    Thanks

    Shyam

    • Hi Shyam,

      Thanks for asking,

      >>  Is there a command which can update them.

      Not yet (nor is there anything in the works) but you can run the generator again to recreate everything again based on what's in the schema at the time.

      >> My query is, do I have to update the schema.cds ,cat-service.cds files manually ? 

      That is also an alternative. The initial run provides an indication of what needs to be done.

       

  • Thanks for your blog.

    But i went some issues when I try to read the data via post man.

    it shows 401 error when i try to request a token.  but i followed all the steps you mentioned in the video.

    do you know why? Thanks!

    • Hi Kerry,

      Best to post your question to the forum > https://answers.sap.com for follow up and knowledge sharing.

      Copy/paste is fine but maybe include some screen prints so the issue can be reproduced.

      Thx!

  • Thanks for your blog.

    I followed the guide, but once the token is created with Postman, there is no possibility to change 'app' to 'srv' as the application name does not appear in the URL.

    I tried to put the URL I find inside SCP under myappodata-srv but Postman returns error 401 not authorized.

    Has the procedure changed with respect to this guide?

     

    Thanks.

  • Hi @denys.kempen , thanks for the blog. 
    But when I deploy the application it's said like: 
    
    Creating service "myappodata-db" from MTA resource "myappodata-db"...
    Service operation failed: Controller operation failed: 502 Updating service "myappodata-db" failed: Bad Gateway: Error creating service "myappodata-db" from offering "hana" and 
    plan "hdi-shared": CF-ServiceBrokerRequestRejected(10001): Service broker error: Service broker hana-broker failed with: Can not create service instance 'myappodata-db': 
    There is no database available. Ensure that you have a database available in space 'dev' within organization '4164c669trial'.

     

    When I have for sure the HANA Cloud connected and right configured.
    Do you know why?

    • Hi Sebastiano,

      There are two Schema and HDI Container services. The one with Trial appended points to the HANA Service (not HANA Cloud). Could it be the wrong HDI service is configured?

       

      /