Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 
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 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.