MuleSoft IDoc Integration using REST API

Joydeep Paul
Another Integration Blog
4 min readMar 20, 2023

When we integrate with SAP, one of the prominent approaches is using IDoc (Intermediate document). To use IDoc, normally any integration tool needs a SAP connector, which utilizes the SAP JCo libraries. MuleSoft also has Anypoint connector for SAP, which is a SAP certified connector to integrate with SAP using IDoc & BAPI. This is a premium connector, comes along with additional licensing cost.

We will consider few scenarios where there might be a need to integrate SAP using IDocs but enterprise not willing to use SAP connector.

  1. Some time an organization has few number of integration using IDocs and procuring a separate licensing for that may not be feasible.
  2. SAP connector works on RFC protocol which by default operate on TCP/IP layer. And using this enterprise move away from building a pure API led application network. (SAP connector integration doesn’t show up in Visualizer).
  3. SAP ECC is migrating to S4/Hana where majority of integration are planned to use S4/Hana OData/SOAP connectors. But still few IDocs based integration which will remain as is in SAP side.
  4. Your enterprise migrating from a legacy integration platform to MuleSoft, where they do not consider purchasing additional licensing for SAP connector. Existing IDoc based interface will be used as is just by changing some configuration within SAP.

Below I have discussed about the solution incase your enterprise wants to achieve REST API based IDoc integration. Here are the step by steps guides with details and related screenshots.

In MuleSoft, first create a REST API with HTTPS listener and provide the host and API path to SAP Basis team. You can also implement API policy like Client ID Enforcement and share client id/secret. Screenshots of a sample flow given at the end.

SAP side configuration :

  1. Create RFC Destination: Define an HTTP(S) connection of type G in T-Code SM59, specifying the HTTP destination provided by MuleSoft team as well as any logon credentials or proxy settings that might be needed. Screenshot of this setup given below.
RFC Destination Setup for HTTP/S (T-Code SM 59)

MuleSoft may implement client id enforcement policy (as per below screenshot) and client id & secret need to be shared with SAP basis team.

Basis team configure the client & secret in Logon & Security section of SM59 configuration:

Provide Authentication details

Also for TLS settings MuleSoft provided certificate can be installed in SAP.

2. Define Port: SAP Basis team defines a port of type XML HTTP using T-Code WE21 and point it to the RFC destination that is created in step# 1 (highlighted in yellow). Screenshot of this configuration given below.

XML-HTTP/S PORT configuration in SAP using T-Code WE21

3. Define Partner profile: SAP team (functional/technical) configure Partner profile in WE20, point the outbound IDoc configuration to the XML HTTP port created in previous step. Screenshot of this setup given below.

Partner Profile setup in SAP using T-Code WE20

You should be all set from SAP side.

Now in MuleSoft you can simply have a REST API with HTTP listener as event source. When SAP send IDocs through HTTP/S MuleSoft receives IDoc XML which is in same structure as Mule SAP connector provides after IDoc listener event source. Then you may use a transform message to map IDoc to JSON or other structure (for input metadata you need to ask for IDoc XML schema/XSD from SAP, t-code WE60 ) and call process API or implement further steps. A sample Flow screenshot is given below:

Sample Mule REST API to receive IDocs from SAP

That’s it! You are all set to receive IDocs from SAP through HTTP/S without using SAP premium connector. I tried to compare the performance between RFC (SAP connector) and HTTP/S (REST API) deployed in Anypoint platform with same resources. Below is a screenshot where at a time 500 IDocs are sent from SAP. I see the performances are at par for both the options. Both the cases 500 IDocs received within 30 seconds.

Performance of IDocs Integration using RFC on SAP connector:

Performance of IDoc integration using REST API over HTTP/S:

That’s all about receiving IDocs from SAP to MuleSoft. But what about sending IDocs to SAP? Yes that is also possible, due to my restricted access I couldn’t perform that integration but I am sharing a document link for that purpose. Inbound IDocs over HTTP/S — Link

Maybe in the future I plan to write another blog for inbound IDoc integration using XML over HTTP/S 😊.

--

--

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