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: 

Exchange rate Calculation

nmkarthikeya
Active Participant
0 Kudos

Hi Experts,

I have requirement of converting USD into CAD and GBP currencies.

I used FM READ_EXCHANGE_RATE to find out the exchange rate to calculate the amount in CAD or GBP , below is the code used for that.

Now my question is the exchange rate comes as negative while converting from USD to CAD which I have handled by dividing the amount by the rate but when I convert from USD to GBP the value is positive but still amount needs to be divided . Now how do I generalize this for all the conversions?

The below code works well for USD to CAD conversion but for USD to GBP it doesn't work!!(as the exchange rate is positive and amount needs to be divided)

CALL FUNCTION 'READ_EXCHANGE_RATE'
             EXPORTING
               client           = sy-mandt
               date             = v_date
               foreign_currency = 'CAD'
               local_currency   = 'USD'
               type_of_rate     = v_extype
             IMPORTING
               exchange_rate    = v_er
               foreign_factor   = v_ff
               local_factor     = v_lf
               valid_from_date  = v_vfd
             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 = 0.
             IF v_lf NE 0.
               IF v_ff NE 0.
                 v_result = ( v_ff / v_lf ).
                 IF v_result NE 0.
                   v_exrate = v_er / v_result.
                   IF v_exrate < 0.
                     wa_work_tab-nav_post = wa_work_tab-nav_post / v_exrate.
                   ELSE.
                     wa_work_tab-nav_post = wa_work_tab-nav_post * v_exrate.
                   ENDIF.
                 ENDIF.
               ENDIF.

Regards,

Karthikeya

7 REPLIES 7

juergenbaur
Contributor
0 Kudos

Hi,

try CONVERT_TO_LOCAL_CURRENCY

br

Jürgen

raymond_giuseppi
Active Contributor
0 Kudos

As a rule, try to use CONVERT_TO_LOCAL_CURRENCY and CONVERT_TO_FOREIGN_CURRENCY FM.

Regards,
Raymond

Former Member
0 Kudos

You can use table TCURR.

Thanks,

Jigar thakkar.

Former Member
0 Kudos

Hi,

Have a look at table TCURR. If the exchange rate TCURR-UKURS is less than 0, then multiply or else if it is greater than 0 then divide.

For USD -> CAD, you will have to divide.

For USD -> GBP, you will have to multiply.

It is however recommened to use function modules as stated by Raymond.

Regards,

Danish.

0 Kudos

Hi,

I used the FM  CONVERT_TO_FOREIGN_CURRENCY and below is how its happening.

CLIENT                      020
DATE                        02/29/2012
FOREIGN_CURRENCY            USD
LOCAL_AMOUNT                1000
LOCAL_CURRENCY              CAD
RATE                        0
TYPE_OF_RATE                M
READ_TCURR                  X

In the above case its converting properly from USD to CAD and giving the result as 994CAD for 1000USD.

But if I change the LOCAL_CURRENCY to GBP it is giving a wrong output. for 1000USD its giving 1565 where as it should be around 630.

Please let me know whether I am missing out something in this.

Regards,

Karthikeya

0 Kudos

What is (are) your true local currency (-ies), how are the rate stored in your database. If you are in Canada and local currency is CAD, then  you cannot convert USD to GBP you have to convert USD to local currency CAD and then convert local currency CAD to foreign currency GBP. (Read FM documentation on how they look for currency rate)

Former Member
0 Kudos

Hi   Karthik,

Try this BAPI.

BAPI_EXCHANGERATE_GETDETAIL

Thanks,

Deb