Application Development 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: 

CONVERT_FOREIGN_TO_FOREIGN_CUR result incorrect

former_member503295
Discoverer
0 Kudos

Hi,

When I use the FM 'CONVERT_FOREIGN_TO_FOREIGN_CUR' to convert an amount from USD to VND, the result has 2 0s less. For example, when the Exchange Rate is 20.7 and Translation Ratio is 1:1000,

130 USD = 130 * 20.7 * 1000 = 2691000 VND

But, the FM 'CONVERT_FOREIGN_TO_FOREIGN_CUR' returns the value as 26910 VND.

P.S: USD has 2 decimal places and VND has 0 decimal places as per config.

6 REPLIES 6

former_member503295
Discoverer
0 Kudos

Can somebody tell if this is the intended behaviour or if some other setting is missing for the output to be as expected?

0 Kudos

Hi Anandkumar,

Enough information about currency conversion at that link http://www.geocities.ws/victorav15/sapr3/abapfun.html#currency

There are two example linked also..

Former Member
0 Kudos

Hi Anandkumar,

After converting to the Foreign amount, you need to use CURRENCY_AMOUNT_SAP_TO_IDOC function module to convert this SAP to ISO currency. The reverse can also be done, i.e IDOC to SAP. In this function module you will convert the amount to the required amount of that currency, i.e. for 216 VND it will give 21600 and similar to JPY.

In this function module, you may find error while activating, or can create the problem in output during runtime, just copy this to Z Function module and change the type of IDOC_TYPE. The problem will then be solved.


Regards,

Hardik Mehta

0 Kudos

Hi Hardik,

Thanks for the inputs.

However, this FM 'CURRENCY_AMOUNT_SAP_TO_IDOC ' cannot be used in all cases because if I do a conversion from JPY to IDR, the result is correct because both have 0 decimals. In that case, if I use the above FM, my result would again get multiplied by 100.

Only when the FM 'CONVERT_FOREIGN_TO_FOREIGN_CUR' is used for 2 currencies which has different number of decimal places, this problem occurs.

For example, from USD to VND or from EUR to VND, where USD or EUR has 2 decimal places and VND has 0 decimals.

Can something be done about this?

0 Kudos

Hi Anand,

I am not asking you to replace your FM 'CONVERT_FOREIGN_TO_FOREIGN_CUR', I am asking you to use the function module 'CURRENCY_AMOUNT_SAP_TO_IDOC' after you have got your result from the first function module. It can be used in all the cases. The sample of the code will be:

CALL FUNCTION 'CONVERT_FOREIGN_TO_FOREIGN_CUR'

Exporting

TO_AMT = <amt>

which will export the amount<amt> for currency <curr>. Take this amount and then in the Function Module pass the amount to get the correct ISO values of that currency.

CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_IDOC'

IMPORTING

   CURRENCY          = <curr> (VND)

  SAP_AMOUNT       = <amt> (26910)

EXPORTING

  IDOC_AMOUNT      = <amt1>

The value of <AMT1> will be 2691000. If you put the value as 26910.23, then the return value will be 2691023. This will work for all the currencies for that factor. Instead of VND, if you use USD, then the same amounts will be returned.

Just try the same with different decimal places as well as same decimal places. There is also the function module 'CURRENCY_AMOUNT_IDOC_TO_SAP', which does the opposite things of above.

Regards,

Hardik Mehta

raymond_giuseppi
Active Contributor
0 Kudos

How did you test ? Remember USD has 2 decimals, so 130 USD will be 130.00 USD and stored as 13000 internally, when 2691000 VND will be stored as it is in memory 2691000 ! (FM use internal values, perform some where-used to get this information)

Also don't forget to check for fixed rate (use READ_EXCHANGE_RATE), else you will be required to use CONVERT_TO_LOCAL_CURRENCY and CONVERT_TO_FOREIGN_CURRENCY.

Regards,

Raymond