XI/PI: Introduction to Context Handling in Message Mapping

Context handling is an important technique to map complex scenarios in XI. This article introduces the basics of context handling using a simple example.

Message mapping in XI works by means of queues. A queue contains an entire XML instance of the source message. Depending on the hierarchy in the source message, different nodes and elements can be categorised into different contexts. All the nodes and elements that belong to the same parent node are said to be in the same context. Hence, the nodes and elements that belong to different parent nodes have to be separated by a context change.

XI provides various node functions for context handling during message mapping. Let us understand the concept of contexts using a simple example. Consider the source message shown below:

image

Elements ItemNumber and MaterialNumber belong to the same parent node OrderItem, and hence are in the same context. Also, node OrderItem and element OrderNumber are under the same parent node OrderHeader, and hence are in the same context. Whereas, as elements ItemNumber and OrderNumber belong to different parent nodes, they fall under different contexts.

Following figure shows the OrderItem context. Context change is inserted after every occurrence of OrderItem. Grey coloured rows correspond to context changes.

image image

Following figure shows the OrderHeader context. Context change is inserted after every occurrence of OrderHeader.

image image

Similarly, using the Customer context, inserts a context change after every occurrence of Customer.

image image

If the Orders context is used, no context changes will be inserted as Orders is at the highest level in the hierarchy.

image image

We can use explicit context selection as shown above or use the node functions available in the Graphical Mapping Editor.

Let us take an example where the use of contexts can be emphasised. In the source message shown above OrderNumber appears only once while OrderItem can occur multiple times within the OrderHeader node. Suppose we want to map OrderNumber multiple times in the target message, such that it is available under the target node corresponding to every sales order item. To do this, we can use the node function called useOneAsMany as described below:

image

  • The first input parameter expects the list of values that we want to propagate to the target message.
  • The second input parameter expects the number of iterations or how many times we want to replicate the value given in the first parameter.
  • The third input parameter is the list of context changes. Depending on this parameter the source values will be propagated to the target after every context change.

Note: For this function to work as expected, the first two parameters must contain the same number of contexts while the last two parameters must contain the same number of values.

In our case, the first parameter is OrderNumber, since we want to assign value of this element to the field in the target structure. Second parameter is OrderItem as it corresponds to the number of times sales order items would occur in the target structure. Note that both these parameters have the same number of contexts (See figure below). The third parameter is ItemNumber, which indicates the number of context changes. ItemNumber uses OrderItem context by default (since, OrderItem is the immediate parent node of ItemNumber). Hence, the value of first parameter will be assigned to the target every time the context change occurs for ItemNumber. Also note that the second and third parameter has the same number of values (See figure below).

image

We can see that the value 1100 (first parameter) has been replicated three times (second parameter) at every context change in third parameter.

There are many other node functions available within the Graphical Mapping Editor to aid the context handling in different scenarios. Graphical Mapping Editor also allows you to write your own functions wherein you can use methods of predefined classes to handle contexts.

This entry was posted in SAP, SAP XI / PI and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.
Around the Web »»

