The Collapse Context and Remove Context functions are two node functions provided by the standard Graphical Message Mapping feature in SAP Integration Suite (CPI) and SAP PI/PO. Node Functions ‘Collapse Context’ and ‘Remove Context’ can be confusing if you are new to the integration space. Although Collapse Context and Remove Context have similarities, there are a few major differences between them.
The Collapse Context and Remove Context functions work exactly the same in platforms, SAP Integration Suite (CPI) and PI/PO.
What is “Context” in SAP Integration Suite (CPI) and PI/PO Mapping?
Before we look at the differences between Collapse Context and Remove Context, let’s look at what a ‘Context’ in the Graphical Mapping feature of SAP Integration Platforms means.
XML messages in SAP PI/PO/CPI are handled as Queues. In a queue, Context is the position or the level of an XML node (element) relative to a parent node.
If elements belong to the same parent node, the elements are in the same Context. When the parent node changes, Context Change is inserted into the queue. Context Changes are shown in dark grey color.
Therefore, when we talk about the Context of a message it is always based on a certain parent node. An XML element can have different Context queues depending on the parent node it is related to.
Let’s use the Message Type below to understand Context Changes and Node Functions.
XML can have multiple exam grades of multiple students.
-
Element ‘Grade’ context changes based on immediate parent node ‘Grades’.
Grade values of each exam are assigned to separate Contexts.
-
Element ‘Grade’ Context Changes based on higher level parent node ‘StudentDetail’.
Now all grades of each student are in one Context.
Collapse Context vs Remove Context.
Although the two node functions behave differently, both Collapse Context and Remove Context delete the Context Changes from the input queue.
1. How Context Values are Copied in Collapse and Remove Context.
The major difference between these two functions is how they copy input Context values to the output. While Collapse Context only copies the first value of each Context from the input, Remove Context copies all the values from the input to the output.
Collapse Context |
Remove Context |
Only first value of each context is copied to the output. | All values form input context are copied to the output. |
2. How SUPPRESS Values Are Interpreted by Collapse Context and Remove Context When “Keep SUPPRESS Values” Are Disabled.
Let’s look at how each function acts when “keep SUPPRESS values” property of IF-THEN function is disabled.
Another difference is how these node functions handle SUPPRESS values in queues. While Remove Context ignores the SUPPRESS values and does not copy them to output, Collapse Context copies them as null [] values to output.
Collapse Context copies SUPPRESS Values as [].
Remove Context ignores SUPPRESS Values.
3. How SUPPRESS Values Are Interpreted by Collapse Context and Remove Context When “Keep SUPPRESS Values” Is Activated.
In this situation both functions handle SUPPRESS values the same way. SUPPRESS values are considered similar to any other value in the same context.
Both functions remove the Context Changes. The collapse Context function copies the first value from each Context, and Remove Context copies all values of each context to output.
You can only remove these SUPPRESSED values using a UDF.
Although in this example I use SAP PI/PO, in SAP Integration Suite the functions behaves the same way. The concept remains the same in SAP CPI.
If you have any questions about Collapse Context and Remove Context node functions, please, leave a comment below. I will be happy to help.
Good work. please keep more topics related to PI/PO
Thank you!
Hi ,
Nice explanation for Remove context and collapse context.
I have one doubt not related to this topic
How to use Exchange fault message in SAP PI/PO in sync and async scenarios while using proxy scenarios.
Thanks.
Hi Sai,
Fault message assigned in the PI interface will be visible in the ABAP Proxy class as an exception class. Raise expectations in the ABAP proxy class using the this exception class. You can use the syntax RAISE EXCEPTION.
Hi Isuru,
Can you provide any step by step process.
Thanks.
Thanks.
Can you explain about use one as many and map with default value. Context object, x- path .
Do you have any real scenarios as to when to use remove or collapse context?
Nice and very helpful post. Please keep posting 🙂
Thank you Akshay! 😊
Thank you for your sharing, nice and helpful article for SAP PIPO
Thank you, Bang! 🙂
Thank you so much for the information you have provided. It is very much helpful to not only me but to many like me.
Thank you very much, Syed!