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.
formatByExample_MM
The objective of the mapping is to convert below test source data (flat data) and target data (tree data):
formatByExample_before_after

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.
formatByExample_queue_Category_explain

 

For field CatID and CatName, follow above similar way to map, and add additional SplitByValue [Each value].
formatByExample_queue_CatID_CatName

 

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.
formatByExample_queue_Book_explain
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.
formatByExample_queue_BookID      formatByExample_queue_BookName

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

8 thoughts on “collapseContext and formatByExample to Convert Flat Structure to Tree Structure

  • January 20, 2015 at 5:39 pm
    Permalink

    Your post helped me a lot in getting clear understanding of tricky node functions.

    Thanks.

    Regards,
    Ajit

    Reply
  • January 23, 2015 at 12:40 pm
    Permalink

    Thank you very much Clearly explained.Keep Posting

    Reply
  • January 31, 2015 at 5:54 pm
    Permalink

    Hi Ajit, Pavan,
    Thanks. Once we understand those tricky node functions, it could be very useful. 🙂

    Regards,
    Yee Loon

    Reply
    • June 13, 2015 at 1:31 am
      Permalink

      Exactly, once you get it right. you can achieve the complex mapping easily. Thank you for making it easy.

      Reply
  • October 21, 2015 at 7:14 pm
    Permalink

    Great post, info clear and concise. SAP training should be more like this.

    Reply
    • October 22, 2015 at 10:36 am
      Permalink

      Hi Younesse,

      Thanks. Glad to hear that 🙂

      Regards,
      Yee Loon

      Reply
  • July 11, 2017 at 3:43 pm
    Permalink

    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.

    Reply
  • July 27, 2017 at 9:19 pm
    Permalink

    Excellent post sir..it is very clear

    Reply

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.