Skip to Content

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

test
0 %
Add Services and Consume an External Service from SAP S/4HANA
Details

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

Requires Customer/Partner License
January 18, 2022
Created by
December 7, 2021
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
QR code

Prerequisites

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


Step 1: Add the Connectivity service

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:

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.

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 on to answer question

Step 2: Bind the Connectivity and Destination services to your CAP service

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

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, we will create a Destination and a Destination Service.

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

Step 3: Create a Destination in the SAP BTP cockpit
  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 Create a technical user)
    Password Welcome1 (as defined in Create a technical user)

    Replace {Virtual host} and {Virtual port} in the URL with the values you defined in Add system mapping.

    Configure Settings
  7. Choose Save.

Log on to answer question

Step 4: Set Destination

To set the 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"
            }
        }
Log on to answer question

Step 5: 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 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 6: Test your CAP application with SAP S/4HANA connectivity

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 steps 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 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. 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.

Give us 55 seconds of your time to help us improve

Log on to answer question

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


Next Steps

Back to top