APPROACH OVERVIEW
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def iteratorValue=1;
def body = message.getBody(java.lang.String);
def rows = body.split("\n");
def rowlength = rows.length;
def columnsize = 5;//define the columnsize based on CSV file
def separtedCSVMessages = new String[rowlength];
StringBuilder finalMessage = new StringBuilder();
def separateMessageIterator =0;
def rowsColumnsArray = new String[rowlength][columnsize];
for(int i=0;i<rowlength;i++)
rowsColumnsArray[i] = rows[i].split(";") as String[];
while(iteratorValue<rowlength){
def uniqueIdentifier = rowsColumnsArray[iteratorValue][0];
separtedCSVMessages[separateMessageIterator]= (rowsColumnsArray[iteratorValue] as java.lang.String).trim();
while(iteratorValue+1 <rowlength && rowsColumnsArray[iteratorValue+1][0].equals(uniqueIdentifier)) {
iteratorValue = iteratorValue +1;
separtedCSVMessages[separateMessageIterator] = (separtedCSVMessages[separateMessageIterator] as String) +':'+(rowsColumnsArray[iteratorValue] as String);
if(iteratorValue+1 == rowlength)
break;
}
try {
def temporaryString = (separtedCSVMessages[separateMessageIterator] as String).replace('[', '').replace(']','').replaceAll('\\R','');
finalMessage.append(temporaryString+"\r\n");
} catch(Exception e){
e.printStackTrace();
}
if(iteratorValue < rowlength) {
iteratorValue = iteratorValue + 1;
separateMessageIterator = separateMessageIterator + 1;
}
}
message.setBody(finalMessage.toString());
return message;
}
import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.util.XmlParser
def Message processData(Message message) {
String body = message.getBody(String);
def rows = body.split(":") as String[];
StringBuilder finalMessage = new StringBuilder();
for(int i=0;i<rows.length;i++){
finalMessage.append(rows[i]+"\r\n");
}
message.setBody(finalMessage.toString());
return message;
}
Column1;Column2;Column3;Column4;Column5
Message1;R1C2;R1C3;R1C4;R1C5
Message1;R2C2;R2C3;R2C4;R2C5
Message1;R3C2;R3C3;R3C4;R3C5
Message2;R4C2;R4C3;R4C4;R4C5
Message2;R5C2;R5C3;R5C4;R5C5
Message3;R6C2;R6C3;R6C4;R6C5
Message3;R7C2;R7C3;R7C4;R7C5
Message3;R8C2;R8C3;R8C4;R8C5
Message3;R9C2;R9C3;R9C4;R9C5
Message4;R10C2;R10C3;R10C4;R10C5
Message5;R11C2;R11C3;R11C4;R11C5
Message1, R1C2, R1C3, R1C4, R1C5:Message1, R2C2, R2C3, R2C4, R2C5:Message1, R3C2, R3C3, R3C4, R3C5
Message2, R4C2, R4C3, R4C4, R4C5:Message2, R5C2, R5C3, R5C4, R5C5
Message3, R6C2, R6C3, R6C4, R6C5:Message3, R7C2, R7C3, R7C4, R7C5:Message3, R8C2, R8C3, R8C4, R8C5:Message3, R9C2, R9C3, R9C4, R9C5
Message4, R10C2, R10C3, R10C4, R10C5
Message5, R11C2, R11C3, R11C4, R11C5
Message1, R1C2, R1C3, R1C4, R1C5:Message1, R2C2, R2C3, R2C4, R2C5:Message1, R3C2, R3C3, R3C4, R3C5
Message1, R1C2, R1C3, R1C4, R1C5
Message1, R2C2, R2C3, R2C4, R2C5
Message1, R3C2, R3C3, R3C4, R3C5
<?xml version='1.0' encoding='UTF-8'?><MT_XML><rs><r><C1>Message1</C1><C2> R1C2</C2><C3> R1C3</C3><C4> R1C4</C4><C5> R1C5</C5></r><r><C1>Message1</C1><C2> R2C2</C2><C3> R2C3</C3><C4> R2C4</C4><C5> R2C5</C5></r><r><C1>Message1</C1><C2> R3C2</C2><C3> R3C3</C3><C4> R3C4</C4><C5> R3C5</C5></r></rs></MT_XML>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |