The Difference Between Collapse Context and Remove Context in SAP PI/PO

Node Functions ‘Collapse Context’ and ‘Remove Context’ can be confusing if you are new to PI/PO space. Although Collapse Context and Remove Context have similarities, there are a few major differences between them.

 

What is a Context in PI?

Before we look at the differences between Collapse Context and Remove Context, let’s look at what a ‘Context’ in PI/PO means.

XML messages in PI are handled as Queues. In a queue, Context is the position or the level of a XML node (element) relative to a parent node. If elements belong to the same parent node, the elements are in same Context. When the parent node changes, Context Change is inserted to the queue. Context Changes are shown in dark gray color.

Context change shown in dark gray in Graphical Mapping queue
Context change shown in dark gray in Graphical Mapping queue

Therefore, when we talk about 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.

Message type which represent the student grade detail in ESR
Message type which represents the student grade detail

 

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.

Context Changes of 'Grade' element relative to parent node 'Grades'
Context Changes of ‘Grade’ element relative to parent node ‘Grades’

 

  • Element ‘Grade’ Context Changes based on higher level parent node ‘StudentDetail’.

Change the Context of the element to 'StudentDetail' level. Right click on element and select Context.
Change the Context of the element to ‘StudentDetail’ level.

 

Now all grades of each student are in one Context.

Context Changes of 'Grade' element relative to parent node 'Grades'
Context Changes of ‘Grade’ element relative to parent node ‘Grades’

 

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 first value of each Context from the input, Remove Context copies all the values from the input to 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.
Collapse Context, copy only first value from each context to the output Remove Context copy all the values from the input Context to 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.

Keep SUPPRESS values property is disabled in IF-THEN function
Keep SUPPRESS values property is disabled in IF-THEN function

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 [].
Collapse Context copy SUPPRESS values as null [] values to output.
Collapse Context copies SUPPRESS values as null [] values to output.
Remove Context ignores SUPPRESS Values.
Collapse Context function ignore the SUPPRESS values
Collapse Context function ignores SUPPRESS values

 

3. How SUPPRESS Values Are Interpreted by Collapse Context and Remove Context When “Keep SUPPRESS Values” Is Activated.

Keep SUPPRESS values of IF function is active
Keep SUPPRESS values of IF function is active

 

In this situation both functions handle SUPPRESS values the same way. SUPPRESS values are considered similar to any another value in the same context.

Both functions remove the Context Changes. Collapse Context function copies the first value from each Context, and Remove Context copies all values of each context to output.

Collapse Context when Keep SUPPRESS values is activated
Collapse Context when “Keep SUPPRESS values” is activated

 

Remove Context queue when Keep SUPPRESS values is disabled
Remove Context queue when “Keep SUPPRESS values” is disabled

You can only remove these SUPPRESSED values using a UDF.

If you have any questions about Collapse Context and Remove Context node functions, please, leave a comment below. I will be happy to help.

7 Comments

Add a Comment

Your email address will not be published. Required fields are marked *