25 Comments

  1. Idetrorce
    Posted December 15, 2007 at 7:16 pm | Permalink

    very interesting, but I don’t agree with you
    Idetrorce

  2. Posted December 25, 2007 at 3:44 pm | Permalink

    Hi Idetrorce, I would appreciate if you could briefly describe what you do not agree on?

    Thanks.

    Regards,
    Riyaz

  3. Naga
    Posted January 29, 2008 at 9:33 pm | Permalink

    Hi Riyaz,

    Do u provide online training in XI Especially in BPM and Perfromance training. and also support for the first project and resume preparation. Let me know if u have interest.

    thank u
    Naga

  4. Posted January 29, 2008 at 10:04 pm | Permalink

    Hi Naga,

    If you are looking for any technical help with respect to XI or on any xi topic in particular, do let me know. I will provide relevant articles on this website which would certainly help you and the community as well. I dint understand your second point w.r.t. support, however, if you need assistance in resume preparation, I would be able to help you through.

    Regards,
    Riyaz

    • Subra Manian
      Posted August 27, 2010 at 10:15 pm | Permalink

      Riyaz,
      I have been trying to setup a conditional Receiver Determination in our environment. This is for implementing standard SAP functionality within the ICH (Inventory Collaboration Hub) for ASN Cancellations. The problem is that the ERP IDoc message type has to be one type for ASN creation, and has to be different for ASN Cancellation. It appears that we need two different Services without Party to allow a Receiver Determination based on the Action code contained in the XML message coming from ICH – one service will cause one type of IDoc to generate and the other will cause the second type of IDoc to get created. The problem I am facing is how to create the second service, when there is only one system (the ERP system will be the same) for the Target. I created the second service as a Business Service, but at run time , I get the message that the Receiver service XXX cannot be converted into an ALE logical system. The Communication channel definition within the Business Service does contain the correct RFC settings. Any idea what I need to change? Thanks for all your postings.

      Subra

  5. Naga
    Posted January 29, 2008 at 11:57 pm | Permalink

    Thank u riyaz, I really appreciate ur reply, could u pls provide articles on Performance Tuning.

    Also,How would one know that he reached 7 on a scale of 10 in XI. Are there some core topics/important topics that need to covered/mastered from both interview point of view as well work point of view, in XI. Also heard that the combination of EP/XI in our resume keeps our phones ringing.

    Also please suggest,
    I though of going into FICO but ended up in XI. Know how to write programs in ABAP and Java but not advanced programmer in either of those two languages. And bit of Webmethods/SAP BC. I still couldnt able to foresee whether I could able to get a gud project.

  6. Posted January 30, 2008 at 10:30 am | Permalink

    I would soon be adding those articles on riyaz.net Blog.

    The best way to master XI is to read, explore and do hands-on practice of configuring different interfaces,scenarios. You cant really speak of core topics, hoever BPM, proxies and mappings are major areas to learn. More advanced topics include adapter module development etc.

    FICO is a non-technical call, while XI is purely technical. If you have a background/experince on financials, accounting , controlling you can certainly try your hand at FICO.

    Regards,
    Riyaz

  7. Karthik
    Posted March 6, 2008 at 12:11 am | Permalink

    Riyaz,
    Could you post an example of sending a File to XI and then XI sends an email to a party based on what is mapped from source message type to the standard Mail message XSD(for emails).?

    If you import the mail message XSD under external definition, is it necessary to create a message interface for the receiver side from XI? Because the imported XSD itself has the WSDL already. If yes, how do I create an interface mapping since there is no target interface on Integration Design?

    Appreciate your help a lot.

  8. Posted March 6, 2008 at 12:49 pm | Permalink

    Hi Karthik,

    Check out these articles about Mail Adapter. This should help you understand the configuration.

    Working with mail adapter with/without parties shouldnt be much different. You can use secure protocols and security parameters in the adapter.

    As regards your second question, you will have to create the message interface. XSD is XML Schema Definition file which defines the data structure. so if you use XSD, you need not create data types and message types. But you must create message interface as it defines the direction of interface.

  9. sankara rao bhatta
    Posted July 19, 2008 at 6:12 pm | Permalink

    Hi Riyaz,

    this is sankar again. I need your help in learning the java mapping. I did not see any article published by you in this web regarding the java mapping. if u have any material or atricle please send them to my id bhattasankar@gmail.com

    I am looking for a beginner examples.not highly complex only the basic concepts.

    thanks
    sankar

  10. Fadel Taha
    Posted July 24, 2008 at 5:16 pm | Permalink

    Hi Riyaz

    I just want to thank you for the good job you are doing.

    best regards

  11. Posted July 24, 2008 at 5:22 pm | Permalink

    Thanks Fadel for your kind compliments.

    Regards,
    Riyaz

  12. Posted September 15, 2008 at 6:57 pm | Permalink

    very good!thanks!

  13. Harish
    Posted January 15, 2009 at 3:30 am | Permalink

    You are amazing.. I just can’t keep stopping myself for praising you.!!
    Keep the good work ..

    I have a question though. What would have happened if we choose third parameter as OrderItem instead of item number?

    Cheers
    Harish

  14. Posted February 14, 2009 at 12:29 am | Permalink

    Hi Naga,

    We are offering Online as well as physical training for XI/PI..Let me know if u r interested.

    Thanks.

  15. Alexwebmaster
    Posted March 3, 2009 at 4:18 pm | Permalink

    Hello webmaster
    I would like to share with you a link to your site
    write me here preonrelt@mail.ru

  16. helmut klinger
    Posted May 30, 2009 at 8:24 pm | Permalink

    Hi Riyaz,
    giving an xml-instance corresponding to the to the context structure above would certainly increase my rating by one star to maximum.
    Thank You
    Helmut

  17. Posted August 14, 2009 at 10:41 pm | Permalink

    Thank you for all your effors Riyaz!

    Could you tell me what I would have to change if it were the Customer Numbers I wanted to use as many times as the item number?

  18. Posted August 15, 2009 at 4:29 pm | Permalink

    The first parameter should be the one you wish to propagate to the target, So this would be the customer number in your case. Second parameter is the number of times you wish to replicate the first parameter. So this could be the item number or order item. You might have to change the context of item number (right click and choose appropriate context) such that both first and second parameters have the same number of contexts. Third parameter again could be the item number or order item. The number of values in the second and third parameter should be same.

  19. Posted August 17, 2009 at 8:55 pm | Permalink

    I am new to XI. Thank you so much for your help. Works quite well now.
    Cindy

  20. Posted September 21, 2009 at 11:58 am | Permalink

    For online training in SAP XI /PI and MDM please log to http://www.sap-advisors.com/.

  21. Mohamed
    Posted October 18, 2009 at 1:05 pm | Permalink

    Hi Riyaz,

    In your mapping,If the context is choosen as “OrderItem”,there is 1 element between each context change.Which element is that?.Also if the context is choosen as “OrderHeader”,what are the elements coming between each context change.
    Please explain how to undersrand this.

    I have made a post regarding message mapping.Would appreciate it ,if you could answer that.
    Thanks
    M

  22. Posted October 18, 2009 at 1:19 pm | Permalink

    Hi,

    You map a source element to a target element. When you right-click the source element, you can choose the context. Default context of any element is the parent node. In the above example, I have shown the context of element ItemNumber. Default context of ItemNumber is OrderItem. In this case a context change is inserted after every occurrence of OrderItem node. Since ItemNumber occurs only once under every OrderItem, a context change will be inserted after every ItemNumber.

    If you now change the context from OrderItem to OrderHeader, context change will be inserted after every occurence of OrderHeader node. Since OrderItem can occur multiple times under OrderHeader, ItemNumber will also occur that many times under OrderHeader. So in this case, multiple ItemNumber elements can occur in a single context.

    Hope this answers your query. Do feel free to revert otherwise.

  23. Mohamed
    Posted October 19, 2009 at 12:22 am | Permalink

    Hi Riyaz,
    Thanks…

  24. Lavi
    Posted July 18, 2010 at 10:31 pm | Permalink

    Hi Riyaz,
    I have been surfing your websites regarding XI. I have started learning XI. I wanted to be strong in the basics of XI. Eg: What is ABAP stack, Java Stack, IS…etc. I need a very detailed explaination of these basics. Could you please help me by providing the link for the very detailed Basic of XI?

Post a Comment

Login with your Facebook or Twitter Account to comment. Alternatively, please fill in the fields marked *.

.

Connect with Facebook

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv Enabled

Subscribe without commenting

GetSocial