‎2009 Mar 17 12:02 PM
The following program converts 1000 TRL into EUR with an exchange rate of 1. It should display 1.000,00 EUR (decimal separator = comma, because it's French format), but displays 0,10 EUR !!
Could you explain me why?
I think there is an error in last line of CONVERT_CURRENCY_BY_RATE :
TO_AMOUNT = REFE * REF2 / 1000 / REF1.should have been this :
TO_AMOUNT = REFE * REF1 / 1000 / REF2.As a workaround, I think we should call the function module with FROM_CURRENCY = 'EUR' and TO_CURRENCY = 'TRL'. My SAP release is ECC 6.
Thx a lot !
REPORT zzysro_test.
TYPES xx TYPE kstbmt.
DATA l_locamount TYPE xx.
PERFORM convert_devise3 USING '1' '1.000' 'TRL' 'EUR' CHANGING l_locamount.
WRITE : l_locamount CURRENCY 'EUR', 'EUR'.
*****************
FORM convert_devise3
USING
i_kurrf TYPE ukurs_curr
i_amount TYPE xx
i_fromcurr TYPE waerk
i_tocurr TYPE waerk
CHANGING
u_locamount TYPE xx.
DATA l_from_amount TYPE bseg-dmbtr.
DATA l_to_amount TYPE bseg-wrbtr.
PACK i_amount TO l_from_amount.
* ERREUR
CALL FUNCTION 'CONVERT_CURRENCY_BY_RATE'
EXPORTING
from_amount = l_from_amount
from_currency = i_fromcurr
from_factor = 1
rate = i_kurrf
to_currency = i_tocurr
to_factor = 1
IMPORTING
to_amount = l_to_amount.
PACK l_to_amount TO u_locamount.
ENDFORM. "convert_devise3
‎2009 Mar 17 1:48 PM
Hello Sandra,
I am not about this FM. What is its functionality? Do you have to provide the "From" "To" currency exch. rates to his FM?
I have always used the FMs: CONVERT_TO_LOCAL_CURRENCY & CONVERT_TO_FOREIGN_CURRENCY for currency conversion.
BR,
Suhas
‎2009 Mar 17 12:18 PM
‎2009 Mar 17 1:37 PM
‎2009 Mar 17 1:48 PM
Hello Sandra,
I am not about this FM. What is its functionality? Do you have to provide the "From" "To" currency exch. rates to his FM?
I have always used the FMs: CONVERT_TO_LOCAL_CURRENCY & CONVERT_TO_FOREIGN_CURRENCY for currency conversion.
BR,
Suhas
‎2009 Mar 18 8:52 AM
Hi Suhas, thank you for your answer, you provided me a workaround for that with CONVERT_TO_LOCAL_CURRENCY which works well.
Nevertheless, we have to provide a date to this FM which I thought wasn't necessary because I have to provide a fixed exchange rate (not from exchange rate tables). But as I don't have the factor (1:1 for most of cases), this date is welcome.
Now, this solves the issue in my program, but doesn't answer the question : I hoped a confirmation of the "bug" could be useful as some people propose CONVERT_CURRENCY_BY_RATE without warning.
‎2012 Jul 20 7:29 AM
Hi Suhas and Sandra,
I have used as u said i did some search in net came across a Code
REPORT ZCONVERT_TOFOREIGN_CURRENCY.
DATA : L_NETWR TYPE VBAP-NETWR.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
DATE = '19970131'
FOREIGN_AMOUNT = '1000'
FOREIGN_CURRENCY = 'CAD'
LOCAL_CURRENCY = 'USD'
TYPE_OF_RATE = 'M'
IMPORTING
LOCAL_AMOUNT = L_NETWR
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
WRITE: L_NETWR.
I get the output but the calculation to the rate is coming wrong. How to handle rates ? i.e i have my requirement to convert the currency from CA(Canada) $ to US(USA) $ the today's rate is like .9999 but the outcome is way to less (about 8.5 something ). if I Comment the
(TYPE_OF_RATE = 'M') then the outcome is 10 as u can see above i have given foreign amount as 1000 the output should be around ' 992 '. Don't no what to do, Sooner help will be appreciated.Thanks in Advance.
‎2009 Mar 18 6:41 AM
Hi Sandra,
Try this piece of code, I know that FM doesnt convert but it works well with the retrieved exchange rate...
DATA: FCURR TYPE TCURR-FCURR,
TCURR TYPE TCURR-TCURR,
DATE TYPE SY-DATUM,
VALUE TYPE P LENGTH 8 DECIMALS 2,
VALUE2 TYPE P LENGTH 8 DECIMALS 2.
FCURR = 'EUR'.
TCURR = 'USD'.
DATE = SY-DATUM.
VALUE = 10.
PERFORM CURRENCY_CONVERSION USING FCURR
TCURR
DATE
CHANGING VALUE.
WRITE:/'FOREIGN CURRENCY=', FCURR,
/'LOCAL CURRENCY=', TCURR,
/'CONVERTED VALUE=', VALUE,
/'CONVERTED VALUE=', VALUE2.
FORM CURRENCY_CONVERSION USING P_FCURR
P_TCURR
P_DATE
CHANGING P_VALUE.
DATA: EX_RATE TYPE TCURR-UKURS,
F_FACTOR TYPE TCURR-FFACT,
L_FACTOR TYPE TCURR-TFACT,
V_DATE TYPE DATUM,
D_ERATE(12) TYPE C.
CALL FUNCTION 'READ_EXCHANGE_RATE'
EXPORTING
* CLIENT = SY-MANDT
DATE = P_DATE
FOREIGN_CURRENCY = P_FCURR
LOCAL_CURRENCY = P_TCURR
TYPE_OF_RATE = 'M'
* EXACT_DATE = ' '
IMPORTING
EXCHANGE_RATE = EX_RATE
FOREIGN_FACTOR = F_FACTOR
LOCAL_FACTOR = L_FACTOR
VALID_FROM_DATE = V_DATE
* DERIVED_RATE_TYPE =
* FIXED_RATE =
* OLDEST_RATE_FROM =
EXCEPTIONS
NO_RATE_FOUND = 1
NO_FACTORS_FOUND = 2
NO_SPREAD_FOUND = 3
DERIVED_2_TIMES = 4
OVERFLOW = 5
ZERO_RATE = 6
OTHERS = 7
.
IF SY-SUBRC EQ 0.
* D_ERATE = EX_RATE / ( F_FACTOR / L_FACTOR ).
* P_VALUE = P_VALUE * D_ERATE.
P_VALUE = P_VALUE * EX_RATE.
ENDIF.
ENDFORM. " currency_conversionWith CONVERT_CURRENCY_BY_RATE there is a problem, i am not sure what.
You may also refer to the following thread for more help..
Regards.
‎2009 Mar 18 5:16 PM
thank you Rajan for the help.
In my case, I already have the exchange rate which is entered manually. Your code doesn't work well for all currencies (the factor numerator and denominator should be used, and currency amounts should be calculated with a floating decimal separator according to number of decimals of the 2 currencies).
The thread you mention doesn't help either.
So the best solution for me is CONVERT_TO_LOCAL_CURRENCY, as I said earlier.
‎2009 Mar 18 8:18 AM
Hi,
you just try once the below Function module
READ_EXCHANGE_RATE
‎2009 Mar 18 8:21 AM
Also check with these fnm
CONVERT_TO_TC_CURR
CONVERT_TO_FOREIGN_CURRENCY
CONVERT_TO_LOCAL_CURRENCY