Contact Free trial Login

SAP Connector Examples - Mule 4

Establish a SAP Connection

Create a Mule app that establishes a connection to SAP and receives a function using the SAP connector’s Function source operation. The Function source operation passes the export parameter back to SAP.

  1. Create a new Mule project in Anypoint Studio.

  2. Add the SAP connector to your project from Exchange.

  3. Drag the SAP Function source operation to the source area of the canvas at the start of a flow.

  4. Create a new SAP Inbound global element configuration and specify the environment values.

  5. Add a Transform Message component to the flow and specify the details based on the metadata.

    sap function return response

    The flow now contains Function source in the canvas source area and the Transform Message:

    sap flow response

    The SAP Design Studio displays feedback about the received object and its response:

    sap result sap gui

Send an IDoc to SAP

In this example, you create a Mule app to send an IDoc to SAP:

  1. Create a new Mule project in Anypoint Studio.

  2. Drag the HTTP Listener operation to the canvas and use the default values.

  3. Drag the HTTP Request operation to the canvas and set the Path to /sendIDoc. Use the same HTTP configuration as the HTTP Listener operation.

  4. Create a new SAP outbound global element configuration and specify the environment values.

  5. Click Test Connection to confirm that Mule runtime engine can connect with the SAP instance.

  6. If the connection is successful, save the configuration. Otherwise, review and correct any invalid parameters, and test again.

  7. Select the SAP Connector and add the Send IDoc operation next to the HTTP operation.

  8. Configure the operation with the following values:

    Parameter Value

    Display Name

    Send IDoc (or any other name you prefer).

    Connector configuration

    SAP_Outbound - The name of the global element you created.





  9. Drag a Transform Message component before the SAP connector, and click the component to open its properties editor.

  10. Once metadata has been retrieved, select the respective fields to populate for the employee.

    The XML for the transform script shows the DataWeave content for Transform Message:

    %dw 2.0
    output application/xml
    read('<?xml version="1.0"?>
        <IDOC BEGIN="1">
            <EDI_DC40 SEGMENT="1">
  11. Add a Logger right after the SAP endpoint. When you run your app, Logger displays messages in the Anypoint Studio console that enables you to see the connector payload in the logs.

  12. Click File > Save to save your app.

  13. Click Run > Run as > Mule Application to run the app. Anypoint Studio provides a web server so that you can test the app from a browser.

  14. From a web browser, test the application by entering an employee’s internal ID, first name, and last name in the form of the following query parameters:


    Mule runtime engine conducts the query and adds the employee record.

XML to Send an IDoc to SAP

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee=""
    <configuration-properties file=""/>
    <sap:outbound-config name="SAP_Outbound" doc:name="SAP Outbound" >
        language="${sap.jcoLang}" />
    <http:listener-config name="HTTP_Listener_config"
      doc:name="HTTP Listener config" >
        <http:listener-connection host="" port="8081" />
    <flow name="demo-idoc-clientFlow" >
        <http:listener config-ref="HTTP_Listener_config"
        path="/idoc" doc:name="Listener" />
        <ee:transform doc:name="Transform Message" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
output application/xml
read('<?xml version="1.0"?>
    <IDOC BEGIN="1">
        <EDI_DC40 SEGMENT="1">
    <sap:send config-ref="SAP_Outbound" doc:name="Send IDoc"
    <logger level="INFO" doc:name="Logger" message="#[payload]"/>

See Also

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.