08-08-2013 9:45 AM
I need to convert JPY to USD value. Using CONVERT_AMOUNT_TO_CURRENCY is returning wrong results. Also I've tried several others FMs but couldn't find proper result. Any suggestions please?
08-08-2013 10:06 AM
Hello Pawan,
Check this.
data: w_dec1 like tcurx-currdec,
w_amt like ekpo-netwr,
w_rate like tcurr-ukurs,
w_fact1 like tcurr-ffact,
w_fact2 like tcurr-ffact.
parameters:
p_curr1 like tcurc-waers default 'USD',
p_amt1 like ekpo-netwr default '100',
p_curr2 like tcurc-waers default 'JPY',
pdate like sy-datum default sy-datum.
end-of-selection.
write:
/ 'Entered:',
/ ' from currency:', p_amt1 currency p_curr1, p_curr1, '<-', p_amt1,
/ ' to currency :', p_curr2,
/ ' on :', pdate.
CALL FUNCTION 'FWOS_CURRENCY_DECIMALS_READ'
EXPORTING
I_CURRENCY = p_curr1
IMPORTING
E_DECIMALS = w_dec1
EXCEPTIONS
I_CURRENCY_INITIAL = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
w_dec1 = 2.
ENDIF.
p_amt1 = p_amt1 * 10 ** ( w_dec1 - 2 ).
write:
/ 'after adjusting using currency decimals:',
/ ' from currency', p_amt1 currency p_curr1, p_curr1,
'<-', p_amt1, '(', w_dec1, ')'.
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
* CLIENT = SY-MANDT
DATE = pdate
FOREIGN_CURRENCY = p_curr2
LOCAL_AMOUNT = p_amt1
LOCAL_CURRENCY = p_curr1
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
IMPORTING
EXCHANGE_RATE = w_rate
FOREIGN_AMOUNT = w_amt
FOREIGN_FACTOR = w_fact1
LOCAL_FACTOR = w_fact2
* EXCHANGE_RATEX =
* DERIVED_RATE_TYPE =
* FIXED_RATE =
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
write: / 'Conversion to for.curr. failed:',
p_curr1, '->', p_curr2, 'err.code=', sy-subrc.
ELSE.
write: / 'to For.curr:', p_amt1 currency p_curr1, p_curr1, '->',
w_amt currency p_curr2, p_curr2,
'(', w_rate, ')', w_fact1, w_fact2.
ENDIF.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
* CLIENT = SY-MANDT
DATE = pdate
FOREIGN_AMOUNT = p_amt1
FOREIGN_CURRENCY = p_curr1
LOCAL_CURRENCY = p_curr2
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
IMPORTING
EXCHANGE_RATE = w_rate
FOREIGN_FACTOR = w_fact1
LOCAL_AMOUNT = w_amt
LOCAL_FACTOR = w_fact2
* EXCHANGE_RATEX =
* FIXED_RATE =
* DERIVED_RATE_TYPE =
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
write: / 'Conversion to loc.curr. failed:',
p_curr1, '->', p_curr2, 'err.code=', sy-subrc.
ELSE.
write: / 'to Loc.curr:', p_amt1 currency p_curr1, p_curr1, '->',
w_amt currency p_curr2, p_curr2,
'(', w_rate, ')', w_fact1, w_fact2.
ENDIF.
For reference, check this : http://scn.sap.com/thread/47276
Thanks
Katrice
08-08-2013 10:01 AM
Hi Pawan,
Please use the FM "BAPI_CURRENCY_CONV_TO_EXTERNAL" to convert the JPY Amount into an external format.
I think this should suffice your purpose.
Thanks,
Arnab
08-08-2013 10:06 AM
Hello Pawan,
Check this.
data: w_dec1 like tcurx-currdec,
w_amt like ekpo-netwr,
w_rate like tcurr-ukurs,
w_fact1 like tcurr-ffact,
w_fact2 like tcurr-ffact.
parameters:
p_curr1 like tcurc-waers default 'USD',
p_amt1 like ekpo-netwr default '100',
p_curr2 like tcurc-waers default 'JPY',
pdate like sy-datum default sy-datum.
end-of-selection.
write:
/ 'Entered:',
/ ' from currency:', p_amt1 currency p_curr1, p_curr1, '<-', p_amt1,
/ ' to currency :', p_curr2,
/ ' on :', pdate.
CALL FUNCTION 'FWOS_CURRENCY_DECIMALS_READ'
EXPORTING
I_CURRENCY = p_curr1
IMPORTING
E_DECIMALS = w_dec1
EXCEPTIONS
I_CURRENCY_INITIAL = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
w_dec1 = 2.
ENDIF.
p_amt1 = p_amt1 * 10 ** ( w_dec1 - 2 ).
write:
/ 'after adjusting using currency decimals:',
/ ' from currency', p_amt1 currency p_curr1, p_curr1,
'<-', p_amt1, '(', w_dec1, ')'.
CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
* CLIENT = SY-MANDT
DATE = pdate
FOREIGN_CURRENCY = p_curr2
LOCAL_AMOUNT = p_amt1
LOCAL_CURRENCY = p_curr1
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
IMPORTING
EXCHANGE_RATE = w_rate
FOREIGN_AMOUNT = w_amt
FOREIGN_FACTOR = w_fact1
LOCAL_FACTOR = w_fact2
* EXCHANGE_RATEX =
* DERIVED_RATE_TYPE =
* FIXED_RATE =
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
write: / 'Conversion to for.curr. failed:',
p_curr1, '->', p_curr2, 'err.code=', sy-subrc.
ELSE.
write: / 'to For.curr:', p_amt1 currency p_curr1, p_curr1, '->',
w_amt currency p_curr2, p_curr2,
'(', w_rate, ')', w_fact1, w_fact2.
ENDIF.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
* CLIENT = SY-MANDT
DATE = pdate
FOREIGN_AMOUNT = p_amt1
FOREIGN_CURRENCY = p_curr1
LOCAL_CURRENCY = p_curr2
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
IMPORTING
EXCHANGE_RATE = w_rate
FOREIGN_FACTOR = w_fact1
LOCAL_AMOUNT = w_amt
LOCAL_FACTOR = w_fact2
* EXCHANGE_RATEX =
* FIXED_RATE =
* DERIVED_RATE_TYPE =
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
write: / 'Conversion to loc.curr. failed:',
p_curr1, '->', p_curr2, 'err.code=', sy-subrc.
ELSE.
write: / 'to Loc.curr:', p_amt1 currency p_curr1, p_curr1, '->',
w_amt currency p_curr2, p_curr2,
'(', w_rate, ')', w_fact1, w_fact2.
ENDIF.
For reference, check this : http://scn.sap.com/thread/47276
Thanks
Katrice
08-08-2013 10:19 AM
Arnab, am already using this BAPI to convert MBEW-STPRS as per the company currency.
The problem is with later on conversion of this JPY value to USD..
Regards.
08-08-2013 10:22 AM
Katrice,
already tried CONVERT_TO_FOREIGN/LOCAL_CURRENCY FMs
Say JPY value is 250 JPY then USD value returned with these is around 100 times more
But it should be around 2.5 USD..
08-08-2013 10:24 AM
Katrice,
looks like I'll have to manually check for conversion exchange rate from SAP table and manullay code the conversion?
08-08-2013 10:22 AM
08-08-2013 11:22 AM
Swathi,
Already tried this it returns incorrect value-
call function 'CONVERT_TO_LOCAL_CURRENCY'
exporting
date = sy-datum
foreign_amount = g_cost_jpy
foreign_currency = lv_jpu
local_currency = lv_usd
type_of_rate = 'M'
read_tcurr = 'X'
importing
local_amount = g_cost_usd
exceptions
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
others = 6.
Runtime values in debuggin:-
g_cost_jpy = 16502550.00
lv_jpy = JPY
lv_usd = USD
g_cost_usd = 165685100.0000
USD cost is wrong. it should be around 16502.50
Also tried CONVERT_TO_FOREIGN_CURRENCY FM.. also gives incorrect result.
Whats the concept of Local and Foreign in these Function Modules by the way?
08-12-2013 9:20 PM
Hi,
you are using the correct FM.
the correct value es g_cost_usd = 165685100.0000
because u need to check when was the last time that the exchange rate was updated it.
it doesnt matter if you put the date of today, the system check if todays dates is on the exchange rate table, if not, it takes the last date of the exchange rate of JPY to USD.
and it gives you value g_cost_usd = 165685100.0000, then you need to show it using sth like this
write g_cost_usd to g_cost_usd_c currency 'USD'.
Regards
Miguel
08-12-2013 1:43 PM
08-12-2013 9:40 PM
Hi Pawan,
After running the currency conversion use function module CURRENCY_AMOUNT_BAPI_TO_SAP.
Pass the currency as JPY and the amount
Sorry about my previous post. Before passing the data to the currency conversion function module, use the function module
CURRENCY_AMOUNT_BAPI_TO_SAP (In this case currency here will be JPY). then use the converted value to pass to the currency conversion function module.
Regards
Rajvansh
Message was edited by: Rajvansh Ravi
08-12-2013 11:52 PM
Hi Pawan,
The JPY currency does not have decimals but is stored in the DB as a decimal value. Check the T-Code OY04 to see if the decimal places has been maintained correctly. Ant conversion exit for amount just converts based on maintenance done here. Then on top of that the rate of exchange is to be considered. Check the link below to understand what are the prerequisites
http://wiki.sdn.sap.com/wiki/display/ERPFI/CURRENCIES+-+Customizing+and+transactions
Cheers,
Arindam
08-13-2013 2:08 PM
Thank you Guys, for your helpful inputs.
I only used CONVERT_AMOUNT_TO_CURRENCY FM and it gave correct results.
There are several approaches for this problem-
1. Pass input amount to FM in character format with exact decimal format taking the same from TCURX table. Then the output cost returned is absolutely correct. We would need to firstly use BAPI to convert cost to external format as per currency (BAPI_CONVERT_COST_EXTERN_9.. etc are available)
2. Or we can just pass cost (input/output) parameters in standard SAP way - (Type P Length 12 decimals 2) to the FM and after getting output. Write both Input and Output Costs after currency conversion using WRITE... TO.. CURRENCY syntax. No need of BAPI to convert costs based on currency before passing to FM
Thanks and Best Regards.