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
 Apps
X
HANA App
>>>
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
Apps
HANA App
Hadoop App
';
Search
Stay Connected
Search Topics
Topic Index
+
-
XSA Overview
+
-
XS Overview
+
-
Hello World Example
+
-
XS OData Service
+
-
HANA XSJS Service
+
-
Core Data Service
+
-
Others

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.

Prerequisite:


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.

--REPLACE <YOUR SCHEMA> WITH YOUR SCHEMA NAME

-- 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.
  2.  
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

4 thoughts on “How to Create SAP HANA OData Service

  1. Sulabh says:

    HI,
    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 {
    “sap.test::myTable”
    create forbidden
    update forbidden
    delete forbidden;
    }

Leave a Reply

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

Current day month ye@r *

 © 2017 : saphanatutorial.com, All rights reserved.  Privacy Policy