Skip to Content

Add Services and Consume an External Service from SAP S/4HANA

Requires Customer/Partner License
This tutorial shows you how to prepare and deploy your CAP application and test it with SAP S/4HANA 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 connectivity
manjuXManju ShankarDecember 6, 2022
  • Step 1

    In this tutorial, you do the final steps to use the external service in the CAP application on SAP BTP. You create an on-premise destination with your technical user’s name and password. By binding the Connectivity and the Destination services to your CAP service, it can access the service using the destination.

    Add the following lines to your mta.yaml file:

    YAML
    Copy
    resources:
       ...
     - name: cpapp-connectivity
       type: org.cloudfoundry.managed-service
       parameters:
         service: connectivity
         service-plan: lite
    

    The Destination service is already added to the mta.yaml. If you look at the resources that already exist in the mta.yaml, you’ll see that the Destination service is already there, so you don’t have to add it yourself.

    YAML
    Copy
    resources:
        ...
      - name: cpapp-destination
      type: org.cloudfoundry.managed-service
      parameters:
        config:
          HTML5Runtime_enabled: true
          init_data:
            instance:
              destinations:
              - Authentication: NoAuthentication
                Name: ui5
                ProxyType: Internet
                Type: HTTP
                URL: https://ui5.sap.com
              existing_destinations_policy: update
          version: 1.0.0
        service: destination
        service-plan: lite
    
    Log in to complete tutorial
  • Step 2

    Add the following lines to the cpapp-srv module in your mta.yaml file:

    YAML
    Copy
    modules:
       ...
     - name: cpapp-srv
     # ------------------------------------------------------------
       type: nodejs
       path: gen/srv
       requires:
        # Resources extracted from CAP configuration
        - name: cpapp-db
        - name: cpapp-uaa
        - name: cpapp-logs
        - name: cpapp-connectivity
        - name: cpapp-destination
       provides:
        - name: srv-api      # required by consumers of CAP services (e.g. approuter)
          properties:
            srv-url: ${default-url}
     # -------------------- SIDECAR MODULE ------------------------
    

    The Destination service lets you find the destination information that is required to access a remote service or system from your Cloud Foundry application.
    To consume the external service from our cloud deployed application, you will create a Destination and a Destination Service.

    How can you bind the Connectivity service to your CAP service?

    Log in to complete tutorial
  • Step 3
    1. Enter your Global Account. If you are using a trial account, choose Go To Your Trial Account.

    2. Choose Account Explorer.

    3. Choose your subaccount in the Subaccounts tab.

    4. Choose ConnectivityDestinations.

      Destinations
    5. Choose New Destination.

      New Destination
    6. Configure the following settings:

      Property Value
      Name cpapp-bupa
      Type HTTP
      URL http://{Virtual host}:{Virtual port}
      Proxy Type On Premise
      Authentication BasicAuthentication
      User CPAPP (as defined in Step 3: Create a technical user from this tutorial)
      Password Welcome1 (as defined in Step 3: Create a technical user from this tutorial)

      Replace {Virtual host} and {Virtual port} in the URL with the values that you defined in Step 3: Add system mapping from this tutorial.

      Configure Settings
    7. Choose Save.

    Log in to complete tutorial
  • Step 4

    To set the destination for API_BUSINESS_PARTNER service, add the following lines for productive profile to your package.json file:

    JSON
    Copy
        "API_BUSINESS_PARTNER": {
            ...
            "[sandbox]": {
            ...
            },
            "[production]": {
                "credentials": {
                    "path": "/sap/opu/odata/sap/API_BUSINESS_PARTNER",
                    "destination": "cpapp-bupa"
                }
            }
    
    Log in to complete tutorial
  • Step 5

    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 Multi-Target Application (MTA).

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

      Shell/Bash
      Copy
      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:

      Shell/Bash
      Copy
      cf deploy cpapp_1.0.0.mtar
      
    Log in to complete tutorial
  • Step 6

    When creating new entries in the Risks application, you should be able to use the value help for Supplier to see all the values from the remote SAP S/4HANA system.

    Don’t forget to perform the steps from the tutorial Subscribe to 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 Subscribe to 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 Step 6 Exclude CSV files from deployment of Deploy Your Multi-Target Application (MTA), 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. Open the value help for the Supplier field.

      Risk Object Page
    6. You should see a list of suppliers.

      RiskTitle

    Congratulations! You have completed all tutorials.

    The result of this tutorial can be found in the ext-service-s4hana-consume branch.

    Log in to complete tutorial
Back to top