INTRODUCTION
Companies using SAP as a resource planning solution may need to integrate it with other applications in order to automate their business processes. This article demonstrates how to connect other systems with SAP using MuleSoft Mule ESB.
Install and Configure Java Connector Libraries
There are SAP Java Connector (JCo) libraries available which SAP Transport uses to perform below operations in the Mule application:
There are SAP Java Connector (JCo) libraries available which SAP Transport uses to perform below operations in the Mule application:
- Execute BAPI functions over synchronous RFC (sRFC), transactional RFC (tRFC) and queued RFC (qRFC).
- Send IDocs over tRFC and qRFC.
- Receive IDocs over tRFC and qRFC.
- Transform all SAP objects (JCoFunction & IDocs) to/from XML.
1. Download the SAP JCo and IDoc libraries from the SAP site: http://service.sap.com/connectors (it requires an SAP User ID). There will be two jars and one dynamic link library (dll):
- sapidoc3.jar
- sapjco3.jar
- sapjco3.dll
Note: These libraries are operating system dependent, so download he SAP libraries that correspond to the OS you are working in.
2. Create a Mule application e.g. SAP.Connect
3. Place jars i.e. sapidoc3.jar and sapjco3.jar in application CLASSPATH. In this instance, I am showing one application so copy the files under: SAP.Connectsrcmainapplib.
3. Place jars i.e. sapidoc3.jar and sapjco3.jar in application CLASSPATH. In this instance, I am showing one application so copy the files under: SAP.Connectsrcmainapplib.
Note: MuleSoft recommends configuring the following directories
- $MULE_HOME/apps/YOUR_APP/lib: make libraries available just for your application.
- $MULE_HOME/lib/user: Share libraries among all applications running within the same Mule ESB instance.
4. Copy SAP JCo dynamic linked library sapjco3.dll under local folder. For this application I placed the file under DLL folder.
Note: As per MuleSoft, it can be done by either of the following:
- Configure the LD_LIBRARY_PATH environment variable
- Configure the Mule ESB wrapper configuration file $MULE_HOME/conf/wrapper.conf by adding the line wrapper.java.library.path.{N}=PATH/TO/SAP-JCO/LIB-DIR
SAP CONNECTOR CONFIGURATION
1. Go to Global Elements of Mule application created in the step above, click the Create button, write SAP in Filter, select SAP under Connector Endpoints and click OK
2. Provide SAP connection properties as shown in the image below, i.e.:
- SAP Host
- User
- Password
- SAP System Number
- SAP Client
- Login Language
- For Required Dependencies, provide the JCo DLL sapjco3.dll path for the SAP Java Native Library, classpath of JAR sapjco3.jar for the SAP Java Connector and classpath of JAR sapidoc3.jar for the SAP Java IDoc Class Library
Click Test Connection and click the OK button if successful.
OUTBOUND ENDPOINT CONFIGURATION
In this instance, we will poll the FTP location to receive the IDoc XML and send to SAP after converting to IDoc and receiving a successful/failed response from SAP. In order to accomplish this scenario, create a Mule flow with following artifacts:
- FTP Endpoint – Location to receive XML document.
- Byte Array to String – To convert the received byte array to string.
- XML to SAP IDoc – Reads the input idoc array byte stream and converts it to an SAP object.
- SAP Endpoint – To receive IDoc.
Inside the Mule flow drag-and-drop the SAP Endpoint and configure it as shown in the image below:
- Endpoint Pattern – request-response
- Connector Configuration – Select connector configured in above step
- Type – IDoc
- Object Name – SAP object for sending IDoc
- RFC Type – Synchronous RFC
Below is the whole mule flow:
INBOUND ENDPOINT CONFIGURATION
For the SAP Inbound Endpoint (JCo Server), we need to modify OS services using the following path:
C:WINDOWSsystem32driversetcservices file
At the end of the services file set the following:
sapgw00 3300/tcp
1. Create a mule flow for inbound
2. Drag and drop SAP endpoint and configure as showing below:
2. Drag and drop SAP endpoint and configure as showing below:
Below is the mule flow: