Lesson 3 of 6
Node functions in practice
8 min
Listen to this lesson
Node functions work on whole queues, not on single values. They insert, remove or reshape context changes, and that makes them the standard fix for the mismatches you found in lesson 2. Cloud Integration offers the same node functions PI/PO developers know, under Node Functions in the Functions pane. Learn what each does to a queue and you can predict the output before you simulate.
| Function | What it does to the queue | Contoso use |
|---|---|---|
| removeContexts | Deletes all context changes, so every value is in one context | One flat list of items from several IDocs in a bulk message |
| splitByValue | Inserts a context change after each value, after each value change, or after each empty value | One target record per value, e.g. one output line per item |
| collapseContexts | Keeps the first value of each context, puts them in one context; empty contexts become empty strings | Create one parent node per source occurrence (with splitByValue) |
| useOneAsMany | Repeats a value that occurs once as often as a field that occurs many times | PO number on every order line |
| createIf | Creates a target node only if the condition is true | Ship-to loop only if a WE partner exists |
| exists | Returns true if the source field is present in the instance | Test for optional segments |
| mapWithDefault | Replaces empty contexts with a default value | Default for a genuinely optional field |
| formatByExample | Takes the values from queue 1 and the context changes from queue 2 (same number of values) | Re-group values to match another field's structure |
| sort / sortByKey | Sorts values within a context; sortByKey sorts value pairs by key | Order lines by item number |
| replaceValue | Replaces the value with one you define in the parameters | Overwrite a value with a constant |
Node functions available in Cloud Integration message mapping, as documented for the SAP mapping runtime.
removeContexts and splitByValue
These two are opposites. removeContexts deletes every context change in the queue: all values move into one context. Use it when the target wants a flat list, for example all items of a bulk message with several IDocs. splitByValue inserts context changes, and its parameter decides where: after each value, after each value change, or after each empty value. Use it when the target needs one parent per value. The pair often appears together: splitByValue(removeContexts(field)) first flattens, then gives each value its own context.
useOneAsMany: one header value on many lines
Lakeside wants a flat order-line file in which every line repeats the PO number. E1EDK01/BELNR occurs once per IDoc; E1EDP01/POSEX occurs once per item. useOneAsMany has three inputs. The first is the value that occurs once per context (BELNR). The second decides how often to repeat it: the item field with its context set to the header's parent (POSEX with context IDOC). The third supplies the context changes for the result (POSEX in its default context). Finish with splitByValue (each value) so each order line gets exactly one value.
Written as an expression, the target field Line/PONumber is splitByValue(useOneAsMany(BELNR, POSEX[context IDOC], POSEX)). SAP's own examples use exactly this pattern: the second argument with its context raised to the level of the field that occurs once, and splitByValue with Each Value on the result. Display Queue on the result should show 4500000187 three times, separated by context changes.
A common error is mismatched queues. The first input must have as many contexts as the second, and the second must have as many values as the third. If the counts differ, the runtime raises an exception or pairs values wrongly. Check all three with Display Queue.
createIf and exists: building optional structure
createIf creates a target node only when its condition is true. Contoso's X12 850 needs an N1 ship-to loop only if the IDoc has an E1EDKA1 segment with partner function WE (ship-to). Map the N1 node from createIf(equalsS(E1EDKA1/PARVW, Constant WE)), with the PARVW context set so all partner segments are tested. exists returns true when a field is present in the instance, which is the usual guard for optional segments.
collapseContexts, mapWithDefault and formatByExample
collapseContexts keeps only the first value of each context and puts all of them into one context. Empty contexts become empty strings. SAP's example combines it with splitByValue(removeContexts(...)) to create exactly one parent node per source item. mapWithDefault fills empty contexts with a default value and is equivalent to if(exists(field), field, Constant). formatByExample takes values from its first queue and the context structure from its second. Both queues must contain the same number of values, or the runtime raises an exception.
- Does the target show only the first group of values?Yes → raise the source context, or use removeContexts · No → next question
- Does a header value appear on the first line only?Yes → useOneAsMany plus splitByValue (each value) · No → next question
- Should a target node exist only in some cases?Yes → createIf with exists or a comparison · No → next question
- Is a target field empty where the source segment is missing?Yes → mapWithDefault only if a default is acceptable to the business · No → check the parent node mapping
- removeContexts flattens a queue; splitByValue inserts context changes (each value, value change or empty value).
- useOneAsMany needs three aligned queues and is usually followed by splitByValue (each value).
- createIf with exists or equalsS builds optional structure such as an N1 ship-to loop.
- mapWithDefault is for optional data only; required data should fail visibly.
Check your understanding · not graded
Lesson check
1. Which node function inserts a context change after each value of a queue?
2. What does the second argument of useOneAsMany determine?
3. A developer maps an optional requested delivery date with mapWithDefault and a fixed date. Why does Priya object?
4. formatByExample raises an exception during simulation. What is the most likely cause?