SapHanaTutorial.Com HOME     Learning-Materials Interview-Q&A Certifications Quiz Online-Courses Forum Jobs Trendz FAQs  
     Explore The World of Hana With Us     
About Us
Contact Us
Hadoop App
Tutorial App on SAP HANA
This app is an All-In-One package to provide everything to HANA Lovers.

It contains
1. Courses on SAP HANA - Basics, Modeling and Administration
2. Multiple Quizzes on Overview, Modelling, Architeture, and Administration
3. Most popular articles on SAP HANA
4. Series of Interview questions to brushup your HANA skills
Tutorial App on Hadoop
This app is an All-In-One package to provide everything to Hadoop Lovers.

It contains
1. Courses on Hadoop - Basics and Advanced
2. Multiple Quizzes on Basics, MapReduce and HDFS
3. Most popular articles on Hadoop
4. Series of Interview questions to brushup your skills
Hadoop App
Stay Connected
Search Topics
Topic Index
XSA Overview
XS Overview
Hello World Example
XS OData Service
Core Data Service

How to Create SAP HANA OData Service

In previous articles Introduction to OData and SAP HANA OData Service, we explained
  • What is OData Service?
  • How does OData Service works in SAP HANA?

In this article we will show you how to create a HANA OData (.xsodata) service in simple steps.


Note: In this example we will use HANA Studio to create OData Service. You can also create it using HANA Web-based tools. For HANA Web-based tool, you should first read Create Your First HANA XS Application using HANA Web-Based Tool

Create a Table to be used in OData Service:

Let us first create a table which we will call using OData service.
Copy paste the below SQL script in HANA Studio SQL Console and execute.


-- Create Product table
create column table "<YOUR SCHEMA>"."PRODUCT"(
      "PRODUCT_ID" INTEGER null primary key,
      "PRODUCT_NAME" VARCHAR (100) null default ''

insert into "<YOUR SCHEMA>"."PRODUCT" values(1,'Shirts');
insert into "<YOUR SCHEMA>"."PRODUCT" values(2,'Jackets');
insert into "<YOUR SCHEMA>"."PRODUCT" values(3,'Trousers');
insert into "<YOUR SCHEMA>"."PRODUCT" values(4,'Coats');
insert into "<YOUR SCHEMA>"."PRODUCT" values(5,'Purse');

Steps to create HANA OData Service:

  1. Create a XS project as mentioned in the article Create Your First HANA XS Application using HANA Studio
HANA OData Tutorial
  1. Right click on the project and select New à XS OData File. Give file name as “ProductODataService” and click on Finish.
HANA OData Tutorial
  1. Copy paste the below code. Make sure you change <YOUR_SCHEMA> to the schema where PRODUCT table was created.
service {
"<YOUR_SCHEMA>"."PRODUCT" as "Product";
  1. Right click and select Team à Activate. This will activate the file.
HANA OData Tutorial
  1. Right click and select Run As à XS Service. This will open the XSOData service in default browser.
HANA OData Tutorial
  1. Enter user id and password of HANA system. You will see the result as
HANA OData Tutorial
  1. Note that the URL is constructed as http://<host>80<instance no>/<package path>/xsodata_file.

Done!! You have successfully created your first OData service.

Note: If you are using Chrome, then you may install 2 plugins to see the data in a formatted way.
  • XML Tree: For XML
  • JSONView: For JSON

A walk-through the OData Service:

The above OData service URL shows the OData definition.
To see the metadata information of the OData service, we can add $metadata parameter at the end of the URL.
http://<host>80<instance no>/<package path>/xsodata_file/$metadata
HANA OData Tutorial

To see the data in XML format, you need to specify the Entity name as parameter.
Remember that in xsodata file we specified the entity name as “Product”.
http://<host>80<instance no>/<package path>/xsodata_file/entity_name
HANA OData Tutorial

To see data in JSON format, you need to specify $format=json as parameter.
http://<host>80<instance no>/<package path>/xsodata_file/entity_name/?$format=json
HANA OData Tutorial

How to consume this OData Service:

The OData can be called from any SAPUI5 or HTML5 application. This can also be called from any other UI application (in Java, .Net etc.) or any tools that supports OData.

Continue reading:

Support us by sharing this article.

Explore More
Close X
Close X

11 thoughts on “How to Create SAP HANA OData Service

  1. Sulabh says:

    Excellent blog.

    I followed same steps. Working fine. When i execute http://80//xsodata_file/entity_name in IE this is asking for user id and pwd which is fine. After login I am not able to see properties of entity name. If I am downloading content to desktop and opening with notepad I can see all 5 values.
    When i am copying above URL and trying to execute in chrome. Nothing works. Please assist.

  2. Don says:

    How do you pass the userid and password as part of the url string?

  3. Esteban says:

    Thanks you for the post. i just try doing it on HCP and it seems to be working when quering data
    but i kept getting 403 Forbidden trying to do POST request.
    Do you know HCP allows POST or it is only read only like hana on premise used to be for an XSodata

  4. Esteban says:

    Already found the answer :
    By default, all entity sets and associations in an OData service are writeable, that is they can be modified with a CREATE, UPDATE, or DELETE requests. However, you can prevent the execution of a modification request by setting the appropriate keyword (create, update, or delete) with the forbidden option in the OData service definition. The following example of an OData service definition for SAP HANA XS shows how to prevent any modification to the table myTable that is exposed by the OData service. Any attempt to make a modification to the indicated table using a CREATE, UPDATE, or DELETE request results in the HTTP response status 403 FORBIDDEN.

    service {
    create forbidden
    update forbidden
    delete forbidden;

  5. Anjum says:


    Do you know how to filter data for a wildcard search? I want to get all materials which contain ‘nol’ in its description field.

    I tried filter=contains(mat_desc,’nol’) but the message says ‘contains’ is not valid, whereas when i try startswith(mat_desc,’nol’) it is giving me all records which begin with ‘nol’. I want to get all those records which has ‘nol’ in any part of string.

    Appreciate if you can suggest.


  6. karan says:

    Hi I follow the same steps till activate the XSODATA file. I am not getting the options to run as XS service.

    Even when i am trying to run in the http, it asking me to save the file. The file just show the Service {View name}.

    Could you please help

  7. Dorian says:

    I got ‘Collection “product” is not directly accessible’ error.

    • Admin says:

      Hi Dorian,
      Where exactly you are getting the error? While activating OData service, or while calling odata service via browser?

  8. Roshan says:

    Great work…Keep it up

Leave a Reply

Your email address will not be published. Required fields are marked *

Current day month ye@r *

 © 2017 :, All rights reserved.  Privacy Policy