In this tutorial I am going to build a simple HANA application, which consumes data from the HANA server using OData services using HANA Web IDE.
If you are new to the word OData services then I request to gain some knowledge on OData from the below URL.
Scenario:
To display the list of Flight information: To do that we have several options of retrieving the data from the HANA server. We can make use of ODBC or JDBC connection to retrieve data from database using SQL server. But we are going to make use of OData services which is basically designed to provide data to web application. SAP has included the tables for SFLIGHT in the repository. We can also create our own Schemas and Tables; we will see that in the next tutorials. In this tutorial I am going to make of Schemas and Tables which already exists.
Procedure:
1. Create a XS Hana project
2. Develop necessary artifacts
3. Create an OData Services
4. Consume the OData service
5. Testing the Application.
Pre-requisites:
1. An up and running HANA Server with valid user account.
2. Knowledge on XS project.
I recommend you to go through these tutorials before starting with this one.
1. A Simple HANA Application
2. A Simple HANA Application with server side JavaScript.
Create an XS HANA project:
Create a new project:
Choose HANA XS project from HANA Development folder and click on next.
Enter the name for the project and click on Finish.
Develop Necessary Aritfacts:
Create an application descriptor file with extension .xsapp and no name.
Leave the file blank.
Similarly create an Application access file, with file extension .xsaccess and no name. Write the following code in the file.
We have actually forgotten a step, Right click on the project and click on Team à Share project.
Note: The project that we have created so far is local. Sharing the project will create the project in the HANA System repository.
Creating an OData Service:
We have now completed the development of mandatory artifacts, and shared the project to the HANA system. Now let’s create an OData service.
For the system to identify the file as OData service, the Extension of the File has to be .xsodata
Now if you navigate to Content folder of HANA System perspective you can view all the schemas and dictionary objects available within them.
We are going to create a service to a Table “SFLIGHT” which is within the Schema “SFLIGHT”.
To view the content of what is there in the table, right click on the table and click on open data preview.
Now this is the data set for which we are going to create a OData service and consume them in the front end.
Create a File with the name of your choice and extension .xsodata.
Write the following code in it.
This is basically as simple syntax definition where we are creating a service and specifying the path where in Which Schema and which table is to be retrieved.
Note: We can also perform operation similar to that of Join and retrieve data from two or more tables. We can also restrict the use of data, like create update or delete in the database table.
Activate and Commit the whole project.
Testing the OData Services:
Execute the file Services.xsodata,
We get the name which we have provided of our choice in the .xsodata file. This means there is no issues with our OData.
To view the data, you can use the name which we have provided (the one after default) and attaché a parameter format.
We have now successfully created an OData service, which gets data from the SFLIGHT table.
We are now able to see the data, but this is not how the user wishes to see the data or work with it. In the Next tutorial we will see how to consume the OData and display them on the webpage using UI5 Table.
tHANKS for posting a valuable info. And i would like to see consuming this info on Html application or SAP UI5.
ReplyDelete