Skip to Content
Technical Articles
Author's profile photo Alessandro Biagi

Extend SAP SuccessFactors on SAP BTP with CAP – Deploy to SAP HANA Cloud

Prerequisites

To follow-up with this blog post you must have read and completed the following previous blog posts in this series:

Setup Project for SAP HANA

So far, all data persistence of our application has been utilizing a default SQLite in-memory database, which means that, each time we restart the application, all data that has been added/updated is completely gone.

It might be OK for local development, but when it goes to a cloud landscape (either development, QA or production) the data must be persisted in a standard relational database such as SAP HANA Cloud (which is going to be the selected database for our application).

Therefore, it’s now time to prepare our project to deploy the data model to SAP HANA Cloud when it goes to BTP. For that, we must add the appropriate dependencies to our project using the cds add command.

1. In the Terminal type cds add hana and press Enter

Figure%201%20-%20Add%20HANA%20dependencies%20to%20project

Figure 1 – Add SAP HANA dependencies to project

2. On the left-hand pane click on the package.json file to open it. Examine the contents and notice the modifications in the dependencies and cds.requires sections and the new cds.hana section. Change the db.kind from the cds.requires section to “hana

Figure%202%20-%20Changes%20made%20to%20package.json

Figure 2 – Changes made to package.json

3. In the Terminal type npm install and press Enter to install the newly added dependency locally

Figure%203%20-%20Install%20new%20dependency

Figure 3 – Install new dependency

Deploy to SAP HANA Cloud

IMPORTANT NOTE: before executing the next steps first make sure:

  1. You are properly logged to Cloud Foundry as instructed in: Jumpstart the CAP Project
  2. Your SAP HANA Cloud database instance (created following this tutorial) is up and running – remember: on trial accounts everything (including SAP HANA database) shuts down overnight!

4. In the Terminal type cds deploy –to hana and press Enter

Figure%204%20-%20Deploying%20to%20the%20HANA%20Cloud%20database

Figure 4 – Deploying to the HANA Cloud database

It’s going to take a while before the command completes as it’s performing these operations:

  1. Build the database artifacts from the CAP project in the gen folder that’s created under the project root folder, for further deployment to SAP HANA.
  2. Create a service instance named sfsf-projman-db of type SAP HANA Schemas & HDI Containers with the hdi-shared plan, that handles the HDI container
  3. Create the SAP HANA database artifacts from the application inside the HDI container
  4. Bind the service instance to the local project by modifying the default-env.json file, adding the database credentials (actually the service key from the service binding).

After the command completes, we will have achieved what we call a “hybrid approach” where your project runs locally, but the database (and the corresponding persistence) runs in the cloud.

Let’s take a quick look at the default-env.json to verify what happened after command completion: on the left-hand pane click on the default-env.json file to open it:

Figure%205%20-%20Changes%20in%20default-env.json

Figure 5 – Changes in default-env.json

Notice that a “hana” section has been added to the VCAP_SERVICES environment variable, with the service instance name of the HDI container and the credentials (service key) to connect to the SAP HANA Cloud database.

IMPORTANT UPDATE: From CDS version 5 and above, this procedure will not modify the default-env.json file. Instead, it will create the .cdsrc-private.json file containing the service bindings. For such CDS versions you’ll need to “re-bind” the Destination and XSUAA service instances to the local project with: cds bind –to sfsf-dest,sfsf-xsuaa. Then, to run the project locally you must use: cds watch –profile hybrid. If, in the future, you switch back to the SQLite in-memory database, then you can stick with the simple cds watch.

If you click on the Cloud Foundry icon (small light bulb) on the left-hand pane and expand the services node, you’ll also see the newly created service instance:

Figure%206%20-%20HDI%20container%20service%20instance

Figure 6 – HDI container service instance

Now, let’s see what happens when we execute the application.

5. In the Terminal type cds watch and press Enter (IMPORTANT: you must use cds watch –profile hybrid when working with CDS version 5 and above as per the update described in the previous step)

Figure%207%20-%20Project%20connected%20to%20SAP%20HANA%20Cloud%20database

Figure 7 – Project connected to SAP HANA Cloud database

