SAP CALCULATE_EXCHANGE_RATE Function Module for Find Rate Based on Amounts, Currency Keys and Date
CALCULATE_EXCHANGE_RATE is a standard calculate exchange rate SAP function module available within SAP R/3 or S/4 Hana systems, depending on your version and release level. It is used for Find Rate Based on Amounts, Currency Keys and Date processing and below is the pattern details for this FM, showing its interface including any import and export parameters, exceptions etc. there is also a full "cut and paste" ABAP pattern code example, along with implementation ABAP coding, documentation and contribution comments specific to this or related objects.
See here to view full function module documentation and code listing for calculate exchange rate FM, simply by entering the name CALCULATE_EXCHANGE_RATE into the relevant SAP transaction such as SE37 or SE38.
Function Group: SCUN
Program Name: SAPLSCUN
Main Program: SAPLSCUN
Appliation area: *
Release date: 17-May-2000
Mode(Normal, Remote etc): Normal Function Module
Update:

Function CALCULATE_EXCHANGE_RATE pattern details
In-order to call this FM within your sap programs, simply using the below ABAP pattern details to trigger the function call...or see the full ABAP code listing at the end of this article. You can simply cut and paste this code into your ABAP progrom as it is, including variable declarations.CALL FUNCTION 'CALCULATE_EXCHANGE_RATE'"Find Rate Based on Amounts, Currency Keys and Date.
EXPORTING
* CLIENT = SY-MANDT "
DATE = "Conversion Date
FOREIGN_AMOUNT = "Amount in Foreign Currency
FOREIGN_CURRENCY = "Currency Cey for Foreign Currency
LOCAL_AMOUNT = "Amount in Local Currency
LOCAL_CURRENCY = "Currency Key for Local Currency
* TYPE_OF_RATE = 'M' "Exchange Rate Type
IMPORTING
EXCHANGE_RATE = "Exchange Rate
FOREIGN_FACTOR = "Factor for the Foreign Currency Units
LOCAL_FACTOR = "Factor for the Local Currency Units
DERIVED_RATE_TYPE = "Alternative Exchange Rate, Where Used
FIXED_RATE = "Fixed Exchange Rate 4,5, if Present
EXCEPTIONS
NO_RATE_COMPUTABLE = 1 NO_RATE_FOUND = 2 RATE_TOO_BIG = 3 NO_FACTORS_FOUND = 4 NO_SPREAD_FOUND = 5 DERIVED_2_TIMES = 6 OVERFLOW = 7
IMPORTING Parameters details for CALCULATE_EXCHANGE_RATE
CLIENT -
Data type: SY-MANDTDefault: SY-MANDT
Optional: Yes
Call by Reference: No ( called with pass by value option)
DATE - Conversion Date
Data type: SYST-DATUMOptional: No
Call by Reference: No ( called with pass by value option)
FOREIGN_AMOUNT - Amount in Foreign Currency
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
FOREIGN_CURRENCY - Currency Cey for Foreign Currency
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
LOCAL_AMOUNT - Amount in Local Currency
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
LOCAL_CURRENCY - Currency Key for Local Currency
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
TYPE_OF_RATE - Exchange Rate Type
Data type:Default: 'M'
Optional: Yes
Call by Reference: No ( called with pass by value option)
EXPORTING Parameters details for CALCULATE_EXCHANGE_RATE
EXCHANGE_RATE - Exchange Rate
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
FOREIGN_FACTOR - Factor for the Foreign Currency Units
Data type: TCURR-FFACTOptional: No
Call by Reference: No ( called with pass by value option)
LOCAL_FACTOR - Factor for the Local Currency Units
Data type: TCURR-TFACTOptional: No
Call by Reference: No ( called with pass by value option)
DERIVED_RATE_TYPE - Alternative Exchange Rate, Where Used
Data type: TCURR-KURSTOptional: No
Call by Reference: No ( called with pass by value option)
FIXED_RATE - Fixed Exchange Rate 4,5, if Present
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
EXCEPTIONS details
NO_RATE_COMPUTABLE - Translation not Possible
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_RATE_FOUND - Entry not Found in Table TCURR
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
RATE_TOO_BIG - The Exchange Rate Determined Exceeds Acceptable Limits
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_FACTORS_FOUND - No Entry Found in Table TCURF
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
NO_SPREAD_FOUND - Spread not Entered in Table TCURS
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
DERIVED_2_TIMES -
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
OVERFLOW - Arithmetical Overflow
Data type:Optional: No
Call by Reference: No ( called with pass by value option)
Copy and paste ABAP code example for CALCULATE_EXCHANGE_RATE Function Module
The ABAP code below is a full code listing to execute function module POPUP_TO_CONFIRM including all data declarations. The code uses the original data declarations rather than the latest in-line data DECLARATION SYNTAX but I have included an ABAP code snippet at the end to show how declarations would look using the newer method of declaring data variables on the fly. This will allow you to compare and fully understand the new inline method. Please note some of the newer syntax such as the @DATA is not available until a later 4.70 service pack (SP8), which i why i have stuck to the origianl for this example.| DATA: | ||||
| lv_client | TYPE SY-MANDT, " SY-MANDT | |||
| lv_exchange_rate | TYPE SY, " | |||
| lv_no_rate_computable | TYPE SY, " | |||
| lv_date | TYPE SYST-DATUM, " | |||
| lv_no_rate_found | TYPE SYST, " | |||
| lv_foreign_factor | TYPE TCURR-FFACT, " | |||
| lv_local_factor | TYPE TCURR-TFACT, " | |||
| lv_rate_too_big | TYPE TCURR, " | |||
| lv_foreign_amount | TYPE TCURR, " | |||
| lv_foreign_currency | TYPE TCURR, " | |||
| lv_no_factors_found | TYPE TCURR, " | |||
| lv_derived_rate_type | TYPE TCURR-KURST, " | |||
| lv_fixed_rate | TYPE TCURR, " | |||
| lv_local_amount | TYPE TCURR, " | |||
| lv_no_spread_found | TYPE TCURR, " | |||
| lv_local_currency | TYPE TCURR, " | |||
| lv_derived_2_times | TYPE TCURR, " | |||
| lv_overflow | TYPE TCURR, " | |||
| lv_type_of_rate | TYPE TCURR. " 'M' |
|   CALL FUNCTION 'CALCULATE_EXCHANGE_RATE' "Find Rate Based on Amounts, Currency Keys and Date |
| EXPORTING | ||
| CLIENT | = lv_client | |
| DATE | = lv_date | |
| FOREIGN_AMOUNT | = lv_foreign_amount | |
| FOREIGN_CURRENCY | = lv_foreign_currency | |
| LOCAL_AMOUNT | = lv_local_amount | |
| LOCAL_CURRENCY | = lv_local_currency | |
| TYPE_OF_RATE | = lv_type_of_rate | |
| IMPORTING | ||
| EXCHANGE_RATE | = lv_exchange_rate | |
| FOREIGN_FACTOR | = lv_foreign_factor | |
| LOCAL_FACTOR | = lv_local_factor | |
| DERIVED_RATE_TYPE | = lv_derived_rate_type | |
| FIXED_RATE | = lv_fixed_rate | |
| EXCEPTIONS | ||
| NO_RATE_COMPUTABLE = 1 | ||
| NO_RATE_FOUND = 2 | ||
| RATE_TOO_BIG = 3 | ||
| NO_FACTORS_FOUND = 4 | ||
| NO_SPREAD_FOUND = 5 | ||
| DERIVED_2_TIMES = 6 | ||
| OVERFLOW = 7 | ||
| . " CALCULATE_EXCHANGE_RATE | ||
ABAP code using 7.40 inline data declarations to call FM CALCULATE_EXCHANGE_RATE
The below ABAP code uses the newer in-line data declarations. This allows you to see the coding differences/benefits of the later inline syntax. Please note some of the newer syntax below, such as the @DATA is not available until 4.70 EHP 8.| "SELECT single MANDT FROM SY INTO @DATA(ld_client). | ||||
| DATA(ld_client) | = SY-MANDT. | |||
| "SELECT single DATUM FROM SYST INTO @DATA(ld_date). | ||||
| "SELECT single FFACT FROM TCURR INTO @DATA(ld_foreign_factor). | ||||
| "SELECT single TFACT FROM TCURR INTO @DATA(ld_local_factor). | ||||
| "SELECT single KURST FROM TCURR INTO @DATA(ld_derived_rate_type). | ||||
| DATA(ld_type_of_rate) | = 'M'. | |||
Search for further information about these or an SAP related objects