‎2013 Aug 29 12:20 PM
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
‎2013 Aug 30 4:54 AM
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
‎2013 Aug 29 7:57 PM
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.
‎2013 Aug 30 2:14 AM
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.
‎2013 Aug 29 8:15 PM
‎2013 Aug 30 2:18 AM
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'.
‎2013 Aug 30 4:25 AM
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.
‎2013 Aug 30 4:54 AM
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
‎2014 Jan 17 8:54 PM
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:
‎2014 Jan 17 9:00 PM
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.