Skip to Content

Use Your SAP S/4HANA Cloud Service for Your Deployed CAP Application

test
0 %
Use Your SAP S/4HANA Cloud Service for Your Deployed CAP Application
Details

Use Your SAP S/4HANA Cloud Service for Your Deployed CAP Application

Requires Customer/Partner License
October 15, 2021
Created by
October 3, 2021
This tutorial shows you how to prepare your application, deploy it as Multi-Target Application (MTA) and test it with SAP S/4HANA Cloud connectivity.

You will learn

  • How to prepare your CAP application
  • How to deploy your CAP application
  • How to test your CAP application with SAP S/4HANA Cloud connectivity
QR code

Prerequisites

To start with this tutorial use the result in the ext-service-ui branch.


Step 1: Prepare your CAP application

To connect to the SAP S/4HANA Cloud system, you create a service instance for the SAP S/4HANA Cloud Extensibility service with plan api-access. The SAP S/4HANA system provides pre-defined communication scenarios that contain one or multiple APIs. When creating the service instance, the communication scenario needs to be specified along with some configuration. Under the hood, a communication arrangement based on the given scenario is created in the SAP S/4HANA Cloud system.

  1. Go back to the SAP API Business Hub page for the Business Partner (A2X) API that you use: Business Partner (A2X).

  2. Check the list of Communication Scenarios.

    You can see four different Communication Scenarios that expose the Business Partner (A2X) API. You can check the details of those scenarios in the SAP S/4HANA Cloud system.

    In this tutorial, you use the scenario SAP_COM_0008.

    Further information about how to configure communication scenarios

  3. Copy the file templates/ext-service-s4hc-use-service/bupa-service-config.json with the communication scenario configuration into your app folder:

    bupa-service-config.json:

    {
        "systemName": "<set in mta.yaml>",
        "communicationArrangement": {
            "communicationArrangementName": "CPAPP_COM_0008",
            "scenarioId": "SAP_COM_0008",
            "inboundAuthentication": "BasicAuthentication",
            "outboundAuthentication": "BasicAuthentication",
            "outboundServices": [
                ...
            ]
        }
    }
    

    The configuration for the communication arrangement contains the name under which your SAP S/4HANA Cloud system (systemName) was registered, the used scenario, the name for the to be created communication arrangement and some specific configuration.

    The systemName is left out here, because it will be set in the mta.yaml file, which will allow you to oversteer it for a deployment in a productive environment.

    The communicationArrangementName is the name for this arrangement that is created in the S/4HANA Cloud system. It needs to be unique within the system.

    By setting inboundAuthentication to BasicAuthentication, a technical user and a password is automatically created with the permissions defined in the communication scenario.

    Some communication scenarios support outbound communication. The scenario SAP_COM_0008 has some outbound configuration. Although you don’t want to use it, you need to give some configuration to switch it off. Otherwise, the service instance creation will fail.

  4. Add the SAP S/4HANA Cloud Extensibility service to your mta.yaml file by adding the following lines to the resources section:

    _schema-version: '3.1'
    
    resources:
    ...
    - name: cpapp-bupa
      type: org.cloudfoundry.managed-service
      parameters:
        skip-service-updates:
            plan: true
            parameters: true
            tags: true
        service: s4-hana-cloud
        service-plan: api-access
        system-name: CPAPP_S4HANA_CLOUD
        path: ./bupa-service-config.json
        config:
            systemName: CPAPP_S4HANA_CLOUD
    ...
    

    The system name, that is specified two times here, is the name you gave when creating the system in the SAP BTP cockpit.

    The service doesn’t support updates, to avoid errors in subsequent deployments the skip-service-updates option is activated. This means if you want to change the service settings, that you need to delete and newly create the service instance manually.

    Alternatively, you can create the service instance in the SAP BTP cockpit. This would be the better choice if you want to share the instance between different applications. When doing it in SAP BTP cockpit, you don’t need to add the previous mentioned lines to the mta.yaml file.

  5. The SAP S/4HANA Cloud Extensibility service creates a destination with the same name as the service instance. To set destination for API_BUSINESS_PARTNER service add the following lines for productive profile to your package.json file:

        "API_BUSINESS_PARTNER": {
            ...
            "[sandbox]": {
            ...
            },
            "[production]": {
                "credentials": {
                    "path": "/sap/opu/odata/sap/API_BUSINESS_PARTNER",
                    "destination": "cpapp-bupa"
            }
        }
    

    The path property is important as well, because the destination contains only the URL of the system.

    You can find the path on the Business Partner (A2X) page in the SAP API Business Hub. Choose Configuration Details and take note of the sandbox URL.

    For example:
    https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_AddressEmailAddress

    The path is the part between https://sandbox.api.sap.com/s4hanacloud and the last path segment (A_AddressEmailAddress here).

  6. Add the Destination service to your CAP service by adding the requires section for the cpapp-srv module in mta.yaml file:

    modules:
    - name: cpapp-srv
      ...
      requires:
      ...
      - name: cpapp-destination
    

    The CAP server needs the destination service to access the CPAPP_S4HANA_CLOUD destination and get the required credentials to call the SAP S/4HANA Cloud system.

Additional Documentation:

CAP documentation about Consuming Services

Log on to answer question

Step 2: Deploy your CAP application

If you use the SAP Continuous Integration and Delivery (CI/CD) service on SAP Business Technology Platform, you just need to push the commit to your main branch and wait for the deployment to be completed.

Otherwise, deploy your application as described in the tutorial Multi-Target Application (MTA).

  1. Build the MTA module from your project root folder:

    mbt build -t ./
    

    This creates a mtar file cpapp_1.0.0.mtar in the current folder (option: -t ./).

    In case you get the error On Windows, this driver only supports the x64 architecture. You node process is: ia32, check if you have installed the right version of Node.js for your operating system.

  2. Deploy the module to your current Cloud Foundry space:

    cf deploy cpapp_1.0.0.mtar
    
Log on to answer question

Step 3: Test your CAP application with SAP S/4HANA Cloud connectivity

You need to perform step 16-18 from the tutorial Add the SAP Launchpad service before you continue with this step to be able to create entries in the Risks application.

  1. Open your SAP BTP Launchpad Service site as described in the tutorial Add the SAP Launchpad Service.

  2. Choose the Risks application.

  3. Choose Go.

    You’ll see a message No data found. Try adjusting filter or search criteria.

    Why there’s no data in the Risks application?

    As explained in section Exclude CSV files from deployment, test files should never be deployed to an SAP HANA database as table data. For this reason, there’s no test files in the deployment archive.

  4. Choose Create.

    Create Risk
  5. Fill in information for the new risk in the object page and choose Create.

    Risk Object Page

    You can leave the Mitigation field empty, since there’s no available mitigations to choose from.

  6. Check if the new risk is visible.

    RiskTitle
Log on to answer question

Step 4: Summary

Congratulations! You have completed all tutorials.

What command was used to deploy Multi-Target Applications (MTA) to Cloud Foundry?
×

Give us 55 seconds of your time to help us improve

The result of this tutorial can be found in the ext-service-s4hc-use branch.


Next Steps

Back to top