Consuming an External Service From SAP S/4HANA

Objective

After completing this lesson, you will be able to consume an external service from SAP S/4HANA

Consume an External Service from SAP S/4HANA

Business Scenario

In this lesson, you will expand your application with an API, which allows to get data from your SAP S/4HANA back-end system. This enables the application to use data directly from the back-end system.

In this exercise, you will perform the following tasks:

  • Get familiar with the Service Center in SAP Business Application Studio.
  • Add the Business Partner API to the application.
  • Add the Business Partner entity to your application service.
  • Configure an SAP Business Accelerator Hub Destination.

Prerequisites

You have successfully completed the exercise Define Services.

Note

Note, that some of the services that this learning journey links to, can incur costs.

If you are concerned about charges, you can opt to skip the corresponding exercises and watch the simulation instead.

Exercise Options

You can perform this exercise in two ways:

  1. Live Environment / Practice System: you can perform the steps provided below, either in your SAP BTP account or you use the "Practice System Access" provided below.
  2. Simulation: follow the step-by-step instructions within the simulation.

Note

You can try out this exercise in the practice system below. Open the system by choosing the appropriate buttom on the end of this exercise.

Note, that the practice system access only covers access to the SAP Business Application Studio. When deploying to an SAP BTP runtime or consuming other SAP BTP services, you have to use an SAP BTP Trial Account, Free-Tier, or an Enterprise Account.

Note

We recommend performing the steps in the live environment first.

The following simulation reproduces the full exercise execution:

Task 1: Get Familiar With the Service Center in SAP Business Application Studio

Steps

  1. Get familiar with the Service Center.

    1. Navigate to the Storyboard tab of SAP Business Application Studio.

    2. Find the External Resources tile, and choose the + icon to add a new external data model.

      The Service Center opens in a new tab.

    3. On the left side of the window, select Service.

    4. Choose SAP Business Accelerator Hub as Provider, choose SAP S/4HANA Cloud Public Edition as Product, and SAP S/4HANA Cloud Public Edition as Package.

      Note

      In case you see a login window enter the same user you use to login to SAP Business Accelerator Hub.

      Note

      In case the Service Center side panel doesn’t open, select the Service Center icon from the menu on the left side of SAP Business Application Studio.

      A list opens displaying the available services.

    5. Enter Business Partner (A2X) in the search field and select the corresponding service.

    6. Check, that you can get all the information on the selected Business Partner API here, for example:

      • The service entities and properties.
      • The OData protocol version.
      • The service live data coming from the SAP system (in our case from API Hub sandbox).

Task 2: Add the Business Partner API to the Application

Steps

  1. Add a data model.

    1. Choose the Add to Project button in the middle of the screen.

      This screenshot highlights to position of the Add to Project button.

      This imports the service information into your cloud application. Then, you will navigate back to the Storyboard.

    2. Choose the entry corresponding to the namespace you created before, for example, RiskManagementService. From the menu that open select Add Service Entity.

    3. In the service.cds screen, as Projection Type select BusinessPartnerA2X.A_BusinessPartner

    4. Make sure Enable Draft editing is NOT selected.

    5. On the Projection tab in the appeared menu, deselect all properties (use all properties), and then select the following ones:

      • BusinessPartner
      • Customer
      • Supplier
      • BusinessPartnerCategory
      • BusinessPartnerFullName
      • BusinessPartnerIsBlocked
    6. Save your changes.

Task 3: Add the Business Partner Entity to Your Application Service

Steps

  1. Add a relationship.

    Use the following data:

    FieldValue
    TypeAssociation
    Multiplicityto-one
    Namesupplier
    Target EntityBusinessPartnerA2X.A_BusinessPartner

    1. Go back to the Storyboard tab and find the Data Models tile.

    2. Choose the entry Risk Management within the Data Models tile, followed by Open in Graphical Modeler.

    3. Find the entry Risks in the Graphical Modeler. Choose the header of the table.

    4. Choose the Add a relationship icon in the menu on the right.

    5. Drop the line to the Risks entity somewhere on the screen and configure the relationship in the menu on the right side of the screen.

    6. Enter the data from the table above and choose Create.

Task 4: Configure an SAP Business Accelerator Hub Destination

Steps

  1. Add a destination in the SAP BTP Cockpit.

    Before you use the data from the Business Partner API in SAP Business Application Studio, you must first configure a destination for the SAP Business Accelerator Hub.

    Use the following data:

    FieldValue
    Nameapihub_sandbox
    TypeHTTP
    DescriptionSAP Business Accelerator Hub - Sandbox end point
    URLhttps://sandbox.api.sap.com
    Proxy TypeInternet
    AuthenticationNoAuthentication
    1. Go back to your subaccount in the SAP BTP Cockpit. (For more information see: SAP BTP Cockpit)

    2. Navigate to ConnectivityDestinations.

    3. Select Create Destination.

    4. Enter the values from the table above.

  2. Add properties.

    Use the following data:

    FieldValue
    HTML5.DynamicDestinationtrue
    URL.headers.ApiKey(your personal key – see below)
    WebIDEEnabledtrue
    WebIDEUsageodata_gen

    1. Choose the New Property button on the right side.

    2. Except for the entry URL.headers.ApiKey, enter the values from the table above.

      For the property URL.headers.ApiKey you have to enter your unique API key from the SAP Business Accelerator Hub. You will get this in the next substeps.

    3. In your browser, open a new tab.

    4. in this new tab, login to SAP Business Accelerator Hub.

    5. Under your name in the upper right corner, you will find a link to settings.

    6. Under API Settings, choose the Show API key button. Copy the key.

    7. Go back to the other browser tab.

    8. Paste the API.key into the corresponding field.

    9. Make sure that Use default JDK truststore is checked.

    10. Save your settings.

Result

You have integrated an external service API from an SAP S/4HANA system to your application.

Log in to track your progress & complete quizzes