Skip to Content

Deploy a CAP Business Application to SAP Business Technology Platform

test
0 %
Deploy a CAP Business Application to SAP Business Technology Platform
Details

Deploy a CAP Business Application to SAP Business Technology Platform

July 19, 2021
Created by
November 18, 2019
This tutorial shows you how to deploy your SAP Cloud Application Programming Model (CAP) application to SAP Business Technology Platform, Cloud Foundry environment using SAP HANA Cloud Service.

You will learn

  • How to deploy your business service on SAP Business Technology Platform (SAP BTP) using the SAP Cloud Application Programming Model (CAP) and binding appropriate service instances. See the Developer Guide for Cloud Foundry for more details.
QR code

Prerequisites


Step 1: Enhance project configuration for SAP HANA

It’s now time to switch to SAP HANA as a database. To continue with this tutorial you need to Set Up the SAP HANA Cloud Service or Use an Existing SAP HANA Cloud Service Instance to deploy your application.

Your SAP HANA Cloud instance will be automatically stopped overnight, according to the server region time zone. That means you need to restart your instance every day, before you start working with your trial.

  1. If cds watch is still running in VS Code, choose CTRL+C in the command line to stop the service.

  2. To prepare the project, execute in the root level of your project in VS Code:

    cds add hana
    

    This configures deployment for SAP HANA to use the hdbtable and hdbview formats. The previous command added the @sap/hana-client driver for SAP HANA as a dependency in package.json. Note that in the future, this might change to hdb, which is a leaner driver. See section SAP Support for hdb and @sap/hana-client for a feature comparison.

    A data source of type sql is added in the cds.requires.db block. See section Node.js configuration in the CAP documentation for more details.

  3. (Optional) To enable SAP Fiori preview add the following configuration in the package.json of your my-bookshop project in VS Code:

    "cds": {
      "features": {
        "fiori_preview": true
      },
    }
    

    fiori_preview:true enables SAP Fiori preview also in production mode as you saw it in your local application in the previous tutorial in step 4 when using cds watch. This feature is meant to help you during development and should not be used in productive applications.

    Don’t edit the gen/db/package.json file.

Log on to answer question
Step 2: Identify SAP BTP Cloud Foundry endpoint

The Cloud Foundry API endpoint is required so that you can log on to your SAP BTP Cloud Foundry space through Cloud Foundry CLI.

  1. Go to the SAP BTP Trial Cockpit and choose Go To Your Trial Account.

    business technology platform cockpit view
  2. From the Subaccounts overview navigate to your subaccount.

    subaccount tile
  3. From your subaccount copy the Cloud Foundry API Endpoint value.

    CF API endpoint value
  4. Go back to Visual Studio Code to the command line. Authenticate with your login credentials using the following command:

    cf login
    

    This will ask you to select Cloud Foundry API, org, and space.

    The API Endpoint is taken by default. If you want to change the API Endpoint use cf api <CF_API_ENDPOINT> to change the API. Replace <CF_API_ENDPOINT> with the actual value you obtained in the previous step.

    If you don’t know whether you’re logged on to Cloud Foundry or if you’re wondering to which Cloud Foundry org and space are you logged on, you can always use cf target in a terminal to find out.

Log on to answer question
Step 3: Deploy using cf push

SAP BTP, Cloud Foundry environment has a built-in cf push command to deploy applications. It needs the application files plus an optional manifest.yml file to push the application code and to bind the relevant services to the application.

  1. As cf push can only bind but not create services, you need to create the SAP HANA service manually (along with an HDI container and a database schema). In the command line add:

    cf create-service hana hdi-shared my-bookshop-db
    

    This process takes some minutes.

    Check the status of your service using cf service my-bookshop-db.

    If service creation fails, see the Troubleshooting guide in the CAP documentation for more details.

  2. Now, build and deploy both the database part and the actual application and add:

    cds build --production
    cf push -f gen/db
    cf push -f gen/srv --random-route
    

    This process takes some minutes.

    The first part of the command creates the SAP HANA table and view definitions along with manifest.yaml files in both in gen/db and gen/srv folders. Look at gen/db/manifest.yaml and see that it binds to the my-bookshop-db service that you’ve created in the previous step.

  3. In the deploy log, find the application URL in the routes line at the end:

    name:              my-bookshop-srv
    requested state:   started
    routes:            my-bookshop-srv-....cfapps.....hana.ondemand.com
    
  4. Open this URL in the browser and try out the provided links, for example, .../catalog/Books. Application data is fetched from SAP HANA. If enabled in step 1.3 you can also try the Fiori preview.

    application preview
  1. As cf push can only bind but not create services, you need to create the SAP HANA service manually (along with an HDI container and a database schema). In the command line add:

    cf create-service hana hdi-shared my-bookshop-db
    

    This process takes some minutes.

    Check the status of your service using cf service my-bookshop-db.

    If service creation fails, see the Troubleshooting guide in the CAP documentation for more details.

  2. Now, build and deploy both the database part and the actual application and add:

    cds build --production && cf push -f gen/db && cf push -f gen/srv --random-route
    

    This process takes some minutes.

    The first part of the command creates the SAP HANA table and view definitions along with manifest.yaml files in both in gen/db and gen/srv folders. Look at gen/db/manifest.yaml and see that it binds to the my-bookshop-db service that you’ve created in the previous step.

  3. In the deploy log, find the application URL in the routes line at the end:

    name:              my-bookshop-srv
    requested state:   started
    routes:            my-bookshop-srv-....cfapps.....hana.ondemand.com
    
  4. Open this URL in your browser and try out the provided links, for example, .../catalog/Books. Application data is fetched from SAP HANA. If enabled in step 1.3 you can also try the Fiori preview.

    application preview
Which categories can you see in your browser?
×

Give us 55 seconds of your time to help us improve

Next Steps

Back to top