Skip to Content
Technical Articles
Author's profile photo Maxime Simon

Use xsodata to expose HANA tables as Odata services

Disclaimer :This tutorial is designed for SAP HANA on premise and SAP HANA, express edition. It is not designed for SAP HANA Cloud. If you want to expose HANA Cloud tables, check “Use CAP to expose HANA Cloud tables as Odata services.”

When you want to expose data residing into a HANA database to the outside world, the recommended best practice is to use Odata.

In this blog, you will learn how to build xsodata services used to expose your data model.
In the next blog, we use that Odata service to build a User Interface.
xsodata services uses the proprietary XSJS dialect of Javascript to create an Odata service. In order to use XSJS, SAP adds Node.js modules to provide XSJS compatibility.

This content is based on the tutorial by Thomas Jung, SAP HANA XS Advanced, creating a Node.js module.Expose%20data%20residing%20in%20SAP%20HANA%20Cloud%20via%20Odata%20services

Expose data residing in SAP HANA via Odata services



  • SAP HANA, or SAP HANA, Express edition
  • Customers, orders, products tables created in your HDI container, as described in Kabata-san’s blog post. (You can also check his github for the code used)


Create a Node.js module in your project

Open the SAP Web IDE, right-click the project where you created a DB module and create a new Node.js Module.


Give a name to your Node,js Module. I called mine core_xsjs


Check “Enable XSJS Support”.  By checking it, you enable the SAP XSJS libraries which allow you to use the programming model and APIs from the Extended Application Services, classic model.


A node.js module called core_xsjs gets created in your project.

The mta.yaml file has been extended to add the core_xsjs module.
This XSJS module will also need data from the database module and the HDI container behind it. Add those dependencies to the node module Requires section.Additionally add the UAA service for authentication if you created it. Then save and close the mta.yaml.

This step is essential : if dependencies are not declared in the mta.yaml file, your Node.js module will not be able to access the HDI container.

Create an Odata service with xsodata

Right-click the lib folder and create a new file.

Input xsodata/customers/xsodata
This will create a new folder xsodata, and a file customers.xsodata within it.

Within customers.xsodata, paste the following code :

service {
	  as "customers";

This code creates an Odata service v2.0 exposing the content of the table order-entry.db::customers.
You could do the same with views or virtual tables. Find out more about XSODATA

Run and test your service

Right-click your Node.js module core_xsjs and Run it as a Node.js Application.

This will build and run the Node.js application. Click on the URL of the node.js service, and add this path at the end : /xsodata/customers.xsodata/customers?$format=json

This will access your Odata service. 

Your data is now exposed to the outside world.
In the next steps, we will use this Odata service to build a User Interface.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Martin Shinks
      Martin Shinks



      I have just tried this now and all was going well until I tried to run the URL with the additional /xsodata/customers.xsodata/customers?$format=json at the end of the URL. 

      I get this error : -


      "Invalid HANA setting provided. OData services are disabled...."


      Would you know what this is and how it can be rectified.


      Is this method the only way to expose a table as an OData service?




      Author's profile photo Martin Shinks
      Martin Shinks

      On the mta.yaml file adding hdi_db fixed it.


      I missed that step.



      Author's profile photo jhonatan pelaez
      jhonatan pelaez

      Hi good day


      Excuse me, and how is that authentication service configured?

      Author's profile photo Maxime Simon
      Maxime Simon
      Blog Post Author

      This is outside the scope of this blog,

      you can find official information about the XSUAA (User Account and Authentication Services in XS Advanced) on SAP HELP.

      I would recommend this tutorial by Thomas Jung if you want detailed explanations

      Author's profile photo Meenakshi Swaminathan
      Meenakshi Swaminathan

      Hi Experts,

      I have followed this blog and exposed the HANA DB as ODATA service using xsodata. I am able to perform POST, Delete and GET operations but PUT operation is failing with error message "Error while executing a DB query" and status code "500" and also PATCH operation is failing with error message "Method not allowed" and status code "405".

      Can you please help to sort this out?


      Author's profile photo Taranam Dhindsa
      Taranam Dhindsa

      hi Meenakshi

      Were you able to achieve PATCH ? I am also getting same error.




      Author's profile photo Taranam Dhindsa
      Taranam Dhindsa

      Found the reason as per Note 3013788