Previous post useOneAsMany explained in easy example used an example to convert tree structure into flat structure by using useOneAsMany. This post will do the reverse, convert flat structure back to tree structure.
The source message type is flat structure. The target message type is tree structure. This mean Category, CatID, CatName need to be grouped based on same value. Book, BookID and BookName need to placed under corresponding Category.
The objective of the mapping is to convert below test source data (flat data) and target data (tree data):
Firstly, map the first element in target message type, which is “Category” field. Below transformed queue with 6 values and 6 contexts, into queue with 3 values and single context.
For field CatID and CatName, follow above similar way to map, and add additional SplitByValue [Each value].
For field Book, use formatByExample to get correct context changes for each category. Example: values B1,B2,B3 under single context will group and place these 3 books under first category C1.
For field BookID and BookName, use directly one-to-one mapping only. This is because source fields have a context change, and for each target fields under Book group also always have a context change.
Done. We completed the mapping!
The technique and tips in these 2 posts to convert tree structure to flat structure and vice-versa, should be useful to tackle actual mapping development that involved different hierarchy levels. Enjoy!
collapseContext and formatByExample to Convert Flat Structure to Tree Structure
Your post helped me a lot in getting clear understanding of tricky node functions.
Thanks.
Regards,
Ajit
Thank you very much Clearly explained.Keep Posting
Hi Ajit, Pavan,
Thanks. Once we understand those tricky node functions, it could be very useful. 🙂
Regards,
Yee Loon
Exactly, once you get it right. you can achieve the complex mapping easily. Thank you for making it easy.
Great post, info clear and concise. SAP training should be more like this.
Hi Younesse,
Thanks. Glad to hear that 🙂
Regards,
Yee Loon
Very nice explanation, it clarifies my doubts and provides clear picture.
My suggestion is after explaining the functionality , it would be great to give some real time requirements as example.
Excellent post sir..it is very clear
Well explained.. Thank you.
If Row1 CatID = C1 , CatName = Parenting
Row2 CatID = C1 , CatName = Parentingggggg
Row3 CatID = C2 , CatName = Computers
then CatName in Target will shift like
Row1 CatID = C1 , CatName = Parenting
Row2 CatID = C2 , CatName = Parentingggggg
Any suggestion to solve this.
and I know that source should collect it.
but we know that worst case can be happen
hello, nice explanation.
May I know how to achieve this but when the target structure has no records to filter but only the Recordset?
Source: (CSV pipe delimited)
MT_XML
Recordset
ShipNum
OrderNum
Target:
XML.XML
–> FILING 1..UNBOUNDED
->HEADER 1.1
ShipNum 0.1
OrderNum 0.1
->Details 1.1
DetailSet 1.unbounded
I don’t know which fields I can use to generate the structure, also I’m required to,
I need to have one one Filing/Header segment per shipment with multiple tags nested underneath, shipment are not equal as the OrderNum and the values are not matching.
any help is very much appreciated!.
This is a great tutorial, and the screenshots really help.
I’ve tried to use this to set up something similar where we take a flat file, and create CONF_ACT1001 IDocs. It works if the source data is sorted by the key I am using, but if it’s not in order, the data moves to the wrong IDocs. I’ve posted a query on answers.sap.com and that has more screenshots, if anyone knows what I’m missing, please let me know! Thanks
Link: https://answers.sap.com/questions/13110260/sap-po-mapcollate-multiple-records-in-a-file-to-si.html
Hello Yee Loon.
Thanks for your post.
I have a problem with convert tree structure if I use attributes in the target structure.
For example,
MT_BOOK_TREE
Category Element
CatID Attribute xsd:string
CatName Attribute xsd:string
Book Element
BookID Attribute xsd:string
BookName Attribute xsd:string
Result:
Book (element) value = BookID (attribute) value
B1
B2
B3
How can I fix it?
B1
B2
B3
Hello Yee Loon.
Thanks for your post.
I have a problem with convert tree structure if I use attributes in the target structure.
For example,
MT_BOOK_TREE
Category Element
CatID Attribute xsd:string
CatName Attribute xsd:string
Book Element
BookID Attribute xsd:string
BookName Attribute xsd:string
Result:
Book (element) value = BookID (attribute) value
B1
B2
B3
How can I fix it?
B1
B2
B3