MuleSoft SAP Integration using IDocs

Joydeep Paul
Another Integration Blog
4 min readJan 18, 2023

When it comes to integrating with SAP, whether it is S4/Hana or SAP ECC majority of SAP integration uses IDoc format ensuing Event driven Integration pattern.

Here in this blog I will show step by step guides on all the setup needed in MuleSoft to receive IDocs from SAP. I will also mention the step needed when we deploy the App to MuleSoft runtime plane.

Before proceeding, please make sure your organization has subscribed to the SAP premium connector.

Configuration details needed from SAP

The two activities presented in the below sections are performed by SAP Team (Basis) and they share the information to MuleSoft team.

  • RFC destination needs to be created in SAP using Transaction Code SM59. The RFC destination is a symbolic name that is used to direct events to a target system masking the Program ID. The target system in this case is the MuleSoft SAP Connector which acts as an inbound endpoint to receive IDocs and Functions over RFC. MuleSoft needs the Program Id from this step.
  • Create partner profile in SAP using Transaction Code WE20.
  • Create port using Transaction Code WE21.
  • Link the IDoc basic type and Message type.

Following information is needed to configure MuleSoft SAP Connector

  • User Account & password (created by SAP Security Team) : MuleSoft uses this username to connect to SAP. Please make sure SAP username has proper authorization to pull IDoc metadata from SAP.
  • SAP System Number, Client Id & Application server Host.
  • If SAP has load balancing on, then instead of Application server you need Message server Host, System ID, Message server port and Message server group.
  • Along with that you need Gateway Host, Gateway Service, Program Id (configured in previous step).
  • Details given in the screenshot of SAP Connector config.
  • SAP Java Connector (JCo) libraries — these libraries can be provided by SAP team. Jco libraries are available in SAP Marketplace. Anyone who has access can download these library files from there.

Below list shows the Library for different OS.

Windows : sapidoc3.jar, sapjco3.jar, sapjco3.dll

MAC: sapidoc3.jar, sapjco3.jar, libsapjco3.jnilib

LINUX: sapidoc3.jar, sapjco3.jar, libsapjco3.so

Configuration needed in Anypoint Studio and local setup

  • Add Gateway service & port in services file located in C:\Windows\System32\drivers\etc (for Windows). sapgw<system#> 33<system#>/tcp (for example: sapgw00 3300/tcp)
  • If SAP load balancing is on then add another entry in services file. sapms<SID> 36<system#>/tcp (for example: sapmsABC 3600/tcp)

Below is a sample entry in etc/services file in your local drive (where Anypoint Studio runs)

Now you are all set to start the development. In Anypoint Studio, add SAP Connector — Mule 4 (first time click Search on Exchange and then add the Module).

  • Drag SAP -> Document listener as Event source. It listens to incoming IDocs and produces IDoc in XML format as a Mule Event.
  • Complete SAP Config setup using information from SAP and test the connection.
  • Sample SAP Config screenshot is given below for a simple connection provider.

For additional details on SAP Configuration please click here.

Please note the JCo native library is OS specific (highlighted in yellow). If you are using Studio which is on a different OS than your deployment Runtime, please modify the native library specific for Runtime OS. For example if it runs on EC2-Linux use — libsapjco3.so

These OS specific JAR files should be uploaded into the respective project Artifactory.

Screenshot provided at the end for a simple flow and configuration of a document listener.

You can also filter all Incoming IDocs by using Expression IDoc type filter regex.

Once you deploy the app in studio, please ask SAP to send the IDoc to the Program ID you are listening to. If you have access you can also send IDoc (exiting IDoc) using T-Code WE19.

SAP connector converts the IDoc from its native format to XML format and populates in payload of Mule event.

Sample flow to receive IDocs from SAP

Once you have successfully received IDocs you can proceed for further development.

Please note while deploying into the Mule runtime plane verify that POM file has proper dependency based on the OS of Mule runtime. As indicated earlier only Native library is OS specific, the other two libraries are the same.

--

--

Joydeep Paul
Another Integration Blog

Having 18+ years of experience in creating Architecture and building API service layer and integration. Specialist in MuleSoft, Apigee & webMethods. TOGAF 9.1