Mule Integration with SAP

Mule Integration with SAP

Purpose of SAP Connector

MuleSoft facilitates seamless integration with SAP ERP Central Component (ECC) by leveraging its SAP Certified connector. This connector plays a crucial role in connecting cloud-based business applications to SAP ECC through various protocols such as IDoc or BAPI over RFC. Additionally, MuleSoft's SAP Certified connector extends its integration capabilities to SAP S/4 Hana by utilizing RFC, enabling efficient communication and data exchange between diverse systems.

Key Features

  1. Cloud-Based Integration
    • MuleSoft’s SAP Certified Connector enables the integration of cloud-based business applications with SAP ERP Central Component.
  2. Protocol Support
    • Integration with SAP ERP Central Component is supported through IDoc or BAPI over RFC.
    • Integration with SAP S/4 Hana is facilitated via RFC.
  3. Seamless Connectivity
    • The connector ensures a robust and seamless connection between MuleSoft and SAP systems, allowing for efficient data exchange.
  4. Certification
    • MuleSoft’s SAP Connector is officially certified, providing assurance of compatibility and adherence to SAP integration standards.

Use Cases

  1. Data Synchronization
    • Real-time synchronization of data between cloud-based applications and SAP systems, ensuring consistency across the enterprise.
  2. Process Automation
    • Automation of business processes by triggering IDocs or BAPIs over RFC, reducing manual intervention and accelerating workflows.
  3. System Upgrades
    • Smooth transition during SAP system upgrades, with the connector facilitating communication between MuleSoft and SAP environments.

What is ERP software?

ERP or Enterprise Resource Planning, is software that manages important parts of a business like purchasing, production, sales and HR.

SAP is a type of ERP system that holds key information for a company and you often need to change or access this data (CRUD operations) for important tasks.

Integrating with SAP can be tricky, but MuleSoft's SAP connector makes it easy, even for those who aren't experts in SAP. This connector simplifies communication with SAP, making business processes smoother and more efficient.

Prerequisites

  • Anypoint Studio

Import SAP connector

If the connector is not present in your studio, you can get it from Search in Exchange.

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

SAP Configurations

The SAP connector is compatible with versions 3.0.x of the libraries. You can integrate these libraries by adding and configuring JAR files either as Maven dependencies or local files. When opting for Maven dependencies, you need to download the JAR file and subsequently deploy it to any binary repository. Accessing JAR files from the SAP Marketplace necessitates an SAP ID, and for connection establishment, a connection provider using a username and password is mandatory.

There are three jars that need to be configured for SAP in AnyPoint Studio.

1. IDOC Library: Sapidoc3.jar
2. JCO Library: Sapjco3.jar
3. Jco Native Library

There are three different configuration files to run this in different Operating Systems like Windows, Linux, and Mac.

1.sapjco3.dll (Local Windows development).
2.libsapjco3.so (Cloudhub & Linux Os).
3.libsapjco3.jnilib (Mac Os).

The CMD Comments for Configuration Files:

# For Mac:

mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=libsapjco3 -Dversion=3.0.18 -Dpackaging=jnilib -Dfile=libsapjco3.jnilib

# For Windows:

mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=libsapjco3 -Dversion=3.0.18 -Dpackaging=dll -Dfile=sapjco3.dll

# For Linux:

mvn install:install-file -DgroupId=com.sap.conn.jco -DartifactId=libsapjco3 -Dversion=3.0.16 -Dpackaging=so -Dfile=sapjco3.so

SAP Configurations

There are two types of authentication:

  • Simple Connection Provider which is based on username-password.
  • Certificate-based.(Certificate-based authentication is required when MuleSoft is the client).

1. Certificate-based: Connection provider that relies on an X509 Certificate to authenticate the User.

2. Simple Connection Provider: connects using a username and password for the respective system.

Connectivity Configuration

Connectivity configuration involves two primary types of host connections: one is to an application server host, and the other is to a message server host. The direct connection can be established either with the application server or, alternatively, through a message server that sits atop the application server.

1. Application Host Configuration.

2. Message server host configuration.

SAP Operations

IDoc

IDocs serve as a standardized data format established by SAP to facilitate the seamless exchange of information between SAP and non-SAP applications. They find prominent use in scenarios where data transfer is necessary without the need for immediate notifications. Specifically, IDocs play a crucial role in the efficient exchange of master data, enabling the smooth import and export of such information into and out of the SAP system.

HRMD_A08 is an IDOC that encompasses various segments designed for different tables. Within its structure, you'll find diverse IDOC members such as OTYPE, UNAME, TABNAM, and more. These segments and members collectively contribute to the comprehensive functionality of HRMD_A08, making it a versatile and multifaceted IDOC in the SAP environment.

Business Application Programming Interface (BAPI)

BAPIs, or Business Application Programming Interfaces, serve as standardized interfaces within SAP systems, facilitating communication between SAP and external applications. These interfaces, designed for both SAP and non-SAP applications, operate seamlessly in synchronous scenarios. For instance, businesses can leverage BAPIs to efficiently plan and modify orders, with a diverse range of over a hundred BAPIs offering extensive functionalities for seamless integration with SAP.

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

SAP IDOC operations

Document Listener: This is placed at the source to listen to the IDOCs.

Document Listener acts as a source component in a flow it is used to listen to the IDOCs.

Retrieve IDOC: Retrieves an IDOC based on the given key.

This retrieve component is used to retrieve the data from a given IDOC Name in a retrieve component.

Send IDOC:

  1. To send an IDOC to SAP, one can utilize Remote Function Calls (RFC), which serve as a communication mechanism between systems.
  2. RFCs for IDOC transmission can fall into two categories: Transactional Remote Function Calls and Queued Remote Function Calls.
  3. Transactional Remote Function Calls enable immediate processing and transfer of IDOC data between systems.
  4. On the other hand, Queued Remote Function Calls involve placing IDOCs into a queue for later processing, offering a more asynchronous approach to data transfer in the SAP environment.

This component is used to send respective segment tables and IDOC members of the respective IDOC.

Synchronous Remote Function Call:

Executes a BAPI Function over a synchronous Remote Function Call(cRFC).

Similarly, you can use other SAP connector operations to send and retrieve IDocs and other operations.

Asynchronous Remote Function Call:

Executing a BAPI Function through an Asynchronous Remote Function Call involves utilizing a queued Remote Function Call (qRFC). The qRFC, an extension of the transactional RFC (tRFC), ensures sequential processing of individual steps within the remote function call. This approach guarantees that each step is executed in a specific order, maintaining the integrity of the overall process.

Conclusion for Synchronous Remote Function Call and Asynchronous Remote Function Call:

MuleSoft's SAP Connector is a powerful tool that excels in retrieving data from SAP systems. It supports various operations like IDoc, BAPI, and Remote Function Calls, making it a highly favored choice among connectors for interfacing with SAP. It has gained widespread usage and is considered one of the most popular connectors in the MuleSoft ecosystem.

This is how you can use the SAP connector to send and retrieve IDocs, and execute BAPI functions synchronously and asynchronously.

Function Listener: Listens for incoming BAPI Function and it acts as a source.

Get Function: Retrieves a BAPI Function based on its name.

Sample Messages:

A Typical IDoc XML Payload:

First EDI_DC40 section Contains metadata of the data.

Inside EDI_DC40 The DOCNUM represents the IDOC number and is unique for each IDOC.

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

Troubleshooting

Error if any of the jar file is missing:

Missing JCo native library:

java.lang.ExceptionInInitializerError: JCo initialization failed with java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path

Missing JCo JAR:

java.lang.NoClassDefFoundError: com/sap/conn/jco/JCoTraceListener

Missing IDoc JAR:

java.lang.NoClassDefFoundError: com/sap/conn/idoc/IDocMetaDataUnavailableException

Considerations While Deploying To CloudHub

When deploying your application to CloudHub Runtime Manager, it is crucial to include the JCo native library (libsapjco3) in both the build path and the pom.xml file. This is particularly important since CloudHub workers operate on the Linux operating system. Failure to do so may result in a runtime error, specifically, a java.lang.ExceptionInInitializerError with the message "JCo initialization failed due to java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path". Therefore, ensuring the presence of the JCo native library in the appropriate locations is essential to prevent this issue during deployment on CloudHub.

If the Java Connector (JCo) native library supplied is incompatible with the operating system, an error will occur. For instance, using sapjco3.dll configuration in CloudHub instead of libsapjc03.so will result in an error indicating the absence of sapjco3 in the Java library path. It's crucial to ensure the correct native library corresponding to the operating system is utilized to avoid such errors.

Various errors related to JAR files may arise, with one common issue being the mismatch between the intended system architecture and the JAR file's specifications. Specifically, an error might occur if a JAR file designed for a 32-bit system is mistakenly utilized on a 64-bit system.

While testing IDoc connectivity on CloudHub, we faced an issue with gateway registration due to an IP address error. We fixed it by allowing the MuleSoft VPC CIDR range in SAP security settings. After receiving the IDoc, we couldn't read it, and it turned out SAP wasn't set up for Unicode communication. Enabling Unicode in SAP resolved the problem. Gateway registration occurs in the connector serving as a listener, requiring a unique Program ID for registration on the gateway.

Reconnection Strategy

The reconnection strategy for 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, which works in the background, takes care of reconnecting if there's a connection problem. If there's a hiccup between the Java server and ABAP gateway, the JCo RFC provider tries to reconnect. If the first attempt fails, it waits for one minute before trying again. If it fails again, the wait time doubles each time, going from one minute to two minutes, until it maxes out at 100,000 seconds.


Powerful Tool

In conclusion, MuleSoft’s SAP Certified Connector serves as a powerful tool for organizations seeking robust and certified integration solutions between their cloud-based applications and SAP ERP Central Component or SAP S/4 Hana.

Mulecraft Footer