SAP Integration With MuleSoft

kamalika chaudhuri
Another Integration Blog
6 min readAug 6, 2022

This blog is a developers guide to SAP integration with MuleSoft using MuleSoft’s SAP Certified connector. MuleSoft’s SAP Certified connector helps integrate different on-premise and cloud-based business applications with SAP ERP Central Component (ECC) via IDoc or BAPI over RFC, and SAP S/4 Hana via RFC.

SAP is an ERP system that holds all of the master data of an organization. For critical use cases, the organization requires CRUD operations to be performed on this master data. SAP is a difficult system to integrate but with MuleSoft’s SAP connector it becomes easy. Using the connector, you can work on an SAP integration with little or no knowledge about SAP, like me. I have successfully worked on two projects involving SAP integration and am currently involved in a third one. I created this blog to share some challenges I have experienced and solutions to over come them. As developers, we face a lot of errors while trying new things; I hope this will be a helpful resource to explain and overcome common errors for anyone who is new to SAP integration and is implementing it in MuleSoft.

1: Get the connector from Anypoint Exchange: if the connector is not already present in your studio, you can get it from the Exchange.

Once imported, the SAP connector and its operations will be available in the Mule palette, as shown below.

2.1: Configuration: Setting up the Java Connector Libraries

The SAP connector supports 3.0.x versions for the libraries. You can add and configure JAR files as Maven dependencies or local files. For Maven dependency, you have to download the JAR file then deploy it in any of your binary repositories. Downloading the JAR from SAP Marketplace requires an SAP ID.

2.2: Configuration: Configure Based on Authentication

There are two types of authentication: username-password based and certificate based. Certificate based authentication is required when the MuleSoft is the client.

2.3: Configuration: Configure Connectivity Based on host

There are two host types to connect: an application server host or a message server host. You can connect directly to an application server or there might be a message server on top of the application server.

3: Operations

The SAP connector supports a two way exchange of data.

IDoc: IDocs is a standard data format defined by SAP for the exchange of information between SAP and non-SAP applications. IDocs are typically used when information needs to be sent to or from SAP without notification requirements. This is primarily used to transfer master data in and out of SAP.

Business Application Programming Interface (BAPI): BAPIs are defined interfaces that can be called either by either SAP or non-SAP applications, typically in synchronous scenarios. For example, a customer could use BAPIs to plan new orders or change existing ones. There are hundreds of BAPIs available that provide a broad set of functions for SAP integration.

Below, we see various IDoc and RFC based operations available in MuleSoft’s SAP Connector.

4: Sample Messages

A Typical RFC XML Payload:

A Typical IDoc XML Payload:

Based on the configuration on the SAP side, you can receive one of multiple IDocs in a request.

5: Troubleshooting

Additionally, if the Java Connector (JCo) native library provided is not complaint with the operation system we will get an error. For example, if we have configured sapjco3.dll in CloudHub instead of the libsapjc03.so, we will get an error stating that there is no sapjco3 in the Java library path.

Some other errors related to the JAR files can occur. For example, an error can occur when we are using a JAR for a 32 bit system, when it should be for a 64 bit system.

While doing an IDoc connectivity test after deploying to CloudHub, we faced an error that stated gateway registration has failed as the IP was not allowed. Here, we allowed the MuleSoft VPC CIDR range in the SAP external security. Once we received the IDoc, it wasn’t readable. After spending some time on it, we figured out that SAP was not configured to accept Unicode communication. Once that was enabled on SAP side, we were able to read our IDoc and further process it. A gateway registration happens in the connector placed as a listener (i.e. a document listener that listens for IDocs and function listeners that listens for BAPI functions). Program ID creation is required for gateway registration. The SAP system program ID that is registered on the gateway must be unique for the given gateway.

From this experience, I have listed the addition configuration required on the SAP side for the IDoc or function listener.

Reconnection Strategy:

The reconnection strategy on SAP listeners (document listener and function listener) relies exclusively on the JCo library. This means that the Mule reconnection mechanism has no impact on reconnections.

The JCo Server that runs in the background manages the reconnection when there is a connection issue. The JCo RFC provider recognizes a communication error between the Java server and the ABAP gateway and attempts to reconnect. If the first reconnection fails, the next reconnection attempt occurs after waiting for one second. If the reconnection fails again, the reconnection wait-time doubles from one second to two seconds, until eventually it reaches the default maximum waiting period of 3600 seconds (or one hour). Set the maximum reconnection timeout using the -Djco.server.max_startup_delay=<reconnect delay in seconds> JMV parameter.

6 : Useful links

--

--