Build database objects/services in HANA service using SAP WebIDE Full-Stack : Part 2
This blog is part of a blog series which shows to build HANA database artefacts using the SAP WebIDE Full-Stack and the new HANA service on Cloud Foundry.
Create Nodejs. Module
In this section, I am going to show how to create a nodejs module and add an OData service within it. This OData service will be used to expose the contents of the table/view modeled earlier.
Select the project “ProductsApp01” (created earlier) and use the context menu to create a “Node.js module”.
Provide the name of the module as “products01_js” and enable XSJS support before clicking on Finish.
Select the lib folder and use the context menu to create a new file with the name “products01.xsodata”
Paste the below code into the xsodata file
service {
"products01_db::catalog.product" as "Products"
keys ("Id");
}
Below is how your XSOData file would look like:
Modify the yaml file by selecting the nodejs module and under “Requires” section, add two dependencies. This will enable the nodejs module to refer to the DB artefacts.
Build the nodejs module by selecting the folder and using the Build option in the context menu
You should see a success message in the log files..
Run the nodejs application using the menu option shown below.
This will take few minutes. You will get a URL in the console as shown below.
Click on the URL and change it to refer the OData service as shown below
Let’s deploy this application in our Cloud Foundry runtime. Select the root project folder and use the context menu to Build the project
In few minutes, you should be able to the successful build and new folder would get created in your workspace with the .mtar file.
Deploy the mtar file to the Cloud Platform account using the context menu. When prompted for Cloud Foundry details – select your CF API Endpoint, Organization and space
This will take you few minutes to deploy the applications to your CF space.
Once the application has been deployed, navigate to your CF space and under Applications menu, you will be able to see one app for db module and another for js module. The products01_db app would be stopped by default and is only required for the creation of the DB artefacts. Also note there in another app with a long GUID. This app was created when you tried to test the nodejs module from within WebIDE. You can stop this app as its not required. We will be using the app “products01_js” as it will provide the OData service.
Click on the js app to view the application URL.
Modify the URL to call the OData service as shown below and open it in the browser.
https://oneflp-cal-dev-products01-js.cfapps.eu10.hana.ondemand.com/products01.xsodata/Products
This should return the list of products. You can now use this URL with other SAP CP services or build a UI on top of it too.
Hope you found this blog series useful. If you bump into any issues, please post a question in the forum and tag me.
References:
When attempting to create my first HANA artefacts on Cloud Foundry environment, I noticed that there was not much info out there. The below HANA 2.0 tutorials were brought to my attention by Lucia Subatin . Please note that these tutorials will not work on SAP CP due to various limitations. I have spent nearly a day collecting info from various tutorials & HANA Academy contents to get this simple scenario working.
https://www.sap.com/developer/tutorials/xsa-ml-e2e-github-mta.html
https://www.sap.com/developer/tutorials/xsa-ml-e2e-create-cds-db.html
https://www.sap.com/developer/tutorials/xsa-e2e-db-explorer.html
https://www.sap.com/developer/tutorials/xsa-e2e-cds-new.html
https://www.sap.com/developer/tutorials/xsa-ml-e2e-create-node-module.html
https://www.sap.com/developer/tutorials/xsa-ml-e2e-create-ui5-interface.html
Great stuff as always Murali Shanmugham !
Hello
Thanks for below tutorial. I completed all your steps, however when i run the NODE.JS file, i am getting error on executing xsodata service.
https://nscsopya8reqw91bacf-products01-js.cfapps.us10.hana.ondemand.com/products01.xsodata
Error->
Hey Naman, it looks like products01_db::catalog.product is not the correct source. Have you tried only using "product"? It worked for me when I had a similar error.
Hi Naman, did you manage to get around the ‘No data found’ error? I’m facing exactly the same issue although the table used by the OData service contains data.
Thanks!
Marco
Hi Murali,
thanks for sharing great stuff, same we all are facing same issues. please help.
Hi Friends,
To fix this error:
You can use the full Namespace in xsodata file : I tried this and it seem to be working fine:
Also , remember to add the Odata annotation in your artifact file.
Thanks for the hint