cancel
Showing results for 
Search instead for 
Did you mean: 

Configure an SAP CAP Application to Connect to an SAP HANA Cloud Database in Another Global Account

73

How to Configure an SAP CAP Application to Connect to an SAP HANA Cloud Database in Another Global Account or Subaccount Without HDI

When your SAP HANA Cloud database is in another Global Account or subaccount, which prevents the natural use of the HDI container for database object management, you need to follow the steps below to configure your SAP CAP application and achieve a successful connection.

Step 1: Configure a User-Provided Service

It is essential to create a user-provided service using the Cloud Foundry command line. This is important because SAP CAP requires the service to have three specific tags to automatically determine which configuration to use.

Run the following command:

cf create-user-provided-service ups-database-external -t "hana,database,relational"
  • ups-database-external: This is the name you assign to your service.
  • -t "hana,database,relational": These are the tags that CAP uses to identify the database service.

Step 2: Modify the Service's JSON in SAP BTP

After creating the service via the command line, you need to specify the connection data in the service's JSON in SAP BTP.

The JSON should contain the following:

{
  "encrypt": true,
  "host": "your-hana-cloud-host",
  "password": "your-password",
  "port": "443",
  "schema": "YOUR_SCHEMA_NAME",
  "sslValidateCertificate": true,
  "user": "your-username"
}
  • host: The address of your SAP HANA Cloud instance.
  • user and password: The credentials of the user with permissions to access the database schema.
  • schema: The schema where your database objects are located or will be created.
  • encrypt and sslValidateCertificate: Settings to ensure the connection is secure via SSL/TLS.
  • port: The connection port, generally "443" for secure connections.

Step 3: Modify package.json or .cdsrc.json

You need to tell SAP CAP which service to use to obtain the credentials. This is done by modifying your project's package.json or .cdsrc.json file.

Add or update the "requires" section as follows:

{
  "requires": {
    "db": {
      "kind": "hana",
      "credentials": {
        "service": "ups-database-external"
      }
    },
    "[production]": {
      "auth": "xsuaa",
      "db": {
        "kind": "hana",
        "credentials": {
          "service": "ups-database-external"
        }
      },
      "data": false
    }
  }
}
  • "service": "ups-database-external": Indicates to CAP that it should use the provided service named ups-database-external.
  • "[production]": Ensures that the same configuration is used in the production profile.

Step 4: Remove HDI-Related Configurations

Since you are not using HDI for database object management, you need to remove all references and configurations related to HDI in your mta.yaml file or your project's deployment configurations.

This includes:

  • Removing modules or resources that create or manage HDI containers.
  • Deleting dependencies between modules and HDI resources.

Step 5: Bind the Service to the CAP Application Instance in SAP BTP

For your CAP application to take the specified credentials and configuration, you need to bind the provided service to your application's instance in SAP BTP.

You can do this in two ways:

Option 1: Manual Binding

After deploying the application, run the command:

cf bind-service your-application-name ubs-database-external

Then, restart your application:

cf restart your-application-name

Option 2: Automatic Binding in mta.yaml

Add the binding in your mta.yaml file so that it is performed automatically during deployment.

Example of how to define the binding in mta.yaml:

modules:
  - name: your-application-name
    type: nodejs
    path: .
    requires:
      - name: ups-database-external
resources:
  - name: ups-database-external
    type: org.cloudfoundry.managed-service
    parameters:
      service: user-provided
      service-name: ups-database-external

Step 6: Manually Deploy the Database Objects

Since you are not using HDI, you need to manually deploy the database objects in your SAP HANA Cloud instance.

1. Generate the SQL Scripts

From your CDS models, generate the SQL scripts using the following commands:

cds compile db/ --to sql --src db cds compile srv/ --to sql --src srv

These commands generate SQL scripts from your model definitions in the db/ and srv/ directories.

2. Execute the Scripts in the Database Console

  • Access SAP HANA Database Explorer.
  • Connect to your SAP HANA Cloud instance.
  • Execute the generated SQL scripts to create the necessary tables and views in your schema.

Accepted Solutions (0)

Answers (0)