Skip to Content

Exchange rate Calculation

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Mar 20, 2012 at 07:56 AM

    Hi,

    try CONVERT_TO_LOCAL_CURRENCY

    br

    Jürgen

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 20, 2012 at 08:08 AM

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

    Regards,
    Raymond

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 20, 2012 at 08:19 AM

    You can use table TCURR.

    Thanks,

    Jigar thakkar.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 20, 2012 at 08:47 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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)

  • avatar image
    Former Member
    Mar 20, 2012 at 09:22 AM

    Hi   Karthik,

    Try this BAPI.

    BAPI_EXCHANGERATE_GETDETAIL

    Thanks,

    Deb

    Add comment
    10|10000 characters needed characters exceeded