Spend Management Blogs by SAP
Stay current on SAP Ariba for direct and indirect spend, SAP Fieldglass for workforce management, and SAP Concur for travel and expense with blog posts by SAP.
cancel
Showing results for 
Search instead for 
Did you mean: 
ajmaradiaga
Developer Advocate
Developer Advocate
3,792

In this exercise, we will cover how we can move SAP Ariba data to an on-premise service by using SAP Cloud Platform Integration (CPI) and SAP Cloud Connector (SCC). SAP Cloud Connector will be used to achieve a connection from CPI to the on-premise service. The on-premise service will be hosted in our local machine, which means that we will be installing SCC in our local machine, configuring the connection between SCC and SAP Cloud Platform (SCP) locally, and granting access to the on-premise service from the local SCC.


To complete the steps explained in this exercise, there are some prerequisites that we will need to complete first:




On-premise service


The on-premise service that the integration will be communicating with is a simple Cloud Application Programming (CAP) model application hosted locally. It exposes a mock service to which we can post the SourcingProjectSourcingSystemView data extracted from the SAP Ariba Analytical reporting API.














On-premise service schema


The code of the on-premise service will be released shortly. Stay tuned.



Now that we have access to the different systems and we've installed the required software, we will proceed to explain how to get SAP Cloud Platform Integration talking with SAP Ariba and the on-premise service.



Step 1 - Configure SAP Cloud Connector locally


Configure the required components in SAP Cloud Connector locally.


Once SCC is installed locally and running, go to http://localhost:8443 to configure the connection to SAP Cloud Platform. The default login details are:




  • User Name: Administrator

  • Password: manage


Once in the Cloud Connector UI, we need to set up the secure tunnel between our on-premise system (our local machine) and SAP Cloud Platform (Cloud Foundry environment).




The steps describe below are based on the Set up Secure Tunnel between ABAP System and SAP Cloud Platform (CF) tutorial - https://developers.sap.com/tutorials/cp-connectivity-create-secure-tunnel.html.




  1. Go to the SAP Cloud Platform trial and check the details of your trial subaccount. Copy the ID as we will be using this for our configuration in SCC.











    Subaccount ID in SCP


  2. In SCC, click on the Add Subaccount button and fill the fields in the form:











    Create Subaccount


  3. Once configured the subaccount, proceed to create the Cloud to On-Premise connection. Here you define the name of the virtual host and map it to the internal host. After mapping the virtual to internal system, define the resource that you want to expose. In the case of the on-premise service, we want the cloud to be able to send message to anything under the /mock/ URL path.











    Cloud to on-premise connection



Our SCC instance is fully configured, we can now proceed to creating the SAP CPI integration flow.



Step 2 – Create and set up integration flow in SAP Cloud Platform Integration













Integration flow

Create an integration flow in SAP Cloud Platform Integration following the guidelines below.


Given that it is possible to receive large amounts of data from the SAP Ariba Analytical Reporting APIs, there might be a need to paginate the response. This is taken in consideration in the integration flow, hence why there is a looping process in it.




To understand how pagination works in the SAP Ariba APIs, check out the explanation in topics/apis/data-pagination.



We can use externalized parameters below to ensure that the integration flow is reusable.














Externalized parameters

Integration Process


The integration flow includes an integration process that can start on a schedule and a looping process call to handle the SAP Ariba response pagination. The loop will stop when the header pageToken value is STOP. This is handled by the script responsible of processing the SAP Ariba API response.














Looping process conditions

Retrieve Analytical Reporting data from SAP Ariba (Local integration process) This local integration process retrieves the analytical data from SAP Ariba and sending it to an on-premise service. In this exercise we will be extracting data from the SourcingProjectSourcingSystemView view template. Below, the details on what each block in the process is doing:





  • Set Ariba dateFilter parameter (JS script): Specify the date filter expected when calling the view template. The dateFilter included in the script below has been hardcoded for simplicity purposes. In a production scenario this can be dynamically set based on your reporting needs and how often the integration flow will run.



    importClass(com.sap.gateway.ip.core.customdev.util.Message);
    importClass(java.util.HashMap);

    function processData(message) {

    // Set the value for filters query parameter
    message.setHeader("dateFilter", '{"createdDateFrom":"2019-07-01T00:00:00Z","createdDateTo":"2020-06-05T00:00:00Z"}');

    return message;
    }​



  • Ariba API Key header: Creates the ‘apiKey’ header which is required when calling the SAP Ariba APIs. It sets the value specified for the {{Ariba_APIKey}} external parameter.




  • GET analytical reporting data (HTTP to SAP Ariba)




  • Process SAP Ariba response (JS script): This script checks for the PageToken value in the API response and handles its value. This will be used to indicate if the looping process should continue or finish. It also prepares the JSON payload that the on-premise service expects. The contents of the file expects a JSON structure per line and every line will be the equivalent of a record in the on-premise service.



    importClass(com.sap.gateway.ip.core.customdev.util.Message);
    importClass(java.util.HashMap);

    function processData(message) {
    var messageLog = messageLogFactory.getMessageLog(message)

    //Parsing body to JSON
    var body = JSON.parse(message.getBody(new java.lang.String().getClass()));

    /* ===========
    Handle PageToken
    =============*/

    // Retrieving PageToken from payload if one exists
    if("PageToken" in body) {
    messageLog.setStringProperty("PageToken", body['PageToken']);
    message.setHeader("pageToken", body["PageToken"]);
    } else {
    messageLog.setStringProperty("PageToken", "NONE!");
    message.setHeader("pageToken", "STOP");
    }

    /* ===========
    Create payload
    =============*/

    var fileContents = "";

    var i = 0;
    var arr = body['Records'];

    for(var x = 0; x < arr.length; x++) {
    var record = arr[x];

    messageLog.setStringProperty("record", record);
    i += 1;

    // Create JSON line document
    fileContents += '{"ID": "' + record['InternalId'] + '","Title": "' + record['Title'] + '",';
    fileContents += '"Status": "' + record['Status'] + '","ParentDocumentId": "' + record['ParentDocument']['InternalId'] + '",';
    fileContents += '"ExternalSystemCorrelationId": "' + record['ExternalSystemCorrelationId'] + '",';
    fileContents += '"OwnerEmail": "' + record['Owner']['EmailAddress'] + '"}\n';
    }

    messageLog.setStringProperty("Payload", fileContents);
    messageLog.setStringProperty("TotalRecordsProcessed", i);

    message.setBody(fileContents);

    return message;
    }​



  • General Splitter: The expression type is Line Break and its purpose is to process each JSON payload separately.



    {"ID": "WS1858855273","Title": "QP 8D","Status": "Active","ParentDocumentId": "SYS0003","ExternalSystemCorrelationId": "","OwnerEmail": "aribacustomersupportadmin@sap.com"}



  • Set first line as body (JS script): The splitter will output a body like the one above. The script will just set the JSON payload, 2nd line, as the body.



    importClass(com.sap.gateway.ip.core.customdev.util.Message);
    importClass(java.util.HashMap);
    function processData(message) {
    var messageLog = messageLogFactory.getMessageLog(message)

    //body
    var body = message.getBody(new java.lang.String().getClass());
    var lines = body.split("\n");

    var jsonRequest = lines[1];

    messageLog.setStringProperty("JSONPayload", jsonRequest);

    message.setBody(jsonRequest);

    return message;
    }​



  • POST on-prem (HTTP to On-premise service): The address field value is set from the {{CloudConnector_OnPremise_URL}} external parameter. Note the proxy type in the














    On-premise HTTP adapter configuration



Now that all steps are completed, we deploy the integration flow and check the records are created in the on-premise service.














On-premise data

As we can see, we have replicated the SAP Ariba data to our on-premise service. We were able to communicate from SAP Cloud Platform to our on-premise service securely by usi

1 Comment