Notice that, now, CDS is connecting to SAP HANA Cloud as the persistence mechanism of the application.

Again, in this scenario the project is running locally, but the database is running in the cloud (hybrid approach).

If you want to switch to the SQLite in-memory database again for development, just go back to package.json and change the db.kind parameter in the cds.requires section back to “sql“: and notice that cds watch immediately recognizes the change and switches the connection to sqlite with the “:memory:” credentials:

Figure%208%20-%20Switching%20back%20to%20SQLite%20in-memory

Figure 8 – Switching back to SQLite in-memory

Conclusion

After having gone through the steps of this blog post you should have successfully set up your project to utilize the SAP HANA Cloud database and deployed the application data model to it. Now it’s time to create the SAP Fiori Elements application into your project using the MTA (Multi-Target Application) approach as the final step to prepare the project for deployment.

NOTE: all the instructions provided in this blog post apply exactly the same to any CAP project that should utilize SAP HANA Cloud database as the persistence layer for the application.

Please, do not hesitate to submit your questions in SAP Community through the Q&A tag link: https://answers.sap.com/index.html

Next blog post in this series

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo CHARANRAJ THARIGONDA
      CHARANRAJ THARIGONDA

      Hi Alessandro Biagi,

       

      Thanks for providing a nice blog. I got the below error while connecting to HANA DB in Trail

       

      [hana] - Error: Could not establish connection for tenant "anonymous" due to error: Could not connect to any host: [XXXXXXXX.hana.trial-us10.hanacloud.ondemand.com:443 - certificate has expired ]

       

      Could you please help me?

      Regards

      Charan

      Author's profile photo Alessandro Biagi
      Alessandro Biagi
      Blog Post Author

      Hi Charanraj,

      Could you please specify at which step you are getting the error?

      Thanks,

      Alessandro

      Author's profile photo Baris Topal
      Baris Topal

      Hello Biagi,

      I have a problem. This step; 4. In the Terminal type cds deploy –to hana and press Enter

      This code(cds deploy –to hana) is not completed. Throwing errors at me;

      [deploy] - Deployment ended at 2023-03-31 08:37:27
      
      [deploy] - Error: no service definition found; there must be at least one service definition for the deployment target
      
      [deploy] - (0s 195ms)
      
      
      /home/user/projects/sfsf-projman/node_modules/@sap/cds/bin/deploy/to-hana/hdiDeployUtil.js:142
                          return reject(new Error(message));
                                        ^
      
      Error: HDI deployment failed with exit code 1
          at /home/user/projects/sfsf-projman/node_modules/@sap/cds/bin/deploy/to-hana/hdiDeployUtil.js:142:35
          at ChildProcess.<anonymous> (/home/user/projects/sfsf-projman/gen/db/node_modules/@sap/hdi-deploy/library.js:102:14)
          at ChildProcess.emit (node:events:513:28)
          at maybeClose (node:internal/child_process:1100:16)
          at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5)

      I created Hana db and db is running.

       

      My Package.json;

      Why am I getting errors. Can you help me?

      Best Regards,
      Baris

      Author's profile photo Alessandro Biagi
      Alessandro Biagi
      Blog Post Author

      Hi Baris Topal,

      I've been recently in contact with CAP's product development team regarding this problem and found that between versions > 6.2.2 and < 7 (which has not been released yet), a bug has been introduced in the cds cli where, if there's a default-env.json present in your project folder (which is the approach used in this blog series), the tool does not recognize the CAP service definition,

      The team promised to solve it in version 7.

      Meanwhile, two workaround can be tried to move forward with the deployment to HANA:

      1. Rename default-env.json to default-env.old and run the command. After successful completion rename it back to default-env.json.

      2. Downgrade the cds cli version to 6.2.2 (modify your package.json to "@sap/cds" : "6.2.2" and run npm install), then run the command. After successful completion upgrade to the latest version again (modify your package.json to "@sap/cds" : "6.7.0" and run npm install).

      I tested both approaches and they work fine for me.

      Best Regards,

      Alessandro

      Author's profile photo Baris Topal
      Baris Topal

      Hi Alessandro Biagi,

      Thanks for feedback. I tried and solved.

      Best Regards,
      Baris.