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.

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.

      System screenshot

      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.

      System screenshot

      Note

      In case you see a login window, enter the same user you use to log in to SAP Business Accelerator Hub.System screenshot

      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.

      System screenshot

      A list opens displaying the available services.

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

      System screenshot
    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 the 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 that you created before, for example, RiskManagementService. From the menu that open select Add Service Entity.

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

    4. Make sure thatEnable 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.

      System screenshot

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.

      System screenshot
    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.

      System screenshot
    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 preceding table and choose Create.

      System screenshot

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.

      System screenshot
    4. Enter the values from the preceding table.

  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 preceding table.

      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, log in to SAP Business Accelerator Hub.

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

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

      System screenshot
    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.

      System screenshot
    10. Save your settings.

Result

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

Practice System

Log in to track your progress & complete quizzes