Contact Free trial Login

SAP S4 HANA Cloud Connector - Mule 4

Support Category: Premium

SAP S/4HANA Cloud Connector v1.1

The Anypoint Connector for SAP S/4HANA Cloud provides full support for the query, get, create, update, delete entities, and execute functions using the ODATA API exposed by SAP S/4HANA.

This connector lets you perform operations to:

  • Create, update, and delete entities.

  • Retrieve a single entity or query multiple entities.

  • Invoke a remote function.

Get Started

This document assumes that you are familiar with S/4HANA, Mule, Anypoint Connectors, and the Anypoint Studio essentials.

To use this connector you need the following:

  • A developer account or other valid SAP S/4HANA instance.

  • A MuleSoft Enterprise License.

For software requirements and compatibility information, see the SAP S4/HANA Connector Release Notes.

To use this connector with Maven, view the pom.xml dependency information in the Dependency Snippets in Anypoint Exchange.

Supported Operations

The SAP S/4HANA Cloud Connector supports the following outbound operations:

Design Center Configuration

In Design Center, click a trigger such as HTTP Listener or Scheduler. The SAP S/4HANA connector cannot be used as a trigger.

sap hana trigger

To create an HTTP global element for the connector:

  1. Select the plus sign to add a component.

  2. Select the HTTP Listener connector as a component.

  3. Configure these HTTP Listener fields:

    sap hana http listener
    Studio Field Description

    Protocol

    Protocol selected for the HTTP endpoint. This can be HTTP or HTTPS.

    Host

    IP address on which your Mule app listens for requests.

    Port

    Port address on which your Mule app listens for requests.

    Base Path

    Path on which your Mule app listens for requests.

  4. Select the plus sign to add a component.

    sap hana plus
  5. Select the connector as a component.

  6. Select the desired operation.

  7. Configure the global element for the connector.

    Basic Connection:

    sap hana conf
    Studio Field

    Description

    Service Base URL

    Enter the URL of the SAP S/4HANA instance you want to manage.

    Username

    User name used to initialize the session.

    Password

    Password used to authenticate the user.

Studio Configuration

You can use this connector in Anypoint Studio by first downloading it from Exchange and configuring it as needed.

Install the Connector in Studio

  1. In Anypoint Studio, click the Exchange icon in the Studio taskbar.

  2. In Anypoint Exchange, click Login.

  3. Search for this connector and click Add to project.

  4. Follow the prompts to install this connector.

Alternatively you can install the connector from your pom.xml file:

<dependency>
    <groupId>com.mulesoft.connectors</groupId>
    <artifactId>mule-sap-s4hana-cloud-connector</artifactId>
    <version>RELEASE</version>
    <classifier>mule-plugin</classifier>
</dependency>

Mule runtime engine translates the RELEASE keyword to the current version.

To obtain the most up-to-date pom.xml file information, access the connector in Anypoint Exchange and click Dependency Snippets.

Configure a Global Element

To use the SAP S/4HANA Cloud connector in a Mule application, you can configure a global SAP S/4HANA configuration element for use by SAP S/4HANA connector operations in your application.

  1. Click the Global Elements tab at the base of the canvas.

  2. In the Global Configuration Elements screen, click Create.

    sap hana global config wizard
  3. In the Choose Global Type wizard, expand Connector Configuration, select SAP S/4HANA Config, and click OK.

    The following configuration screen for Basic Connection appears.

    sap hana conf
  4. Configure the following content:

    General tab:

    Studio Field Description

    Service base URL

    Base URL of the service on SAP S/4HANA to be accessed from the connector.

    Username

    User name to connect.

    Password

    Password to connect.

    Advanced tab:

    Studio Field Description

    Service discovery relative path

    Relative path from the base URL to the service used for automatic services discovery.

    Unlisted services

    List of services to add to the list of discovered services.

    Default headers

    Custom headers that can be included in each request sent.

    Default query parameter

    Custom query parameters to include in each request sent.

    TLS configuration

    TLS configuration.

    Proxy configuration

    Configuration for executing requests through a proxy.

  5. Click OK to save the global connector configuration.

Notes:

  • In the previous Basic configuration screens, the placeholder values refer to the mule-artifact.content configuration file in the src/main/resources folder of your project.

  • You can either enter your credentials in the global configuration content, or reference a configuration file that contains these values.

  • For simpler maintenance and better reuse of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where access credentials may differ.

Set Up and Run in Studio

  1. In Anypoint Studio, click File > New > Mule Project.

  2. Specify a project name and click Finish.

  3. Search for HTTP and drag the Listener operation to the canvas. Click the green plus sign next to Connector Configuration, and click OK in the menu to accept the default values.

  4. Drag an SAP S/4HANA Cloud connector operation to the canvas. Click the green plus next to Connector Configuration, and specify your access credentials.

  5. Click the Basic Connection connection strategy for authentication.

  6. Click Test Connection to ensure that your access credentials work.

