Real-Time XML to EDI Conversion: A Step-by-Step CPI Integration Scenario 2025
Share

[[{“value”:”

Hello all, welcome to this blog on SAP Cloud Integration and EDI. Business partners in many B2B projects still exchange data in classic EDI formats, while modern applications speak XML or JSON. Bridging these formats reliably is one of the common challenges for integration developers working with SAP CPI.

In this article, we will go through a full, hands-on example of receiving an XML message over HTTPS, converting it to EDI, enriching it with a Groovy script, and finally delivering it to the receiver via email. The aim is to provide you with a clear, end‑to‑end view of how to design this flow, which components to use, and what configuration details matter in real projects.

The Scenario we are working is shown below.

FULL SCENARIO IMAGEFULL SCENARIO IMAGE

 

 Before Going Into the Scenario we need to understand about the EDI ,where it is used and all that .

So,EDI is the automated, system‑to‑system exchange of business documents in a standard electronic format, as opposed to paper or email and manual data entry. It is also widely used in B2B processes like orders, invoices, shipping notices, and inventory updates across retail, manufacturing, logistics, automotive, and healthcare. The main standards are UN/EDIFACT (global), ANSI X12 (North America), plus others like TRADACOMS and healthcare‑focused HL7, each with defined message types such as ORDERS/INVOIC (EDIFACT) or 850/810 (X12).

>For the Trail Account We have only option to use Orders(EDIFACT) Standard only.

Now we will go step by step process : –

1)Create an iflow first and from the sender connect to the start event as show in the figure and select the HTTPS adater to send the XML data from the Postman. Here I’m using postman to send the data , we can also use the timer Event with content modifier to start the iflow.

Screenshot 2025-12-05 153243.png

 2)After connecting with the HTTPS adapter, Deply the iflow so we need can get the HTTPS endpoint as shown below, so we can use that endpoint in postman to post the data to cpi.

POstman pagePOstman page

 

ENDPOINTSENDPOINTS

 3)Now Before going to use XML to EDI converter we need to use EDI xsd’s to use for this conversion.So now we need to go to the Settings–>MIGs and MAGs –> click on the trails as shown in the image below to activate the three standards.

Activate these three standardsActivate these three standards

 Accept the each standard like thisAccept the each standard like this

 

After Activating looks like thisAfter Activating looks like this

 

4)After that we need to go to the Design–>MIGs–>click on Create option as shown in the image below.

MIGS.png

5)After that we need to select the type system that we are using in xml to EDI converter , select the sysstem shown in the image below.

CLICK ON UN/EDIFACTCLICK ON UN/EDIFACT

 6)After that we need to select the ORDERS standard because for the trail accounts we can only  select the ORDERS standard froom the list ,so search for it until you find it .

SEARCH FOR ORDERSEARCH FOR ORDER

7)After Finding it click on ORDERS to  proceed to the next steps  as shown below.
Click on the ORDERS to proceedClick on the ORDERS to proceed

 

8)Select version “D.96A s3” as shown below. This is best version for trail accounts.

Select this versionSelect this version

 9)After the version selection we need to select the Envelope we need have in our system. Use the 3rd Envelope as shown in the image to proceed to the next steps.

Select the EnvelopesSelect the Envelopes

 10)After the above step we  need to SKIP the sample payload step and proceed to the MIG creation step.

SKIP the sample payload stepSKIP the sample payload step

 

11)Here we need to Enter the Name of the MIG and Direction its work , we are selecting it as BOTH , so it will work as IN and OUT Directions.

Enter the MIG name and DirectionEnter the MIG name and Direction

 

12) After that , Click on the plus icon and select the ‘Bussiness Process’ and after that we have access the select the list of business processess we have ,so from the drop down select all 250 processess and click on CREATE to create the MIG.

Select all processSelect all process

 13) After creation , created MIG will be appear here , in my case i have created and exported so it is not showing here. For you guys it shown here and when we have that MIG , click on and open that MIG , on the top right side we have three dots icon click on it and EXPORT the MIG as ‘SAP cloud integration runtime artifacts’ , so that one ZIP file will be downloaded and we can seen it our laptop downloads folder . Extract it to get the both xsd files one is normal EDI xsd and another is EDI xsd for runtime. Most of the times we use only one file i.e “UN-EDIFACT_ORDERS_D96A.xsd” .

 

CREATED MIG SHOWN HERECREATED MIG SHOWN HERE

 

EDI xsds in exported folderEDI xsds in exported folder

 14) Drag a XML to EDI converter step from the pallate and add to the iflow as shown in the first image of full iflow starting of the Blog. Click on the EDIFACT and inside that change connections as shown in image and remaining all default and also add the EDI xsd file by clicking on the add button as shown in the image from your laptop import it here. we dont have to change any thing for X12 and Tradacoms.

 

EDIFACT connection pageEDIFACT connection page

 

15) After that I’m using  Groovy script to Log the payload and see the output . Also we can see the output via MAIL also. so, Drag a groovy script and attach it after xml to edi converter .

GROOVY SCRIPT IM USING  :-

import com.sap.gateway.ip.core.customdev.util.Message

def Message processData(Message message) {
def body = message.getBody(String)

// Log to Message Processing Log (MPL)
def messageLog = messageLogFactory.getMessageLog(message)
if (messageLog != null) {
messageLog.addAttachmentAsString(“EDI_OUTPUT”, body, “application/xml”)
}

// Ensure Content-Type is XML
def headers = message.getHeaders()
headers.put(“Content-Type”, “application/xml”)
message.setHeaders(headers)

// Return the mapped XML
message.setBody(body)
return message
}

16) After this from the End message connect mail adapter to the receiver and give the details as shown in the images . And also we need to create “Security material” for the mail we are using for sending mails . I think you guys known how to create it so that Im not including it .

PROCESSING PAGEPROCESSING PAGE

 

CONNECTION PAGECONNECTION PAGE

 

SECURITY MATERIAL OVERVIEWSECURITY MATERIAL OVERVIEW

 

 17) After all these steps we need to deploy the iflow and send the input payload from the postman and we get the output in groovy and MAIL . Select the option in poastman as shown image below and send it.

INPUT payload  for postman :-

–>For payload see below data.xml file uploaded or here is the code :-

<?xml version=”1.0″ encoding=”UTF-8″?>
<Interchange>
<S_UNA>:+.? ‘</S_UNA>
<S_UNB>
<C_S001>
<D_0001>UNOC</D_0001>
<D_0002>3</D_0002>
</C_S001>
<C_S002>
<D_0004>SENDERABC</D_0004>
<D_0007>14</D_0007>
<D_0008>XXXX</D_0008>
</C_S002>
<C_S003>
<D_0010>ReceiverXYZ</D_0010>
<D_0007>14</D_0007>
<D_0014>YYYYY</D_0014>
</C_S003>
<C_S004>
<D_0017>150831</D_0017>
<D_0019>1530</D_0019>
</C_S004>
<D_0020>1</D_0020>
<C_S005>
<D_0022>HELLO WORLD</D_0022>
</C_S005>
<D_0029>A</D_0029>
<D_0035>1</D_0035>
</S_UNB>
<!– First ORDERS message –>
<M_ORDERS>
<S_UNH>
<D_0062>1</D_0062>
<C_S009>
<D_0065>ORDERS</D_0065>
<D_0052>D</D_0052>
<D_0054>96A</D_0054>
<D_0051>UN</D_0051>
</C_S009>
<C_S010>
<D_0070>2</D_0070>
</C_S010>
</S_UNH>
<S_BGM>
<C_C002>
<D_1001>220</D_1001>
</C_C002>
<D_1004>ORDER1</D_1004>
<D_1225>9</D_1225>
<D_4343>NA</D_4343>
</S_BGM>
<!– Further order details here –>
<S_UNT>
<D_0074>5</D_0074>
<D_0062>1</D_0062>
</S_UNT>
</M_ORDERS>
<!– Second ORDERS message –>
<M_ORDERS>
<S_UNH>
<D_0062>2</D_0062>
<C_S009>
<D_0065>ORDERS</D_0065>
<D_0052>D</D_0052>
<D_0054>96A</D_0054>
<D_0051>UN</D_0051>
</C_S009>
<C_S010>
<D_0070>2</D_0070>
</C_S010>
</S_UNH>
<S_BGM>
<C_C002>
<D_1001>220</D_1001>
</C_C002>
<D_1004>ORDER2</D_1004>
<D_1225>9</D_1225>
<D_4343>NA</D_4343>
</S_BGM>
<!– Further order details here –>
<S_UNT>
<D_0074>6</D_0074>
<D_0062>2</D_0062>
</S_UNT>
</M_ORDERS>
<S_UNZ>
<D_0036>2</D_0036>
<D_0020>1</D_0020>
</S_UNZ>
</Interchange>

 
POSTMAN PAGEPOSTMAN PAGE

 

OUTPUT IMAGES :-

 
GROOVY OUTPUTGROOVY OUTPUT

 

MAIL OUTPUTMAIL OUTPUT

 

 

Thank you very much for taking the time to read this blog and walk with me through the XML-to-EDI scenario. Interest from people like you in topics like SAP Cloud Integration and EDI drives content like this, and I hope it helps in your real projects.

If you try out this flow, improve it, or run into interesting challenges, please share your experience and questions in the comments so others in the community can learn as well.

Happy integrating, and see you in the next blog!

“}]] 

  Read More Technology Blog Posts by Members articles 

#abap

By ali