Integration Blog Posts
cancel
Showing results for 
Search instead for 
Did you mean: 
RajeshwerRao_G_1
Explorer
726

Introduction

While learning SAP Cloud Integration (CPI), I wanted to work on a practical, real‑time use case rather than a basic file‑based or sample integration. In many real projects, applications need to handle multiple currencies because of global customers, suppliers, and financial transactions.

To understand how CPI handles API‑based synchronous integrations, I decided to build a currency conversion iFlow. The objective was to expose an HTTPS endpoint, call an external currency conversion API, and return the converted amount in a readable format. Along with the happy path, I also wanted to implement proper exception handling, similar to what is expected in real production scenarios.

This blog shares my design approach, iFlow structure, and key learnings from implementing this scenario.


Business Requirement

The requirements I considered while designing this iFlow were:

  • Convert an amount from one currency to another in real time
  • Expose the functionality through a secure HTTPS endpoint
  • Fetch up‑to‑date exchange rates from an external API
  • Return the result in a user‑friendly output
  • Handle errors in a centralized and structured way

This closely mimics real‑world requirements where CPI acts as an integration layer between business applications and external services.


High‑Level Solution Overview

I designed the solution using SAP Cloud Integration following a simple API‑to‑API pattern:

  1. An external system sends a currency conversion request.
  2. CPI receives and processes the request.
  3. CPI calls an external currency conversion API.
  4. CPI formats the response as an HTML output.
  5. In case of any failure, CPI handles errors through an Exception Subprocess and sends notifications.

This approach helped me understand how CPI manages synchronous calls, properties, transformations, and error handling together.


iFlow Design Overview

The iFlow is divided into two main parts:

  • Main Integration Flow – handles the successful processing
  • Global Exception Subprocess – handles errors from any step in the flow

This separation made the design clean and easier to maintain.

I-FLow.

rajeshwerrao_gujja151_0-1774191680651.png


Main Integration Flow – Step‑by‑Step

HTTPS_In

I used an HTTPS sender adapter as the entry point of the iFlow. This allows external systems or tools like Postman to send requests in JSON format.

This step starts the message processing and generates the Message Processing Log (MPL) ID, which is useful for monitoring and troubleshooting.

Why I used it:
Most real‑time integrations in CPI are API‑driven, so HTTPS was the natural choice.

HTTPS sender adapter configuration.

rajeshwerrao_gujja151_1-1774191782850.png

You can choose your own address name. 


JSON2XML_Convert

Since the incoming request is in JSON format, I added a JSON to XML converter. This made it easier to work with the payload in CPI, especially for extracting values using content modifiers or XPath.

Learning:
Converting early helps avoid complications in later steps.


Set_ConvParams (Content Modifier)

In this step, I extracted the source currency, target currency, and amount and stored them as Exchange Properties.

I purposely used properties instead of reading values repeatedly from the payload, as this improves readability and reusability across the flow.

Why I did this:
Using properties keeps later steps independent of payload structure.

Content Modifier (Properties tab)

rajeshwerrao_gujja151_2-1774191956044.pngrajeshwerrao_gujja151_3-1774191984996.png


Call_RateAPI

Here, I used a Request‑Reply pattern to call an external currency conversion API. Since the requirement was to return the converted amount immediately, a synchronous call was necessary.

During testing, I intentionally triggered API errors to verify whether my exception handling was working correctly.

Learning:
Request‑Reply is ideal when immediate responses are required.

 rajeshwerrao_gujja151_4-1774192187115.png


Build_HTML_Result

After receiving the API response, I used a Groovy script to extract the converted amount and build an HTML‑formatted output.

Instead of returning raw JSON or plain text, I formatted the result as an HTML table containing:

  • Source currency
  • Target currency
  • Source amount
  • Converted amount
  • Timestamp (IST)

Why I did this:
HTML output improves readability for users, testers, and demos.

rajeshwerrao_gujja151_5-1774192361692.png


HTTP_Out

Finally, the formatted HTML response is sent back to the caller. This allows the result to be previewed directly in Postman or a browser.

Use case:
This is very helpful during testing and demonstrations without needing a separate UI.


Exception Subprocess – Centralized Error Handling

While building the flow, I realized that handling only the success scenario was not enough. So I implemented a Global Exception Subprocess to handle failures consistently.

Err_Start

This step is triggered automatically whenever an error occurs in any part of the main flow, such as:

  • API failures
  • Groovy errors
  • Payload or conversion issues

Err_Build_HTML

In this step, I extracted error details such as:

  • MPL ID
  • Error type
  • Error message
  • Timestamp

I formatted these details into an HTML table, similar to the success response. This made the error output structured and easy to understand.

Learning:
Readable error messages save a lot of troubleshooting time.


Mail_Out_Err

I added a Mail adapter to send the formatted error details to a support email ID. This ensures that failures are noticed immediately without checking CPI logs manually.

Real‑world relevance:
This is commonly used in production environments for monitoring.


Err_End

The exception flow ends cleanly after sending the notification, ensuring proper message lifecycle completion.

rajeshwerrao_gujja151_6-1774192420962.png

The above one is for incorrect input payload 


Benefits of This Approach

  • Practical understanding of API‑based integrations in SAP CPI
  • Importance of Exchange Properties for clean design
  • How to implement a reusable Exception Subprocess
  • Benefits of HTML‑formatted responses for both success and errors
  • How CPL logs (MPL ID) help in monitoring and support

Conclusion

This exercise helped me gain hands‑on experience in building a real‑time integration scenario using SAP Cloud Integration. By implementing both success and error handling properly, I was able to design an iFlow that closely resembles a real‑world project.

The same design pattern can be reused for many API‑driven integration scenarios, making it a valuable learning experience.

2 Comments

@RajeshwerRao_G_1 well documented use case. Thanks for sharing! 🙂

shalini_2002
Explorer

@RajeshwerRao_G_1 This content is very useful. Thanks for sharing.