Dear Reader,
This blog describes all about General Splitter in sap cpi. Several options are available in the general splitter and I will be discussing all of it in detail here with simple example.
Use of Splitter and General Splitter:
The splitter is used to split the bulk message into a small chunk. General Splitter splits the message into N parts based on configured conditions provided in the general splitter.
We have a total of 6 types of the splitter as of Today in CPI. These are as below.
Navigate to
Pallet-----> Routing-----> Splitter

Types of Splitter in CPI
I will jump into example and explain all parameters in detail. Let's assume below is the input payload and I want to split this based on the id.
Example 1:
How to use absolute and relative XPath expression
<?xml version='1.0' encoding='UTF-8'?>
<root>
<record>
<name>A</name>
<items>
<id>1</id>
<id>2</id>
</items>
</record>
</root>
Iflow would be as below. configure receiver mail and timer for simplicity.

Keep Example 1 input payload in Body of content modifier and start configuring General Splitter.

Expression Type:
Use
XPath for xml input. For non-xml input use
Line Break.
XPath Expression:
Here you will specify the path on which split should happen.
You can specify this in two way.
Relative XPath expression:
It starts with "//". This is the easy way to specify the path.
XPath = //id
It will split the Example 1 input XML as many times as id is found in XML. In my example id is coming two times so it will split into two times as output 1 and output 2 as below.
<?xml version='1.0' encoding='UTF-8'?>
<root>
<record>
<name>A</name>
<items>
<id>1</id>
</items>
</record>
</root>
output 1
<?xml version='1.0' encoding='UTF-8'?>
<root>
<record>
<name>A</name>
<items>
<id>2</id>
</items>
</record>
</root>
Output 2
Absolute XPath expression:
Here you need to provide the full path.
XPath = /root/record/items/id
You will get the same output 1 and output 2 as an output.
Example 2:
<id> appearing in two different node
<?xml version='1.0' encoding='UTF-8'?>
<root>
<record>
<name>A</name>
<items>
<id>10</id>
<id>20</id>
</items>
<details>
<id>30</id>
<id>40</id>
<id>50</id>
</details>
</record>
</root>
Now id is coming in two node. items and details
Case 1
XPath = "/id
it will split the Example 2 input xml into 5 parts.
Case 2
XPath = /root/record/items/id
OR
XPath = //items/id
(Both are same)
it will split the Example 2 input XML into 2 parts, contains the items as a parent
Use Absolute XPath expression to choose which id node you want to split (items OR details).
Example 3:
xml containing namespace
<?xml version='1.0' encoding='UTF-8'?>
<root xmlns="http://abc.com">
<record>
<name>A</name>
<items>
<id>10</id>
<id>20</id>
</items>
<details>
<id>30</id>
<id>40</id>
<id>50</id>
</details>
</record>
</root>
To split the Example 3 message, you need to define a namespace mapping (of a prefix and a namespace) for the integration flow (under Runtime Configuration)
for example
xmlns:p1=http://abc.com

XPath = /p1:root/p1:record/p1:items/p1:id
You will get two output: output1 and output 2 (see above)
Example 4:
Split output xml contains only the enveloping element and rest of the element will be ignored
<?xml version='1.0' encoding='UTF-8'?>
<root xmlns="http://abc.com">
<record>
<name>A</name>
<name>B</name>
<items>
<id>10</id>
<id>20</id>
</items>
<details>
<id>30</id>
<id>40</id>
<id>50</id>
</details>
<trailer>
<total>5</total>
<desc>This is trailer </desc>
</trailer>
</record>
</root>
XPath = /p1:root/p1:record/p1:items/p1:id
We use the term
enveloping elements to refer to the elements above and including the split point.
<details> and <
trailer> node are appearing below the split point hence these node will not be the part of output xml.
output 3 and output 4 as below are the output of Example 4 input xml
<?xml version='1.0' encoding='UTF-8'?>
<root xmlns="http://abc.com">
<record>
<name>A</name>
<name>B</name>
<items>
<id>10</id>
</items>
</record>
</root>
output 3
<root xmlns="http://abc.com">
<record>
<name>A</name>
<name>B</name>
<items>
<id>20</id>
</items>
</record>
</root>
output 4
Example 5:
Non xml Input
"Item No", "Description", "Price"
"0001", "Description 1", "120 INR"
"0002", "Description 2", "200 INR"
"0003", "Description 3", "330 INR"
Use Expression type = Line Break

General Splitter interprets the first line of the inbound message as a header or root element. hence splitting starts from 2nd line. Below is the output of Example 5.
"Item No", "Description", "Price"
"0001", "Description 1", "120 INR"
output 5
"Item No", "Description", "Price"
"0002", "Description 2", "200 INR"
output 6
"Item No", "Description", "Price"
"0003", "Description 3", "330 INR"
output 7
Example 6:
Non xml Input, Using Group
"Item No", "Description", "Price"
"0001", "Description 1", "120 INR"
"0002", "Description 2", "200 INR"
"0003", "Description 3", "330 INR"
"0004", "Description 4", "400 INR"
Grouping will group the output xml. I have put the grouping value 2 hence we will get the 2 output instead of 4.

"Item No", "Description", "Price"
"0001", "Description 1", "120 INR"
"0002", "Description 2", "200 INR"
output 8
"Item No", "Description", "Price"
"0003", "Description 3", "330 INR"
"0004", "Description 4", "400 INR"
output 9
Streaming, Parallel Processing and Stop on Exception:

1. Streaming:
Select this checkbox if you want to stream the process of splitting a large composite message.
Selecting this will give you more memory efficient. This will allow your Iflow to split the composite message as a 1st step and then it transfers the split message to the memory.
if you will not select this option then the message is transferred fully to the memory before it is split and processed further. Deactivating streaming is more memory-intensive than activating it.
2. Parallel Processing:
Select this checkbox if you want to enable (parallel) processing of all the split messages at once.

Number of Concurrent Processes: If you have selected
Parallel Processing, the split messages are processed concurrently in threads. Define how many concurrent processes to use in the splitter. The default is 10. The maximum value allowed is 50.
Timeout (in s): Maximum time in seconds that the system will wait for processing to complete before it is aborted. The default value is 300 seconds.
3. Stop On Exception:
Select this option to stop message processing if an exception occurs.
Splitter with Exception Handling
Refer below blog:
https://blogs.sap.com/2018/10/17/cloud-integration-usage-of-general-and-iterating-splitter-with-exce...
Usage of Splitter Flow Steps in Local Process
Refer below blog:
https://blogs.sap.com/2018/02/07/cloud-integration-usage-of-splitter-flow-steps-in-local-process/
Conclusion:
In this blog, you came to know how to use General Splitter in sap CPI. I have tried to cover all options available in General Splitter. How we can use General Splitter for both XML and non-xml messages.