+
+

SAP Connector 5.4 Examples - Mule 4

The following examples show how to send an IDoc to SAP and receive an SAP function.

Send an IDoc to SAP

This example shows you how to create a Mule app that sends an IDoc to SAP. The following screenshot shows the Studio flow for this example:

Studio flow for sending an IDoc to SAP

Configure HTTP Listener

Configure HTTP Listener to initiate a Mule flow when a call is made to the /sendIDoc path on localhost port 8081:

  1. In Anypoint Studio, create a new Mule project.

  2. In the Mule Palette view, drag the HTTP > Listener operation to the canvas to start the flow.

  3. Configure the global element using the default values.

  4. In the Listener properties tab, set the path to /sendIDoc.

Add the Transform Message Component

Configure the Transform Message component to convert the IDoc input to XML:

  1. From the Mule Palette view, select Core and drag the Transform Message component to the right of the Listener component.

  2. After the metadata is retrieved, overlay the text in the Output section of the Transform Message component with the following text:

    %dw 2.0
    output application/xml
    <MATMAS01>
    <IDOC BEGIN="1">
      <EDI_DC40 SEGMENT="1">
        <TABNAM>EDI_DC40</TABNAM>
        <MANDT>800</MANDT>
        <DOCNUM>0000000003519646</DOCNUM>
        <DOCREL>740</DOCREL>
        <STATUS>30</STATUS>
        <DIRECT>1</DIRECT>
        <OUTMOD>2</OUTMOD>
        <IDOCTYP>MATMAS01</IDOCTYP>
        <MESTYP>MATMAS</MESTYP>
        <SNDPOR>SAPIDE</SNDPOR>
        <SNDPRT>LS</SNDPRT>
        <SNDPRN>T90CLNT090</SNDPRN>
        <RCVPOR>MULE01_TP</RCVPOR>
        <RCVPRT>LS</RCVPRT>
        <RCVPRN>MULE01_LS</RCVPRN>
        <CREDAT>20180606</CREDAT>
        <CRETIM>133420</CRETIM>
        <SERIAL>20180606133420</SERIAL>
      </EDI_DC40>
      <E1MARAM SEGMENT="1">
        <MSGFN>005</MSGFN>
        <MATNR>000000000000000088</MATNR>
        <ERSDA>19970527</ERSDA>
        <ERNAM>MORLEY</ERNAM>
        <LAEDA>20030122</LAEDA>
        <AENAM>I021066</AENAM>
        <PSTAT>KVB</PSTAT>
        <LVORM>X</LVORM>
        <MTART>FERT</MTART>
        <MBRSH>M</MBRSH>
        <MATKL>02004</MATKL>
        <MEINS>PCE</MEINS>
        <BLANZ>000</BLANZ>
        <BRGEW>0.200</BRGEW>
        <NTGEW>0.200</NTGEW>
        <GEWEI>KGM</GEWEI>
        <VOLUM>0.000</VOLUM>
        <TRAGR>0001</TRAGR>
        <SPART>09</SPART>
        <WESCH>0.000</WESCH>
        <LAENG>0.000</LAENG>
        <BREIT>0.000</BREIT>
        <HOEHE>0.000</HOEHE>
        <ERGEW>0.000</ERGEW>
        <ERVOL>0.000</ERVOL>
        <GEWTO>0.0</GEWTO>
        <VOLTO>0.0</VOLTO>
        <FUELG>0</FUELG>
        <STFAK>0</STFAK>
        <MHDRZ>0</MHDRZ>
        <MHDHB>0</MHDHB>
        <MHDLP>0</MHDLP>
        <VPSTA>KVB</VPSTA>
        <MSTDE>00000000</MSTDE>
        <MSTDV>00000000</MSTDV>
        <COMPL>00</COMPL>
        <GEWTO_NEW>0.0</GEWTO_NEW>
        <VOLTO_NEW>0.0</VOLTO_NEW>
        <ANP>000000000</ANP>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>1</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>ZH</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>4</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>RO</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>5</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>SL</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>6</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>HR</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>E</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>EN</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>F</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>FR</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>G</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>EL</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>J</SPRAS>
          <MAKTX>AS-100 T ???</MAKTX>
          <SPRAS_ISO>JA</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>W</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>BG</SPRAS_ISO>
        </E1MAKTM>
        <E1MAKTM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <SPRAS>d</SPRAS>
          <MAKTX>AS-100 T-shirt</MAKTX>
          <SPRAS_ISO>SH</SPRAS_ISO>
        </E1MAKTM>
        <E1MARCM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <WERKS>1000</WERKS>
          <PSTAT>V</PSTAT>
          <LVORM>X</LVORM>
          <PLIFZ>0</PLIFZ>
          <WEBAZ>0</WEBAZ>
          <PERKZ>M</PERKZ>
          <AUSSS>0.00</AUSSS>
          <MINBE>0.000</MINBE>
          <EISBE>0.000</EISBE>
          <BSTMI>0.000</BSTMI>
          <BSTMA>0.000</BSTMA>
          <BSTFE>0.000</BSTFE>
          <BSTRF>0.000</BSTRF>
          <MABST>0.000</MABST>
          <LOSFX>0</LOSFX>
          <AUSDT>00000000</AUSDT>
          <BEARZ>0.00</BEARZ>
          <RUEZT>0.00</RUEZT>
          <TRANZ>0.00</TRANZ>
          <BASMG>0.000</BASMG>
          <DZEIT>0</DZEIT>
          <MAXLZ>0</MAXLZ>
          <UEETO>0.0</UEETO>
          <UNETO>0.0</UNETO>
          <WZEIT>0</WZEIT>
          <VZUSL>0.00</VZUSL>
          <UMLMC>0.000</UMLMC>
          <LGRAD>0.0</LGRAD>
          <OBJID>00000000</OBJID>
          <MTVFP>01</MTVFP>
          <VRVEZ>0.00</VRVEZ>
          <VBAMG>0.000</VBAMG>
          <VBEAZ>0.00</VBEAZ>
          <TRAME>0.000</TRAME>
          <FXHOR>000</FXHOR>
          <VINT1>000</VINT1>
          <VINT2>000</VINT2>
          <LOSGR>0.000</LOSGR>
          <KAUSF>0.00</KAUSF>
          <TAKZT>0</TAKZT>
          <VRBDT>00000000</VRBDT>
          <VRBFK>0.00</VRBFK>
          <PREND>00000000</PREND>
          <PRENG>00000000</PRENG>
          <PRFRQ>0</PRFRQ>
          <SHZET>00</SHZET>
          <MMSTD>00000000</MMSTD>
          <DPLHO>0</DPLHO>
          <MINLS>0.000</MINLS>
          <MAXLS>0.000</MAXLS>
          <FIXLS>0.000</FIXLS>
          <LTINC>0.000</LTINC>
          <COMPL>00</COMPL>
          <EISLO>0.000</EISLO>
        </E1MARCM>
        <E1MARCM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <WERKS>2300</WERKS>
          <PSTAT>VB</PSTAT>
          <LVORM>X</LVORM>
          <PLIFZ>0</PLIFZ>
          <WEBAZ>0</WEBAZ>
          <PERKZ>M</PERKZ>
          <AUSSS>0.00</AUSSS>
          <MINBE>0.000</MINBE>
          <EISBE>0.000</EISBE>
          <BSTMI>0.000</BSTMI>
          <BSTMA>0.000</BSTMA>
          <BSTFE>0.000</BSTFE>
          <BSTRF>0.000</BSTRF>
          <MABST>0.000</MABST>
          <LOSFX>0</LOSFX>
          <AUSDT>00000000</AUSDT>
          <BEARZ>0.00</BEARZ>
          <RUEZT>0.00</RUEZT>
          <TRANZ>0.00</TRANZ>
          <BASMG>0.000</BASMG>
          <DZEIT>0</DZEIT>
          <MAXLZ>0</MAXLZ>
          <UEETO>0.0</UEETO>
          <UNETO>0.0</UNETO>
          <WZEIT>0</WZEIT>
          <VZUSL>0.00</VZUSL>
          <UMLMC>0.000</UMLMC>
          <LADGR>0001</LADGR>
          <LGRAD>0.0</LGRAD>
          <OBJID>00000000</OBJID>
          <MTVFP>01</MTVFP>
          <VRVEZ>0.00</VRVEZ>
          <VBAMG>0.000</VBAMG>
          <VBEAZ>0.00</VBEAZ>
          <TRAME>0.000</TRAME>
          <FXHOR>000</FXHOR>
          <VINT1>000</VINT1>
          <VINT2>000</VINT2>
          <LOSGR>0.000</LOSGR>
          <KAUSF>0.00</KAUSF>
          <TAKZT>0</TAKZT>
          <VRBDT>00000000</VRBDT>
          <VRBFK>0.00</VRBFK>
          <PRENO>00000000</PRENO>
          <PREND>00000000</PREND>
          <PRENG>00000000</PRENG>
          <PRFRQ>0</PRFRQ>
          <SHZET>00</SHZET>
          <MMSTD>00000000</MMSTD>
          <DPLHO>0</DPLHO>
          <MINLS>0.000</MINLS>
          <MAXLS>0.000</MAXLS>
          <FIXLS>0.000</FIXLS>
          <LTINC>0.000</LTINC>
          <COMPL>00</COMPL>
          <EISLO>0.000</EISLO>
        </E1MARCM>
        <E1MARMM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <MEINH>PCE</MEINH>
          <UMREZ>1</UMREZ>
          <UMREN>1</UMREN>
          <LAENG>0.000</LAENG>
          <BREIT>0.000</BREIT>
          <HOEHE>0.000</HOEHE>
          <VOLUM>0.000</VOLUM>
          <BRGEW>0.200</BRGEW>
          <GEWEI>KGM</GEWEI>
          <NEST_FTR>0</NEST_FTR>
          <MAX_STACK>0</MAX_STACK>
          <CAPAUSE>0.000</CAPAUSE>
        </E1MARMM>
        <E1MBEWM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <BWKEY>2300</BWKEY>
          <LVORM>X</LVORM>
          <VPRSV>S</VPRSV>
          <VERPR>0</VERPR>
          <STPRS>0.3</STPRS>
          <PEINH>1</PEINH>
          <BKLAS>7920</BKLAS>
          <VMVPR>S</VMVPR>
          <VMVER>0</VMVER>
          <VMSTP>0.3</VMSTP>
          <VMPEI>1</VMPEI>
          <VMBKL>7920</VMBKL>
          <VJVPR>S</VJVPR>
          <VJVER>0</VJVER>
          <VJSTP>0.3</VJSTP>
          <LFGJA>1998</LFGJA>
          <LFMON>09</LFMON>
          <ZKPRS>0</ZKPRS>
          <ZKDAT>00000000</ZKDAT>
          <BWPRS>0</BWPRS>
          <BWPRH>0</BWPRH>
          <VJBWS>0</VJBWS>
          <VJBWH>0</VJBWH>
          <VVJLB>0.000</VVJLB>
          <VVMLB>0.000</VVMLB>
          <VVSAL>0</VVSAL>
          <ZPLPR>0</ZPLPR>
          <ZPLP1>0</ZPLP1>
          <ZPLP2>0</ZPLP2>
          <ZPLP3>0</ZPLP3>
          <ZPLD1>00000000</ZPLD1>
          <ZPLD2>00000000</ZPLD2>
          <ZPLD3>00000000</ZPLD3>
          <BWPH1>0</BWPH1>
          <BWPS1>0</BWPS1>
          <ABWKZ>00</ABWKZ>
          <PSTAT>B</PSTAT>
          <KALN1>000100014878</KALN1>
          <KALNR>000100014879</KALNR>
          <VERS1>00</VERS1>
          <VERS2>00</VERS2>
          <VERS3>00</VERS3>
          <PPRDZ>000</PPRDZ>
          <PPRDL>000</PPRDL>
          <PPRDV>000</PPRDV>
          <PDATZ>0000</PDATZ>
          <PDATL>0000</PDATL>
          <PDATV>0000</PDATV>
          <VPLPR>0</VPLPR>
          <VJBKL>7920</VJBKL>
          <VJPEI>1</VJPEI>
          <HKMAT>X</HKMAT>
          <BWPEI>0</BWPEI>
        </E1MBEWM>
        <E1MLANM SEGMENT="1">
          <MSGFN>005</MSGFN>
          <ALAND>ES</ALAND>
          <TATY1>MWST</TATY1>
          <TAXM1>0</TAXM1>
        </E1MLANM>
      </E1MARAM>
    </IDOC>
    </MATMAS01>
    ',"application/xml")

Add the Send IDoc Operation

The Send IDoc operation sends an IDoc to SAP over a remote function call (RFC):

  1. From the Mule Palette view, select SAP and drag the Send IDoc operation next to the Transform Message component.

  2. Create a global element named SAP_Outbound and specify the connection information.

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

    • If the connection is successful, save the configuration.

    • Otherwise, review and correct any invalid parameters, and test again.

  4. Configure the Send IDoc properties with the following values:

    Parameter Value

    IDoc Name

    MATMAS01

    Content

    #[payload]

Add the Logger Component

The Logger component displays the connector payload in the Studio console.

  1. From the Mule Palette view, select Core and drag Logger next to the Send IDoc operation.

  2. Click File > Save to save the app.

Run the App

To run the Mule app:

  1. Click Run > Run as > Mule Application.

  2. From a web browser, test the application by entering an employee’s internal ID, first name, and last name as query parameters for the following URL:

    http://localhost:8081/sendIDoc

    Mule sends the IDoc to SAP.

XML for Sending an IDoc to SAP

Paste this code into a new Mule app in Studio to quickly load the flow for the sending an IDoc example. Change the values to reflect your environment.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:sap="http://www.mulesoft.org/schema/mule/sap"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/sap http://www.mulesoft.org/schema/mule/sap/current/mule-sap.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="58cb7168-7f00-4b96-977a-31dcc54992dd" >
    <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    <sap:sap-config name="SAP_Outbound" doc:name="SAP Config" doc:id="367ae57d-001b-4d8f-b50f-f6d1d17410a7" >
      <sap:simple-connection-provider-connection username="User1" password="myPassword" systemNumber="00" client="800" applicationServerHost="saptext.net" />
      </sap:sap-config>
      <flow name="sap_send_idocFlow" doc:id="1ee42fb2-8d7d-482d-8f31-095cef12ff08" >
        <http:listener doc:name="Listener" doc:id="a1f287ba-4138-4183-903b-90d34abde5c6" config-ref="HTTP_Listener_config" path="/"/>
        <ee:transform doc:name="Transform Message" doc:id="ae593540-a467-463f-9aae-fbfb781da0cd" >
          <ee:message >
            <ee:set-payload >
              <![CDATA[%dw 2.0
output application/xml
---
read('<MATMAS01>
              <IDOC BEGIN="1">
                <EDI_DC40 SEGMENT="1">
                  <TABNAM>EDI_DC40</TABNAM>
                  <MANDT>800</MANDT>
                  <DOCNUM>0000000003519646</DOCNUM>
                  <DOCREL>740</DOCREL>
                  <STATUS>30</STATUS>
                  <DIRECT>1</DIRECT>
                  <OUTMOD>2</OUTMOD>
                  <IDOCTYP>MATMAS01</IDOCTYP>
                  <MESTYP>MATMAS</MESTYP>
                  <SNDPOR>SAPIDE</SNDPOR>
                  <SNDPRT>LS</SNDPRT>
                  <SNDPRN>T90CLNT090</SNDPRN>
                  <RCVPOR>MULE01_TP</RCVPOR>
                  <RCVPRT>LS</RCVPRT>
                  <RCVPRN>MULE01_LS</RCVPRN>
                  <CREDAT>20180606</CREDAT>
                  <CRETIM>133420</CRETIM>
                  <SERIAL>20180606133420</SERIAL>
                </EDI_DC40>
              </IDOC>
              </MATMAS01>
',"application/xml") ]]>
              </ee:set-payload>
              </ee:message>
              </ee:transform>
              <sap:send doc:name="Send IDoc" doc:id="9d6b0825-7cfb-4c3b-bc6a-b9eae917af9b" config-ref="SAP_Outbound" key="MATMAS01"/>
              <logger level="INFO" doc:name="Logger" doc:id="8fd50dd8-8db4-4271-863b-ef7a463dcaea" />
            </flow>
            </mule>

Receive an Incoming IDoc Request

This example shows you how to create a Mule app that waits for incoming IDoc requests from an external SAP system. In this example, the app acts like an RFC server and registers itself as an SAP gateway. When the app receives an IDoc request, it uses a remote function (RFC) call to ask SAP to create the IDoc. Then it logs the IDoc contents to the Studio console.

The following screenshots show the Studio flows for this example:

Studio flow for retrieving an IDoc

Configure the First Flow

The first flow uses a BAPI function to send IDoc requests to an external SAP system. To configure this flow:

  1. In Anypoint Studio, create a new Mule project.

  2. From the Mule Palette view, select HTTP and drag the Listener operation to the canvas to start a new flow.

  3. Configure the global element using the default values.

  4. In the Listener properties tab, set the path to /trigger.

  5. Drag a Transform Message component next to Listener.

    The content of this message is the payload of the BAPI function that receives the IDoc requests.

  6. In the Output section of the Transform Message component, overlay the brackets with this text:

    %dw 2.0
    output application/xml
    ---
    {
    	ZMMFM_TRIGGER_IDOC_MATMAS: {
    		"import": {
    	IV_MTYP: "MATMAS"
    ,
    IV_OBJ: "23"
    ,
    IV_SYS: "MULE11_LS"
    }
    ,
    export: {
    	EV_RET: "0"
    },export: {
    	EV_OBJ: "0000000003526552"
    },export: null,changing: null,
    tables: {
    	T_MSG: null
    },
    	}
    }
  7. From the Mule Palette view, select SAP and Drag the Synchronous Remote Function Call operation to the right of the Transform Message component.

  8. Create a global element named SAP_Config and specify the connection information.

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

Configure the Second Flow

The second flow logs the contents of each new IDoc request to the Studio console. To configure this flow:

  1. From the Mule Palette view, select SAP and drag the Document listener source to the canvas.

  2. Create a new global element for the source and specify the required information.

    Configure the Document listener properties with the following values:

    Parameter Value

    Gateway host

    Host running the gateway server

    Gateway service

    3200

    Program id

    MULE01_PID

    Connection count

    1

    Idoc type filter regex

    MATMAS01

  3. In the Mule Palette view, select Core and drag a Logger component next to Document listener on the canvas.

  4. Click File > Save to save the app.

Run the App

To run the Mule app:

  1. Click Run > Run as > Mule Application.

  2. From a web browser, test the application by entering the following URL:

    http://localhost:8081/trigger

XML for Receiving an IDoc Request

Paste this code into a new Mule app in Studio to quickly load the flow for the receiving an IDoc request example. Change the values to reflect your environment.

%dw 2.0
output application/xml
---
<?xml version="1.0" encoding="UTF-8"?>
            <mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:sap="http://www.mulesoft.org/schema/mule/sap"
	xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sap http://www.mulesoft.org/schema/mule/sap/current/mule-sap.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
              <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="75b36b20-040b-401f-a65c-f0a966b51190" >
                <http:listener-connection host="0.0.0.0" port="8081" />
                </http:listener-config>
                <sap:sap-config name="SAP_Config" doc:name="SAP Config" doc:id="1f7e7c6e-4bb5-4270-870f-442cda3e3eb8" >
                  <sap:simple-connection-provider-connection username="User1" password="myPassword" systemNumber="00" client="800" applicationServerHost="sap.test.net" />
                  </sap:sap-config>
                  <flow name="sap-receive-idocFlow1" doc:id="bea8cd17-64d9-4f32-8229-d7eb909e8ee1">
                    <http:listener doc:name="Listener" doc:id="448acc4a-0078-485b-bc10-f70d05abf721" config-ref="HTTP_Listener_config" path="/trigger" />
                    <ee:transform doc:name="Transform Message" doc:id="44124bf5-7caf-4050-a3a6-06cfbd37da48">
                      <ee:message>
                        <ee:set-payload>
                          <![CDATA[%dw 2.0
output application/xml
---
{
	ZMMFM_TRIGGER_IDOC_MATMAS: {
		"import": {
	IV_MTYP: "MATMAS"
,
IV_OBJ: "23"
,
IV_SYS: "MULE11_LS"
}
,
export: {
	EV_RET: "0"
},export: {
	EV_OBJ: "0000000003526552"
},export: null,changing: null,
tables: {
	T_MSG: null
},
	}
}]]>
                          </ee:set-payload>
                          </ee:message>
                          </ee:transform>
                          <sap:sync-rfc doc:name="Synchronous Remote Function Call" doc:id="e420d5e1-c436-471e-aa48-59a7d2cee1b9" key="ZCAFM_TRIGGER_IDOC_BY_MSG_TYPE" config-ref="SAP_Config" />
                        </flow>
                        <flow name="sap-receive-idocFlow2" doc:id="4b070ed0-19ac-4899-82ce-275226b08426" >
                          <sap:document-listener doc:name="Document listener" doc:id="a0d3bf88-1bf1-4210-9cf1-5403f30b2d80" gatewayHost="xxx.com" gatewayService="3200" programID="MULE11_IDOC_PID"  config-ref="SAP_Config"/>
                          <logger level="INFO" doc:name="Logger" doc:id="db7ff63b-31b7-48ab-b0ad-73082f4b66c7" message="#[payload]"/>
                        </flow>
                        </mule>

Example response on the Studio console:

<MATMAS01>
                        <IDOC BEGIN="1">
                          <EDI_DC40 SEGMENT="1">
                            <TABNAM>EDI_DC40</TABNAM>
                            <MANDT>800</MANDT>
                            <DOCNUM>0000000003572826</DOCNUM>
                            <DOCREL>740</DOCREL>
                            <STATUS>30</STATUS>
                            <DIRECT>1</DIRECT>
                            <OUTMOD>2</OUTMOD>
                            <IDOCTYP>MATMAS01</IDOCTYP>
                            <MESTYP>MATMAS</MESTYP>
                            <SNDPOR>SAPIDE</SNDPOR>
                            <SNDPRT>LS</SNDPRT>
                            <SNDPRN>T90CLNT090</SNDPRN>
                            <RCVPOR>MULE11_TP</RCVPOR>
                            <RCVPRT>LS</RCVPRT>
                            <RCVPRN>MULE11_LS</RCVPRN>
                            <CREDAT>20191004</CREDAT>
                            <CRETIM>050305</CRETIM>
                            <SERIAL>20191004050305</SERIAL>
                            </EDI_DC40>
 		...

Receive an SAP Function

This example shows you how to create a Mule app that receives an SAP function. This example displays a result when a function is triggered from either another Mule flow or from the SAP GUI. The following screenshot shows the Studio flow for this example:

Studio flow for establishing an SAP connection

To create the flow:

  1. From the Mule Palette view, select SAP and drag the Function listener source to the canvas.

  2. Create a global element named SAP_Inbound and specify the connection information.

  3. Configure the required fields in the properties tab.

  4. From the Mule Palette view, select Core and drag the Transform Message component to the right of Function listener.

  5. Specify the details based on the metadata. For example:

    Sample metadata for the SAP_Inbound global element
  6. Click File > Save to save the app.

  7. Click Run > Run as > Mule Application.

XML for Receiving an SAP Function

Paste this code into a new Mule app in Studio to quickly load the flow for the receiving a function example. Change the values to reflect your environment.

%dw 2.0
output application/xml
---

<?xml version="1.0" encoding="UTF-8"?>
                            <mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:sap="http://www.mulesoft.org/schema/mule/sap"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sap http://www.mulesoft.org/schema/mule/sap/current/mule-sap.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
                              <sap:sap-config name="SAP_Inbound" doc:name="SAP Config" doc:id="9eb4758e-4eb4-4291-9604-84586dda5cd3" >
                                <sap:simple-connection-provider-connection username="User1" password="Password" systemNumber="00" client="800" applicationServerHost="sapdev.muletest.net" />
                                </sap:sap-config>
                                <flow name="receive-a-functionFlow" doc:id="5104aaba-944d-4b8b-ba35-fc210e1f2c4e" >
                                  <sap:function-listener doc:name="Function listener" doc:id="58ee92ea-967f-4a9c-a14d-164032b1b8ee" config-ref="SAP_Inbound" gatewayHost="gateway.host.com" gatewayService="3200" programID="MULE01_API_PID"/>
                                  <ee:transform doc:name="Transform Message" doc:id="59b4c48f-40ca-4587-80e3-f06d895e1c5b" >
                                    <ee:message >
                                      <ee:set-payload >
                                        <![CDATA[%dw 2.0
output application/java
---
{
}]]>
                                        </ee:set-payload>
                                        </ee:message>
                                        </ee:transform>
                                      </flow>
                                      </mule>

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!