“Grouping” Option of Iterating/General Splitter
Introduction
In this blog, I am going to describe the behavior of the Grouping input field of the Iterating/General Splitter and show what happens if it is followed by a Gather step.
Grouping
In each splitter step, you can group nodes into chunks. If you enter “2” in the Grouping field, then each chunk will contain two splits. The last chunk will contain the remainder of the payload.
Let’s look at an example:
In the Content Modifier of this scenario, we define the message body as follows:
<root>
<x>
<y>
<z id="1">1</z>
<z id="2">2</z>
<z id="3">3</z>
<z id="4">4</z>
<z id="5">5</z>
<z id="6">6</z>
</y>
</x>
</root>
If the General Splitter splits this payload with the XPath expression “//z”, then six chunks are created.
The first chunk looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>
<y>
<z id="1">1</z>
</y>
</x>
</root>
If you set the Grouping value to 2, then three chunks are created. The first chunk looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>
<y>
<z id="1">1</z>
<z id="2">2</z>
</y>
</x>
</root>
If you set the Grouping value to 4, then the first chunk contains four z-nodes and the second chunk contains the remaining two z-nodes.
Please note that the General Splitter preserves all nodes up to the split point. This produces well-formed XML.
If we replace the General Splitter with an Iterating Splitter, the first chunk looks like this (Grouping=2):
<?xml version="1.0" encoding="UTF-8"?>
<z id="1">1</z>
<z id="2">2</z>
Please note that this chunk is not well-formed XML because there is no root tag.
Splitter and Gather
In the following scenario, we have an Iterating Splitter followed by a Gather step.
If you deploy this integration flow, the following error occurs:
This is because the XML that the Gather step receives is not well-formed.
On the other hand, if the integration flow has a General Splitter followed by a Gather step, then it can be deployed. If the Grouping value is 2, the output looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<multimap:Messages xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
<multimap:Message1>
<root>
<x>
<y>
<z id="1">1</z>
<z id="2">2</z>
</y>
</x>
</root>
<root>
<x>
<y>
<z id="3">3</z>
<z id="4">4</z>
</y>
</x>
</root>
<root>
<x>
<y>
<z id="5">5</z>
<z id="6">6</z>
</y>
</x>
</root>
</multimap:Message1>
</multimap:Messages>
Conclusion
We have seen that it is not possible to use an Iterating Splitter followed by a Gather step if the Grouping value is greater than 1. In this case, the XML produced by the Iterating Splitter is not well-formed and the Gather step fails.
Further Readings
For more configuration recommendations with respect to the Splitter also check out the following blogs: