SAP CPI Message mapping Flat Structure to Tree structure which has been briefly explained by Eaksiri Sontisirikul in on the blog. It is a great blog. Thanks Eaksiri.

I was trying expand the payload bit complex and came up with some additional mapping steps.

So I decided to share those information below.

Request payload.

<CompoundEmployee>
	<Person>
		<Manager_ID>1000</Manager_ID>
		<Manager_Name>Manager A</Manager_Name>
		<Employee_ID>8000</Employee_ID>
		<Employee_Name>Emp A</Employee_Name>
	</Person>
	<Person>
		<Manager_ID>1000</Manager_ID>
		<Manager_Name>Manager A</Manager_Name>
		<Employee_ID>8005</Employee_ID>
		<Employee_Name>Emp B</Employee_Name>
	</Person>
	<Person>
		<Manager_ID>2000</Manager_ID>
		<Manager_Name>Manager B</Manager_Name>
		<Employee_ID>9000</Employee_ID>
		<Employee_Name>Emp C</Employee_Name>
	</Person>
	<Person>
		<Manager_ID>2000</Manager_ID>
		<Manager_Name>Manager B</Manager_Name>
		<Employee_ID>9002</Employee_ID>
		<Employee_Name>Emp D</Employee_Name>
	</Person>
	<Person>
		<Manager_ID>1000</Manager_ID>
		<Manager_Name>Manager A</Manager_Name>
		<Employee_ID>9003</Employee_ID>
		<Employee_Name>Emp E</Employee_Name>
	</Person>
	<Person>
		<Manager_ID>3000</Manager_ID>
		<Manager_Name>Manager C</Manager_Name>
		<Employee_ID>9004</Employee_ID>
		<Employee_Name>Emp F</Employee_Name>
	</Person>
	<Person>
		<Manager_ID>2000</Manager_ID>
		<Manager_Name>Manager B</Manager_Name>
		<Employee_ID>9005</Employee_ID>
		<Employee_Name>Emp G</Employee_Name>
	</Person>
</CompoundEmployee>

Response Payload

<CompoundEmployee>
	<Person>
		<Manager_ID>1000</Manager_ID>
		<Manager_Name>Manager A</Manager_Name>
		<Employee>
			<Employee_ID>8000</Employee_ID>
			<Employee_Name>Emp A</Employee_Name>
		</Employee>
		<Employee>
			<Employee_ID>8005</Employee_ID>
			<Employee_Name>Emp B</Employee_Name>
		</Employee>
		<Employee>
			<Employee_ID>9003</Employee_ID>
			<Employee_Name>Emp E</Employee_Name>
		</Employee>
	</Person>
	<Person>
		<Manager_ID>2000</Manager_ID>
		<Manager_Name>Manager B</Manager_Name>
		<Employee>
			<Employee_ID>9000</Employee_ID>
			<Employee_Name>Emp C</Employee_Name>
		</Employee>
		<Employee>
			<Employee_ID>9002</Employee_ID>
			<Employee_Name>Emp D</Employee_Name>
		</Employee>
		<Employee>
			<Employee_ID>9005</Employee_ID>
			<Employee_Name>Emp G</Employee_Name>
		</Employee>
	</Person>
	<Person>
		<Manager_ID>3000</Manager_ID>
		<Manager_Name>Manager C</Manager_Name>
		<Employee>
			<Employee_ID>9004</Employee_ID>
			<Employee_Name>Emp F</Employee_Name>
		</Employee>
	</Person>
</CompoundEmployee>

Simulation

To obtain this result we have to adapt our mapping with ‘sort’, ‘sortByKey’ functions in between.

The Employee_ID, Employee_Name need additional mapping steps too.

 

CompoundEmployee

CompoundEmployee

Person

Manager_ID > removeContext 
           > Sort(case sensitive,asc) 
           > SplitByValue (value change) 
           > collapseContext 
           > Person

Person1

Person2

Person3

 

Manager_ID

Manager_ID > Removecontext 
           > sort(case sencitive, asc) 
           > SplitByValue (value change) 
           > collapseContext 
           > splitByValue 
           > Manager_ID

Manager_ID

 

Manager_Name

Manager_Name1

Manager_Name > removeContext 
             > sort (case sensitive, asc) 
             > splitByValue (Value change) 
             > collapseContext 
             > splitByValue (Each value ) 
             > formatByExample(input) 
             > Manager_Name

Manager_ID > removeContext 
           > sort (case sensitive, asc) 
           > splitByValue (Value change) 
           > collapseContext 
           > splitByValue (Each value ) 
           > formatByExample(pattern) 
           > Manager_Name

Manager_Name2

 

Employee

Employee_ID > formatByExample (input)
            > Employee

Manager_ID > removeContext 
           > sort (case sensitive, asc) 
           > splitByValue (Value change) 
           > formatByExample (pattern) 
           > Employee

Employee1

 

Employee_ID

Manager_ID > removeContext 
           > sortByKey(key) 
           > splitByValue(Each value) 
           > Employee_ID

Emoloyee_ID > removecontext 
            > sortByKey(value)
            > Employee_ID

Employee_ID

 

Employee_Name

Same mapping as above with Employee_NameEmployee_name

 

Happy reading.

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x