Run a Flow in Studio

  1. In Package Explorer, right click your project’s name, and click Run As > Mule Application.

  2. Check the console to see when the application starts. You should see messages such as these if an error does not occur:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Mule is up and kicking (every 5000ms)                                        +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2019-06-25 09:19:47,381 [WrapperListener_start_runner] org.eclipse.jetty.server.AbstractConnector: Started ServerConnector@795dbf6c{HTTP/1.1,[http/1.1]}{0.0.0.0:51966}
INFO  2019-06-25 09:19:47,383 [WrapperListener_start_runner] org.mule.runtime.core.internal.logging.LogUtil:
**********************************************************************
*              - - + DOMAIN + - -               * - - + STATUS + - - *
**********************************************************************
* default                                       * DEPLOYED           *
**********************************************************************

*******************************************************************************************************
*            - - + APPLICATION + - -            *       - - + DOMAIN + - -       * - - + STATUS + - - *
*******************************************************************************************************
* saphana-entity-crud-demo                      * default                        * DEPLOYED           *

XML and Maven Support

If you manually code a Mule application in XML from the Studio XML editor or a text editor, perform the following actions to get access to the connector:

  • Add the namespace for the connector to your XML flow.

  • Add dependency information to your Maven pom.xml file.

Alternatively in the Studio visual editor, when you drag a connector from the palette to the canvas, Studio automatically populates the XML code with the connector namespace and schema location.

Add a Namespace for the Connector

If you manually code the Mule application in the Studio XML editor or another text editor, paste the following code inside the <mule> tag in your XML configuration:

http://www.mulesoft.org/schema/mule/s4hana
http://www.mulesoft.org/schema/mule/s4hana/current/mule-s4hana.xsd

This example shows how the namespace statements are placed in the Mule XML block:

<mule xmlns:s4hana="http://www.mulesoft.org/schema/mule/s4hana"
    xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
    xmlns:http="http://www.mulesoft.org/schema/mule/http"
    xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns="http://www.mulesoft.org/schema/mule/core"
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
    http://www.mulesoft.org/schema/mule/core/current/mule.xsd
    http://www.mulesoft.org/schema/mule/file
    http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
    http://www.mulesoft.org/schema/mule/http
    http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/ee/core
    http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
    http://www.mulesoft.org/schema/mule/s4hana
    http://www.mulesoft.org/schema/mule/s4hana/current/mule-s4hana.xsd">

Add a POM File Dependency

The pom.xml Maven file generated by Anypoint Studio contains dependencies for a Mule app. When you code a Mule app manually, include this XML snippet in your pom.xml file to enable access to the connector.

<dependency>
    <groupId>com.mulesoft.connectors</groupId>
    <artifactId>mule-sap-s4hana-cloud-connector</artifactId>
    <version>RELEASE</version>
    <classifier>mule-plugin</classifier>
</dependency>

Mule runtime engine translates the RELEASE keyword to the current version.

To obtain the most up-to-date pom.xml file information, access the connector in Anypoint Exchange and click Dependency Snippets.

Example: Create, Get, Query, Update Entity, and Execute Function

The example that follows demonstrates the use of SAP S/4HANA connector to create and get an entity, query for a value, update the entity, and execute a function.

To build and run this demo project, you need:

  • Anypoint Studio with at least the Mule 4.1.0 and later runtime

  • SAP S/4 HANA Cloud Connector v1.0.0 and later

  • Credentials for sending ODATA API requests

When using the Update entity operation, the entity key must be specified as part of the payload.

Test the Flow

  1. Import the demo project into your workspace using Anypoint Exchange or using the Import command in the File menu.

  2. Specify your basic credentials in the /src/main/app/mule-app.content file:

  3. Run the project in Studio.

  4. Type localhost:8081 in your browser to access the selection menu of the demo.

  5. Optionally you can configure the Connection Timeout and Read Timeout fields.

    The connection timeout is used when making the initial connection with the server. The read timeout is used when waiting to read data from the server.

  6. Use the selection menu from http://localhost:8081 to test the flows.

Use Case: SAP S/4HANA Operations

Operations Studio 7 Flow
Operations Studio 7 Flow
Operations Studio 7 Flow
Operations Studio 7 Flow
Operations Studio 7 Flow
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
 	xmlns:s4hana="http://www.mulesoft.org/schema/mule/s4hana"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/s4hana
	http://www.mulesoft.org/schema/mule/s4hana/current/mule-s4hana.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
	<http:listener-config name="HTTP_Listener_config"
			doc:name="HTTP Listener config"
			basePath="/" >
	  <http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<s4hana:config name="SAP_S_4HANA_Config" doc:name="SAP S 4HANA Config" >
        <s4hana:basic-authentication-connection
	username="${config.username}"
	password="${config.password}"
	baseUrl="${config.serviceBaseUrl}">
            <s4hana:unlisted-services >
                <s4hana:unlisted-service value="API_BUSINESS_PARTNER" />
                <s4hana:unlisted-service value="API_FINANCIALPLANDATA_SRV" />
                <s4hana:unlisted-service value="MD_CUSTOMER_MASTER_SRV_01" />
            </s4hana:unlisted-services>
            <s4hana:default-query-params>
                <s4hana:default-query-param key="saml2" value="disabled" />
            </s4hana:default-query-params>
        </s4hana:basic-authentication-connection>

    </s4hana:config>
    <configuration-properties doc:name="Configuration properties"
      file="mule-artifact.properties" />
    <flow name="createEntityFlow"  >
		<http:listener doc:name="Listener"
		  config-ref="HTTP_Listener_config"
		  path="/create"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
    "BusinessPartner": "17100001",
    "BankIdentification": "1244",
    "BankCountryKey": "US",
    "BankName": "Bank 1 - SAMPLE BANK",
    "BankNumber": "011000390",
    "SWIFTCode": "BOFAUS3M",
    "BankControlKey": "",
    "BankAccountHolderName": "abc",
    "BankAccountName": "abc",
    "IBAN": "",
    "IBANValidityStartDate": null,
    "BankAccount": "100009",
    "BankAccountReferenceText": "abc",
    "CollectionAuthInd": false,
    "CityName": "Palo Alto",
    "AuthorizationGroup": ""
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<s4hana:create-entity
			doc:name="Create entity"
			config-ref="SAP_S_4HANA_Config"
			service="API_BUSINESS_PARTNER"
			entityType="A_BusinessPartnerBank">
			<s4hana:entity ><![CDATA[#[%dw 2.0
output application/java
---
payload]]]></s4hana:entity>
		</s4hana:create-entity>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
	<flow name="getEntityFlow" >
		<http:listener doc:name="Listener"
		  config-ref="HTTP_Listener_config"
		  path="/get"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
	"BusinessPartner": "17100001",
	"BankIdentification": "1244"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<s4hana:get-entity
			doc:name="Get entity"
			config-ref="SAP_S_4HANA_Config"
			select="*"
			service="API_BUSINESS_PARTNER"
			entityType="A_BusinessPartnerBank">
			<s4hana:key ><![CDATA[#[output application/java
---
payload]]]></s4hana:key>
		</s4hana:get-entity>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
	<flow name="queryFlow" >
		<http:listener doc:name="Listener"
		config-ref="HTTP_Listener_config"
		path="/query"/>
		<s4hana:query
			doc:name="Query"
			filter="BankIdentification eq '0001'"
			config-ref="SAP_S_4HANA_Config"
			select="*" service="API_BUSINESS_PARTNER"
			entityType="A_BusinessPartnerBank"
			orderBy="BankCountryKey asc"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
	<flow name="updateEntityFlow" >
		<http:listener doc:name="Listener"
		  config-ref="HTTP_Listener_config"
		  path="/update"/>
		<ee:transform doc:name="Transform Message">
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/java
---
{
	"SalesOrder": "25",
	"TransactionCurrency": "USD"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<s4hana:update-entity
			doc:name="Update entity"
			config-ref="SAP_S_4HANA_Config"
			service="API_SALES_ORDER_SRV"
			entityType="A_SalesOrder">
			<s4hana:entity><![CDATA[#[output application/java
---
payload]]]></s4hana:entity>
			<s4hana:custom-headers>
				<s4hana:custom-header key="If-Match" value="*" />
			</s4hana:custom-headers>
		</s4hana:update-entity>
		<s4hana:get-entity doc:name="Get entity by key"
		config-ref="SAP_S_4HANA_Config"
		service="API_SALES_ORDER_SRV"
		entityType="A_SalesOrder">
			<s4hana:key><![CDATA[#[SalesOrder: "25"]]]></s4hana:key>
		</s4hana:get-entity>
		<ee:transform doc:name="Transform Message">
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
	<flow name="executeFunctionFlow" >
		<http:listener doc:name="Listener"
		config-ref="HTTP_Listener_config"
		path="/execute"/>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
{
	"BusinessPartner": "17100001"
}]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<s4hana:execute-function
			doc:name="Execute function"
			config-ref="SAP_S_4HANA_Config"
			function="GET_DATACLOUD_OPURL"
			service="MD_CUSTOMER_MASTER_SRV_01">
		</s4hana:execute-function>
		<ee:transform doc:name="Transform Message" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<logger level="INFO" doc:name="Logger" message="#[payload]"/>
	</flow>
</mule>

See Also

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.