Mapping changes data from the sender's structure to the receiver's. Cloud Integration gives you several tools. Choose the simplest one that does the job.
| Tool | Best for |
| Message Mapping | Graphical XML-to-XML mapping with source and target structures (XSD, WSDL, EDMX). Most common. |
| XSLT Mapping | Complex XML restructuring, grouping and sorting. |
| Groovy Script | Logic that steps cannot express: calculations, custom formats, dynamic values, logging. |
| Value Mapping | Translating codes between systems, such as country or unit codes, in a separate artifact. |
Groovy in practice
Every script receives the message and returns it. You can read and set body, headers and properties, and add searchable values to the message log:
import com.sap.gateway.ip.core.customdev.util.Message
import groovy.json.JsonSlurper
def Message processData(Message message) {
def order = new JsonSlurper().parse(message.getBody(java.io.Reader)).order
message.setProperty("orderId", order.id)
message.setHeader("SAP_ApplicationID", order.id) // searchable in monitoring
messageLogFactory.getMessageLog(message)?.addCustomHeaderProperty("Customer", order.customer)
return message
}
Good practice · Read large bodies as a stream (java.io.Reader), not as one big String, to save memory. Never log full payloads with personal data in production.
Reusing scripts and mappings
Put shared Groovy functions, mappings and value mappings in a script collection or reusable artifact in the package, so several iFlows use one version.
Contexts and queues: the key to mapping
The graphical mapping does not process one value at a time. It processes queues: all values of a source field, in order. The values are grouped into contexts, and by default a field's context is its parent node. If two orders each have items, the item numbers arrive as one queue with a context change between the first order's items and the second order's items.
Queue for /Orders/Order/Item/ItemNo1020context change10
Most mapping problems ("only the first item is mapped", "values end up under the wrong parent") are context problems. Use Display Queue in the mapping simulation to see the queue of any field or function output. You can also change a source field's context by right-clicking it and choosing a higher parent node.
A value can also be SUPPRESS, meaning "no value here", which is different from an empty string. Node functions are the tools for reshaping queues and contexts.
Every node function, with an example
Each card shows the mapping as you would draw it in the editor (source on the left, function in the middle, target on the right) and what the queue looks like before and after.
createIfcreateIf(condition)
Creates the target node only when the input is true. When it is false, the target node is not created at all.
Use it to: Create a segment or element only in certain cases, for example a Partner node only for B2B orders.
Input: OrderTypeB2Bcontext changeB2C
Outputtruecontext changefalse
ResultPartner is created for the first order only
removeContextsremoveContexts(values)
Removes all context changes, so every value ends up in one single context.
Use it to: Collect values that sit under different parents into one list, for example all item numbers of all orders.
Input1020context change10
replaceValuereplaceValue(values) — parameter: value
Replaces every value with the fixed value you set, but keeps the number of values and the context structure.
Use it to: Create one target node per source occurrence when the source value itself is not needed, or set a constant per record.
existsexists(node)
Returns true if the source field exists in the context, otherwise false. One result per context.
Use it to: Check if an optional field was sent before mapping it, often combined with if or createIf.
Input (2 customers)a@x.comcontext change(empty)
Outputtruecontext changefalse
splitByValuesplitByValue(values) — each value | value change | empty value
Inserts context changes into a queue. Each value: after every value. Value change: whenever the value differs from the previous one. Empty value: where an empty value appears.
Use it to: Create one target parent per value, or group sorted records by a key such as customer number.
Output (value change)C1C1context changeC2
Output (each value)C1context changeC1context changeC2
collapseContextscollapseContexts(values)
Takes the first value of every context and puts them all into one context. An empty context becomes an empty value, so positions stay aligned.
Use it to: Get exactly one value per parent, e.g. the first phone number of each customer, as one flat list.
Input111222context change333context change(empty)
useOneAsManyuseOneAsMany(value, count, structure)
Repeats a value as many times as another field occurs. Input 1 is the value (one per context), input 2 decides how many times, input 3 gives the context structure of the result.
Use it to: Copy a header value, such as the order number, onto every item line.
Input 1: OrderNo1001context change1002
Input 2 and 3: Itemi1i2context changei3
Output10011001context change1002
sortsort(values) — ascending/descending, lexical/numeric
Sorts the values inside each context. Choose ascending or descending and lexical or numeric comparison.
Use it to: Order lines by item number, or prepare values for splitByValue (value change).
sortByKeysortByKey(key, value)
Sorts the value queue using a second queue as the sort key. Both queues must have the same number of values.
Use it to: Sort item descriptions by item number, while mapping only the descriptions.
mapWithDefaultmapWithDefault(value) — parameter: default
Passes values through, but replaces missing (suppressed) values with a default, so the target field is always filled.
Use it to: Mandatory target fields where the source is optional, e.g. a currency that defaults to EUR.
copyValuecopyValue(values) — parameter: position
Returns the value at a given position of a repeating field. Position 0 is the first occurrence.
Use it to: Take a specific occurrence, e.g. the second address line, from a repeating source field.
InputMain St 1Building BFloor 3
getPropertygetProperty() — parameter: property name
Reads an exchange property from the iFlow into the mapping.
Use it to: Bring in values computed earlier, like a lookup result or the target system ID, without putting them in the payload.
Property value at runtimeCRM_PROD
The other function categories
| Category | Functions | Typical use |
| Arithmetic | add, subtract, multiply, divide, abs, round, ceil, floor, max, min, sqrt, power, formatNumber, counter | Totals, unit conversions, number formats |
| Boolean | and, or, not, equals, notEquals, if, ifWithoutElse, isNil | Conditions for if and createIf |
| Constants | constant, sender, receiver | Fixed values and the sender or receiver name |
| Conversions | fixValues, valueMapping | Code translation inside the mapping or from a value mapping artifact |
| Date | currentDate, dateTrans, dateBefore, dateAfter, compareDates | Changing formats such as yyyyMMdd to yyyy-MM-dd |
| Statistic | sum, average, count, index | Line counts, totals, numbering items 1, 2, 3 |
| Text | concat, substring, equalsS, indexOf, lastIndexOf, compare, replaceString, length, startsWith, endsWith, toUpperCase, toLowerCase, trim | Building names, cutting codes, comparing text |
| Custom (Groovy) | Your own script functions | Logic no standard function covers |
Custom functions in Groovy
When no standard function fits, add a script function to the mapping. A simple function works on one value at a time. For queue-based logic, which works on all values and contexts at once, declare Output and MappingContext parameters:
import com.sap.it.api.mapping.*
// Single value: called once per value
def String toSapDate(String isoDate) {
return isoDate?.replace("-", "") // 2026-10-17 -> 20261017
}
// Queue-based: gets all values of the context at once
def void lastValue(String[] values, Output output, MappingContext context) {
if (values.length > 0) output.addValue(values[values.length - 1])
}