Technical Articles
hana-cli: XSA MTA project in VS Code
Last time I wanted to play with hana-cli. I walked through the guide provided by (@Thomas Jung) and wanted to check out, what I can achieve with that.
If You are not familiar with hana-cli, please check first post blog/videos prepared by Thomas: https://blogs.sap.com/2020/03/26/hana-cli-sample-how-to-build-a-node.js-command-line-interface/
I came up with a simple task for my self to setup an existing XSA project for development in Visual Studio Code.
It took me a few hours, I learned a lot, and I prepared this blog post. I hope it will help someone.
Why I would like to develop XSA MTA application in VS Code anyway? There could be a few reasons:
- GIT console
- Faster IDE
- Node modules
But I treat it as a pure fun experiment and learning lesson.
Environment preparation
1. Install Node.js version 10.x or 12.x
2. Clone Your XSA project into a folder using git clone command
3. Add the SAP Registry to your NPM configuration
npm config set @sap:registry=https://npm.sap.com
4. Install hana-cli as a global module
npm install -g hana-cli
Connection setup
Now, to set up the connection between hana container and local project (hana-cli) we need to create a default-env.json file in db folder. It is a JSON file which contains a set of environment variables and their values. There we need to provide variables describing HDI container params which were generated for our XSA project.
Template:
`default-env.json` example file with a target container binding and a user-provided service:
{
"TARGET_CONTAINER" : "target-service",
"VCAP_SERVICES" : {
"hana" : [ {
"name" : "target-service",
"label" : "hana",
"tags" : [ "hana", "database", "relational" ],
"plan" : "hdi-shared",
"credentials" : {
"schema" : "SCHEMA",
"hdi_user" : "USER_DT",
"hdi_password" : "PASSWORD_DT",
"certificate" : "-----BEGIN CERTIFICATE-----\nABCD...1234\n-----END CERTIFICATE-----\n",
"host" : "host",
"port" : "30015"
}
} ],
"user-provided" : [ {
"name" : "GRANTING_SERVICE",
"label" : "user-provided",
"tags" : [ ],
"credentials" : {
"schema" : "SYS",
"user" : "GRANT_USER",
"password" : "PASSWORD",
"procedure_schema" : "PRIVILEGE_PROCEDURE_GRANTOR_DEFINER",
"procedure" : "GRANT",
"type" : "procedure",
"tags" : [ "hana" ]
}
} ]
}
}
Where we can find those properties for our project? – XSA Cockpit
Open SAP HANA XS Advanced Cockpit and navigate through:
Organization -> Space -> Your application, and select Environment Variables from the left menu.
In System-Provided section You should see configuration similar to the template above. You can copy sensitive data, but JSON has to be adjusted according to the above template.
To check if the configuration is correct type in terminal:
hana-cli status
If everything is fine, run:
npm start
//"start": "node node_modules/@sap/hdi-deploy/deploy.js --exit --auto-undeploy"
To build a project in a defined container. It is the same step which is done in Web IDE for building db folder.
If You did everything well – You can continue working on Your project in VS Code now 🙂 I found a lot of useful pieces of information in README of @sap/hdi-deploy node module. TThere are also a lot of explanations, how this module works and how to configure it correctly. I recommend to read that, to better understand the topic.
Bonus: Cloud MTA Build Tool
As a bonus to this task, I did test run for Cloud MTA Build Tool. Using MBT we could build the whole project to mtar file.
1. Install MBT as global module
npm install -g mbt
2. Build project with XSA flag
mbt build -p=XSA
And that’s it!
*.mtar file should be created in Your project directory.
Very happy to see that you found the hana-cli sample interesting and especially glad to see that you shared your learnings via a blog entry of your own. Nice job!
Hi Thomas. Thanks for your contributions..
My research for ways to improve my SDLC around the SAP HANA & XSA environments brought me here. Would you have some point form tips to share? For example:
Not sure I'm exactly sure what you are looking for here. Groups/blogs/etc - you are in the right place. I'd suggest following the HANA tag here in the community. We also have HANA content such as tutorials in the developer center. SAP Tutorial Navigator | Tutorials for SAP Developers We have just been adding some new tutorials that cover HANA Cloud development with CAP in the Business Application Studio. We also have videos in the SAP Developers channel on YouTube. SAP HANA - YouTube. Maybe that helps
Thank you for sharing!
I came across the following error: Error: Connection failed (RTE:[300006] Cannot create certificate store
I was able to solve this by removing the certificate in the credentials and add these parameters instead:
Hi Wouter Lemaire,
I believe this issue can be corrected by checking if you can run sapgenpse at any path. Open a command prompt and run this command. It should show you some information, including the environment variable SECUDIR location. If it doesn't recognize it as a valid command, then check your path environment variable. I had to enter mine without using the SECUDIR variable so it would work - didn't stop to try to understand why.
Best regards,
Ivan
Ivan Mirisola worked like a charm. Many thanks!
I had something similiar. The reason was simple: The database wasn't available from outside the SCP. Check the settings of the database, if it's available from 'everywhere'.
Thank you Majer.
In reference to the XSA Cockpit, are there some specific switches/params/args we could provide the XS CLI to get the configurations we need? I don't have familiarity with the cockpit, nor do I have the access without the assist from administrators, which makes getting this setup a difficult task.
Adam West XS-CLI should have similar possibilities as cloud foundry CLI. The most important part for this configuration are environment variables (default-env.json file).
It is possible to get it using cf CLI, so maybe the same will work for XS:
Hi Michal,
Wonderful blog, Thanks for your efforts,
I was also trying it the same you stated in this blog, but not able to understand in which db folder I have to create the default-env.json file. I am using HANA XSA WebIDE for development.
this is what i have done,
Installed node js in my local computer
set
Installed hana-cli
next i open my command prompt and try to open hana-cli UI interface
for example: hana-cli massconvertui
and i am getting this when ui is opening for mass convert.
"Error: Missing configuration file. No default-env.json or substitute found. Full Details: VError: No service matches hana"
Kindly suggest me some solution.
Hey Ahmed Ali Khan,
Well, it all depends on how Your project is structured. You have to create the default-env.json file on Your own in the main folder module related to HANA DB development. In my example above, my module had 'db' name, in Your case the folder name is probably different.
Best,
Michal