
202310FABCDX 01TEST123 4530450801000100000002825999010152023
202310FABCDF 01TEST456 3530150801000100000014582444010152023
202310FABCDA 01TEST789 5530250801000100000023264182710152023
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<Record>
<Date>202310</Date>
<Mat>FABCDX</Mat>
<PO>01TEST123</PO>
<GRP1>453</GRP1>
<GRP2>045</GRP2>
<GRP3>0801</GRP3>
<GRP4>0001</GRP4>
<AMT>000000028259990</AMT>
<CRDT>10152023</CRDT>
</Record>
<Record>
<Date>202310</Date>
<Mat>FABCDF</Mat>
<PO>01TEST456</PO>
<GRP1>353</GRP1>
<GRP2>015</GRP2>
<GRP3>0801</GRP3>
<GRP4>0001</GRP4>
<AMT>000000145824440</AMT>
<CRDT>10152023</CRDT>
</Record>
<Record>
<Date>202310</Date>
<Mat>FABCDA</Mat>
<PO>01TEST789</PO>
<GRP1>553</GRP1>
<GRP2>025</GRP2>
<GRP3>0801</GRP3>
<GRP4>0001</GRP4>
<AMT>000000232641827</AMT>
<CRDT>10152023</CRDT>
</Record>
</Root>
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import groovy.xml.*
import com.sap.it.api.ITApiFactory;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message)
{
//Body
def body = message.getBody(java.lang.String) as String;
def lines = body.split("\n");
//root node
def body1 = "<Root>";
//Get the XML segments name and Field fixed lengths
def prop = message.getProperties();
def Segments = prop.get("xmlSegments").split(",") as String[]
def FieldFixedLengths = prop.get("FieldFixedLengths").split(",") as String[]
//looping to read the lines and form a XML
for (i = 0; i < lines.length; i++)
{
def sum = 0
body1 += "<Record>";
//looping through externalized parameters to create XML tag with fixed lengths
for (k = 0; k < FieldFixedLengths.length; k++)
{
def l2 = Integer.valueOf(FieldFixedLengths[k]);
println("Start" + sum + "End" + l2)
body1 += "<" + Segments[k] + ">" + lines[i].substring(sum, sum + Integer.valueOf(FieldFixedLengths[k])) + "</" + Segments[k] + ">";
sum += Integer.valueOf(FieldFixedLengths[k]);
}
body1 += "</Record>";
}
//closing root note
body1 += "</Root>";
//storing the converted XML to body
message.setBody(body1);
return message;
}
Simulation Results for Flat File to XML with Field Fixed Length conversion
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |