DEV Community

Exchange Rate API
Exchange Rate API

Posted on Originally published at allratestoday.com

From a REST Rate Table to an EXCHANGE_RATE01 IDoc: An Integration Suite iFlow and ABAP Report

Most rate feeds for SAP end the same way: a JSON response somewhere, and table TCURR on the other side expecting rows keyed by rate type, currency pair and valid-from date. The glue in between is where the work is: rate direction, translation ratios, the IDoc control record, and tables that have two rates per currency.

The open-source sap-official-exchange-rates package is that glue for official exchange rates (customs valuation rates by clearance country, central bank reference rates, tax authority tables) from the AllRatesToday API. It has two routes:

Route For File
SAP Integration Suite (Cloud Integration) S/4HANA and ECC, on-premise or private cloud, through Cloud Connector integration-suite/ExchangeRateToIdoc.groovy
ABAP report On-premise systems that call the API directly abap/zallrates_load_exchange_rates.prog.abap

To be clear about status: both are reference implementations to review, test in a sandbox client and adapt. The Groovy mapping is unit-tested; the ABAP report has not been run in an SAP system by us.

The full guide is at allratestoday.com/docs/integrations/sap-integration-suite/.

Which endpoint to call

  • Customs rate for a clearance country: GET /api/v1/customs/{country}/latest, with an ISO code such as NL, US, IN.
  • A past declaration date: /api/v1/customs/{country}/{YYYY-MM-DD} (paid plans).
  • A central bank or tax authority table: /api/v1/central-bank/{code}/latest, for example ecb, hmrc, rbi.

Send the key as Authorization: Bearer <key>. Every response carries rate_date, the authority's own table date, and both routes write it as VALID_FROM.

Route 1: Integration Suite iFlow

The iFlow is four steps:

  1. Timer start event on the source's cadence.
  2. Request Reply to an HTTP receiver calling the endpoint. Keep the key in a Secure Parameter and set the Authorization header in a Content Modifier.
  3. Content Modifier setting the exchange properties below, then a Groovy Script step with ExchangeRateToIdoc.groovy.
  4. IDoc receiver adapter to the SAP system.

Script properties

Property Meaning Default
RateType TCURR exchange rate type (KURST) M
HomeCurrency Write every rate as foreign → home (direct quotation) the table's own direction
Currencies Comma list to keep all
Factors Ratios matching OBBS/TCURF, e.g. JPY:100,KRW:1000 1
TableRateType Side of a two-sided table: import or export one row per currency, import first
SenderPort, SenderPartner, ReceiverPort, ReceiverPartner EDI_DC40 partner data (partner type LS) none
UpdateAllowed / ChangeFixed / AllowedDeviation UPD_ALLOW / CHG_FIXED / DEV_ALLOW X / blank / 000

For the export side of India's customs table, for example:

RateType        = ZCIX          # TCURR rate type (KURST)
HomeCurrency    = INR           # write every rate as foreign -> home
Currencies      = USD,EUR,GBP   # optional filter
Factors         = JPY:100       # must match OBBS / TCURF
TableRateType   = export        # import or export, for two-sided tables
SenderPort      = SAPCPI
SenderPartner   = CPI_LS
ReceiverPort    = SAPS4H
ReceiverPartner = S4H_100
Enter fullscreen mode Exit fullscreen mode

Rates are written with 5 decimals, because EXCH_RATE is DEC 9,5. A rate that doesn't fit for the chosen factor is skipped, not truncated. If a currency goes missing, give it a ratio in Factors and in OBBS. The script also sets the headers AllRatesRateDate, AllRatesSource and AllRatesRows, so you can monitor each run without opening the payload.

IDoc receiver adapter

The adapter settings follow SAP's own exchange-rate recipe in the SAP Integration Recipes repository:

  • Address http://<virtual host>:<port>/sap/bc/srt/idoc?sap-client=<client>, using the Cloud Connector virtual host.
  • Proxy Type On-Premise, with your Cloud Connector Location ID.
  • Authentication Basic (User Credentials artifact).
  • IDoc Content Type Text/XML.

SAP backend

  • SRTIDOC: register the IDoc SOAP inbound service (default values).
  • SICF: activate /sap/bc/srt/idoc.
  • WE20: inbound partner profile for the sender logical system with message type EXCHANGE_RATE (basic type EXCHANGE_RATE01). Sender partner, partner type and port must match the IDoc, or it stops in status 56.
  • OBBS: translation ratios for every pair in the rate type, matching Factors.

If an IDoc stops in status 56, compare the partner properties set in the Content Modifier with the WE20 profile.

Route 2: ABAP report

For on-premise systems that can reach the API directly, ZALLRATES_LOAD_EXCHANGE_RATES calls it with CL_HTTP_CLIENT, parses the response with /UI2/CL_JSON, writes every rate as foreign → home and posts with BAPI_EXCHRATE_CREATEMULTIPLE and BAPI_TRANSACTION_COMMIT.

Parameter Meaning
P_CNTRY or P_SRC Clearance country (customs), or a source code such as ecb, hmrc, zollde
P_DATE Table in force on this date; empty for today's table
P_HOME Ledger or customs currency
P_KURST Rate type, default ZCUS
P_CURR, P_FACT Optional currency list and ratios (JPY:100)
P_RTYP Table side for two-sided tables: import or export; empty = one row per currency, import first
P_UPD, P_TEST Allow overwrite; test mode lists without posting (on by default)

Test mode is on by default, so the first run lists what it would post instead of posting it.

Prerequisites:

  • The SSL client PSE (STRUST) trusts allratestoday.com's certificate chain.
  • GET_API_KEY is replaced with your secure storage.
  • The translation ratios exist.

Schedule it in SM36 on the source's cadence, one variant per rate type.

Two-sided tables

India (CBIC), Thailand, Korea, Iceland and Uganda set separate import and export rates per currency, and Uganda adds VAT and income-tax series. A TCURR rate type holds one rate per pair and date, so both routes keep one row per currency: the side named in TableRateType / P_RTYP, or the import side when none is named.

Load each side into its own rate type, for example ZCIN with import and ZCIX with export, and assign each to the matching legal regulation in SAP GTS. The SAP GTS guide covers that assignment.

Running the tests

The Groovy mapping is tested with plain Groovy 4 and a stand-in for the CPI Message class:

CP="groovy-4.0.24.jar:groovy-json-4.0.24.jar:groovy-xml-4.0.24.jar"
java -cp "$CP" org.codehaus.groovy.tools.FileSystemCompiler -d build \
  test/com/sap/gateway/ip/core/customdev/util/Message.groovy
java -cp "$CP:build" groovy.ui.GroovyMain test/run.groovy   # ExchangeRateToIdoc: ok
Enter fullscreen mode Exit fullscreen mode

The tests cover direction and inversion, ratios, the currency filter, skipped oversize rates, IDoc control data and the import/export selection on a two-sided table.

What it doesn't cover

S/4HANA Cloud, public edition is not covered by the package. Public edition takes exchange rates through SAP's own interfaces; check the current options and field names on the SAP Business Accelerator Hub for your release.

Links

Rates are redistributed from each institution's own publication. They are reference rates for accounting, tax and compliance, not dealing quotes.

Top comments (0)