Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function module 'CONVERT_TO_LOCAL_CURRENCY' return wrong exchange rate

derek_yang
Product and Topic Expert
Product and Topic Expert
0 Likes
9,821

Hello all,

I run into a very weird issue when calling function module ''CONVERT_TO_LOCAL_CURRENCY', the result of the exchange rate is 100000 times of the actual value I expected. See the details here:

Then I call function module like below:

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

   EXPORTING

     date                    = sy-datlo

     foreign_amount    = lv_value

     foreign_currency  = 'EUR'

     local_currency     = 'USD'

     type_of_rate        = 'M'

   IMPORTING

     exchange_rate    = lv_liccf

     local_amount      = lv_amount

   EXCEPTIONS

     no_rate_found    = 1

     overflow             = 2

     no_factors_found = 3

     no_spread_found  = 4

     derived_2_times  = 5

     OTHERS           = 6.

WRITE:/ lv_liccf.

WRITE: / lv_amount.

lv_convert = lv_value * lv_liccf.

Given the lv_value to 1000, and after the run, the lv_amount is correctly converted to 1333.3, but the lv_liccf is return as 1.3333000000000000E+05. Which is 100000 times of the actual value. So as a result the lv_convert is 100000 times of 1333.3, which didn't make much sense to me.

This is the test code I written in my local, The idea in real program is that I stored this exchange rate in a table, so next time when doing the conversion, if I am sure the criteria is the same, I just get this exchange rate value directly from database instead of call conversion function module again, but obviously I get some issues here, so I have below questions:

1. I debug into the code, but didn't even get much clue about this, does anyone know what happened here?

2. How can I avoid this problem if I don't want to call the conversion function module again?

Your help is highly appreciated!

Thanks,

Derek



1 ACCEPTED SOLUTION
Read only

arindam_m
Active Contributor
0 Likes
7,544

Hi,

Exchange rates are saved in Exponential format to save the accuracy of the rates as minor difference in 3rd or 4th decimal place make a difference. So the they are saved in such a way internally. I would suggest to set the flag READ_TCURR = 'X' that should give you the exchange rate in external format i think.

Cheers,

Arindam

8 REPLIES 8
Read only

Former Member
0 Likes
7,544

Hi Derek,

Can you check if you are using the right data type for the lv_convert ? As far as my understanding I dont seee any issues with the FM, it is only wiht the field LV_CONVERT . Correct me If I am wrong.

Read only

derek_yang
Product and Topic Expert
Product and Topic Expert
0 Likes
7,544

Hello Raja,

The data type for both 'lv_amount', 'lv_value' and 'lv_convert' are declared as data type 'CURR', which is the 'Currency field, stored as DEC', like below:

I didn't see anything wrong here.

Read only

ronaldo_aparecido
Contributor
0 Likes
7,544

Hi

Check

declare the variable with value.

TYPE p DECIMALS 2.

Read only

derek_yang
Product and Topic Expert
Product and Topic Expert
0 Likes
7,544

Hello Ronaldo,

To define as data type p is not what i wanted, I need to define all the amount as the same data type 'CURR', see the screen shot above of the type 'CURR'.

Read only

0 Likes
7,544

Hi Derek,

I do not understand how you define a variable with data type CURR in code because elementary data type for 'CURR' is packed decimal and syntax is as suggested by Ronaldo.

BR.

Read only

arindam_m
Active Contributor
0 Likes
7,545

Hi,

Exchange rates are saved in Exponential format to save the accuracy of the rates as minor difference in 3rd or 4th decimal place make a difference. So the they are saved in such a way internally. I would suggest to set the flag READ_TCURR = 'X' that should give you the exchange rate in external format i think.

Cheers,

Arindam

Read only

Former Member
0 Likes
7,544

The function READ_TCURR is not for "give you the exchange rate in external format i think". It is to handle the buffer / read from table:

Read only

Former Member
0 Likes
7,544

Hi, I was having similar issues until I declared the exchange rate fields as " UKURS_CURR". See the test code below. I also had an issue with the local amount for very small quantities. For example the exchange rate from MXN to USD is 0.07667 but when I enter 1 MXN as foreign_amount and try to convert to USD, I get zero as local_amount . That is why I took the exchange rate field instead .

Cheers,

Alfonzo

*&---------------------------------------------------------------------*
*& Report  ZBW_CONVERT_TO_LOCAL_CURRENCY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zbw_convert_to_local_currency.

DATA:
   v_drt    TYPE kurst_curr,
   v_fixrat TYPE f,
   v_forfac TYPE f,
   v_locamo TYPE f,
   v_locfac TYPE f,
   v_price  TYPE f,
   v_rate   TYPE UKURS_CURR,
   v_ratex  TYPE f.

v_price = 1.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
   EXPORTING
     date              = sy-datum
     foreign_amount    = v_price
     foreign_currency  = 'MXN'
     local_currency    = 'USD'
     type_of_rate      = 'M'
   IMPORTING
     exchange_rate     = v_rate
     foreign_factor    = v_forfac
     local_amount      = v_locamo
     local_factor      = v_locfac
     exchange_ratex    = v_ratex
     fixed_rate        = v_fixrat
     derived_rate_type = v_drt
   EXCEPTIONS
     no_rate_found     = 1
     no_factors_found  = 2
     no_spread_found   = 3
     derived_2_times   = 4
     OTHERS            = 5.

IF sy-subrc = 0.
   WRITE: / 'exchange_rate', v_rate.
   WRITE: / 'foreign_factor', v_forfac.
   WRITE: / 'local_amount', v_locamo.
   WRITE: / 'local_factor', v_locfac.
   WRITE: / 'exchange_ratex', v_ratex.
   WRITE: / 'fixed_rate', v_fixrat.
   WRITE: / 'derived_rate_type', v_drt.
ENDIF.