In SAP Process Orchestration, 'content conversion' processes XML level 3 elements into CSV format. Note, the fieldNames do not influence the output CSV.
Conversely, in SAP Cloud Integration, the 'CSV to XML converter' generates CSV using the element names from the first record of the input XML. If a new element appears in subsequent records, it will be appended at the end of the line.
This difference in behavior can create challenges in migration projects. For PO interfaces with optional elements, fewer CSV columns are produced, whereas CPI interfaces will append optional fields at the end of the line. To manage these issues, you can use additional message mapping with a one-to-one mapWithDefault, although this will create columns even for optional elements. Another option is to use a Groovy script to create consistent elements (e.g., field1, field2, field3, and so on). Below is an example Groovy script:
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.xml.MarkupBuilder
def Message processData(Message message) {
def stringWriter = new StringWriter()
def xmlBuilder = new MarkupBuilder(stringWriter)
def inputXml = new XmlSlurper().parseText(message.getBody(String))
xmlBuilder.Root {
inputXml.Record.each { record ->
Record {
record.children().eachWithIndex { element, index ->
"field${index + 1}"(element.text())
}
}
}
}
message.setBody(stringWriter.toString())
return message
}You can use a Content Modifier after the 'XML to CSV Converter' if you want to prefix the header with actual field names instead of generic names like field1, field2, field3.
SAP Help Links:-
SAP PO - Converting File Content in a Sender Adapter
SAP Cloud Integration - Configure XML to CSV Converter - "When optional fields exists in the XML, the ordering is maintained in the order when a tag is encountered."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.