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

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.

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

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.

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

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.

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.

Encode Message Payload to Base64 on CPI!

How to use Base64 message encoder in SAP Integration Suite.

Subscribe for more

My First Interface on CPI!

Learn how to develop your first iFlow on SAP Integration Suite within 7 minutes!

Subscribe for more

13 thoughts on “The Difference Between Collapse Context and Remove Context in SAP CPI/PI/PO

  1. sai says:

    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.

  2. Syed Shamohammad says:

    Thank you so much for the information you have provided. It is very much helpful to not only me but to many like me.

Leave a Reply

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