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:
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.
Following figure shows the OrderHeader context. Context change is inserted after every occurrence of OrderHeader.
Similarly, using the Customer context, inserts a context change after every occurrence of Customer.
If the Orders context is used, no context changes will be inserted as Orders is at the highest level in the hierarchy.
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:
- 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).
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.
very interesting, but I don’t agree with you
Idetrorce
Hi Idetrorce, I would appreciate if you could briefly describe what you do not agree on?
Thanks.
Regards,
Riyaz
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
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
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
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.
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
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.
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.
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
Hi Riyaz
I just want to thank you for the good job you are doing.
best regards
Thanks Fadel for your kind compliments.
Regards,
Riyaz
very good!thanks!
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
Hi Naga,
We are offering Online as well as physical training for XI/PI..Let me know if u r interested.
Thanks.
Hello webmaster
I would like to share with you a link to your site
write me here preonrelt@mail.ru
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
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?
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.
I am new to XI. Thank you so much for your help. Works quite well now.
Cindy
For online training in SAP XI /PI and MDM please log to http://www.sap-advisors.com/.
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
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.
Hi Riyaz,
Thanks…
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?
Hi Riyaz,
I am trying to implement your scenario that you explained above, while doing the message mapping testing when i create multiple instances of OrderData i am getting the following error when i execute.
Too many values in the second queue in function useOneAsMany. The number of values for all contexts must be the same as the number of values for the third queue] in class com.sap.aii.mappingtool.flib7.NodeFunctions method useOneAsMany
Sorry, Ignore the comments here, it is the wrong blog i posted my comments.
Hi,
I was not aware if this site. Its a good one. it also good suggestion to people. I’m a frequent visitor of http://ezsap.com/ which by the way is my favorite.
Hi Riyaz,
could you plz help me determine what would be the process to bring Pricing data from Vendao to ECC6 through PI?
Many Thanks in Advance
aslkm,
This is rahim i want some sample resumes regarding of sap pi plz send to my mail id
rahimb4u@gmail.com.
Thanking you
Very well written as well as all your posts that I have read so far – been into PI lately and they have been so far a valuable tool in order to understand the platform – thanks & keep p the good work!