Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

Tags:
Not what you were looking for? View more on this topic or Ask a question