CPI iFlows
BTP & Integrationintermediate

BTP CPI iFlows Part 4: Message Mapping — Graphical, XSLT or Groovy

Key takeaway

Choose the right mapping technique: graphical message mapping with functions and value mappings, XSLT for XML-to-XML transformations, and Groovy scripts for complex logic or JSON — with guidance on maintainability, performance, testing and reuse.

Explanation

📌 KEY POINTS
✅ Graphical mapping: visual, maintainable for structured XML with clear source/target schemas.

✅ XSLT: powerful for XML transformations, especially restructuring and complex conditions.

✅ Groovy: flexible for JSON, API-style logic and calculations; keep scripts small and reusable.

✅ Value mappings translate codes (e.g. country, unit) centrally.

⚠️ Putting all logic in one huge Groovy script makes flows untestable and hard to support.

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Part 3 covered errors. Now mapping.

━━━━━━━━━━━━━━━━━━━━
▶ 1. GRAPHICAL MAPPING

  • Schemas, functions, UDFs.\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 2. XSLT\n• Templates, XPath.

━━━━━━━━━━━━━━━━━━━━
▶ 3. GROOVY

  • JSON, calculations, helpers.

━━━━━━━━━━━━━━━━━━━━
▶ 4. VALUE MAPPING

  • Code translation.

━━━━━━━━━━━━━━━━━━━━
▶ 5. CHOOSING

  • Team skills, complexity, performance, testability.

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Build a graphical mapping with a value mapping.
  2. Rewrite one part as XSLT.
  3. Compare readability and test.

✅ CHECKPOINT: both produce identical output on test payloads.

Code example

ABAP Code
===== GROOVY (small, focused) =====import com.sap.gateway.ip.core.customdev.util.Messageimport groovy.json.JsonSlurperdef Message processData(Message message) {  def json = new JsonSlurper().parseText(message.getBody(String))  message.setProperty('p_total', json.items.sum { it.qty * it.price })  return message} ===== XSLT (fragment) =====<xsl:template match="/Order"><SalesOrder><Customer><xsl:value-of select="Buyer/ID"/></Customer></SalesOrder></xsl:template> ===== VALUE MAPPING =====Agency S4/Country "DE" ↔ Agency Partner/Country "GER"

Real project scenario

A team put all transformation logic into a 600-line Groovy script; a small change broke unrelated fields. Splitting into graphical mapping for structure and small scripts for calculations made changes safe.

Common mistakes

  • Giant scripts.
  • No simulation.
  • Hard-coded code lists.
  • Loading huge payloads.
  • Copying scripts.

Best practices

  • Right technique per need.
  • Simulate with samples.
  • Value mappings.
  • Watch memory.
  • Script collections.

Interview angle

Questions: "When use graphical vs XSLT vs Groovy?", "What is a value mapping?", "How do you test mappings?"
Strong answer: techniques, value mapping, choice criteria, testing, performance.

Practice this lesson

Quick check

1. Which technique is typically most maintainable for structured XML-to-XML mappings with clear schemas?

2. Which statement correctly describes how a Groovy Script step accesses and modifies the message body in a CPI iFlow?

3. Where should code translations like country or unit codes be maintained in CPI?

Interview questions

1. A 600-line Groovy script handles all mapping and breaks frequently. How do you choose mapping techniques?

Answer it in your own words first, then compare.

2. What are the most important design decisions, trade-offs, and best practices in CPI iFlows?

Answer it in your own words first, then compare.

Practice more with Interview AI →

Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.

More lessons in this topic

Interview questions on this topic

Related SAP topics