cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Function module for Currency translation

Former Member
0 Likes
16,392

Hi ABAP Gurus,

I wanted to convert my all currencies to USD, I have exchange rates in TCURR Table already.

I have used below code to call FM and used code for key figure (0DEB_CRE_LC) but the out values are become a ZERO.


DATA: L_KURST     type TCURR-KURST,  "exchg.rate type (M or variant)
        L_CURR_RATE type TCURR-UKURS,  "exchange rate value
        L_FC type TCURR-FCURR,  " From currency
        L_TC type TCURR-TCURR,  " To currency
        L_FF type TCURR-FFACT,
        L_TF type TCURR-TFACT,
       L_FA(16) type p.

    CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
         EXPORTING
              DATE             = SY-DATUM        "currency date
              FOREIGN_AMOUNT   = L_FA    "trans. currency amount
              FOREIGN_CURRENCY = L_FC       "trans. currency code
              LOCAL_CURRENCY   = 'USD'  "local currency
              TYPE_OF_RATE     = L_KURST        "rate on key date
              RATE             = L_CURR_RATE "rate from tcurr
         IMPORTING
              EXCHANGE_RATE    = L_CURR_RATE
              FOREIGN_FACTOR   = L_FF
              LOCAL_AMOUNT    = L_FA
              LOCAL_FACTOR     = L_TF
         EXCEPTIONS
            NO_RATE_FOUND    = 1
        OVERFLOW         = 2
        NO_FACTORS_FOUND = 3
        NO_SPREAD_FOUND  = 4
        OTHERS           = 5.


*  RESULT = 100.


Could you please check and let me know if am doing wrong.


Regards,

Vishu

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hello,

There are two methods to convert the currency. Mentioned two methods below.

You can follow either one.


1.  Same way you did. Please check the parameters once again. below is my code

  CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

          EXPORTING

            client            = sy-mandt
            date              = sy-datum
            foreign_amount    = l_wrbtr
            foreign_currency  = hdrcurrency
            local_currency    = 'USD'
*           RATE                 = 0
*           TYPE_OF_RATE      = 'M'
*           READ_TCURR        = 'X'
          IMPORTING
*           EXCHANGE_RATE     =
*           FOREIGN_FACTOR    =
            local_amount      = l_usd_amount
*           LOCAL_FACTOR      =
*           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 EQ 0.

2.  Multiply the Foreign amount with the exchange rate, then you will get the converted USD amount.. Recently I tried this , it works. Use FM below, it returns the latest exchange rate from TCURR table.

data: l_rate             TYPE UKURS_CURR.


CALL FUNCTION 'READ_EXCHANGE_RATE'
  EXPORTING
    CLIENT                  = SY-MANDT
    date                    = sy-datum
    foreign_currency        = l_waers
    local_currency          = 'USD'
    TYPE_OF_RATE            = 'M'
*   EXACT_DATE              = ' '
  IMPORTING
    EXCHANGE_RATE           = l_rate
*   FOREIGN_FACTOR          =
*   LOCAL_FACTOR            =
*   VALID_FROM_DATE         =
*   DERIVED_RATE_TYPE       =
*   FIXED_RATE              =
*   OLDEST_RATE_FROM        =
* EXCEPTIONS
*   NO_RATE_FOUND           = 1
*   NO_FACTORS_FOUND        = 2
*   NO_SPREAD_FOUND         = 3
*   DERIVED_2_TIMES         = 4
*   OVERFLOW                = 5
*   ZERO_RATE               = 6
*   OTHERS                  = 7

Now multiply the rate with the amount.


  itab-usd_amt = l_rate * itab-foreign_amount.

You can cross verify the result in Google .

please let me know if any questions.

Thanks

AV

Former Member
0 Likes

Hi AV, Thanks for quick replay.


I have little confusion with below line?


itab-usd_amt = l_rate * itab-foreign_amount.

What is itab-usd_amt ? and what is itab-foreign_amount.?


FYI, My source Kefigure ans target KF technical names are same.

i.e 0DEC_CRE_LC


Regards,

Vishu

Former Member
0 Likes

ok, are you converting the amount to a USD currency amount?  Is this your requirement?

I don't understand what is Key figures.

Former Member
0 Likes

Yea, I wanted to convert all currency amount(CAD, Etc..) to USD Cuurency.

0DEC_CRE_LC, This is standard key figure (Amount in Local currency) in SAP BW

Former Member
0 Likes

ok I am not familiar with Key figures , sorry but as per the code is concerned.


itab_usd_amount is nothing but  L_FA... which is amount field in your code.

so can you please try  like this

l_fa = l_rate * l_fa.

Answers (1)

Answers (1)

Ashokv
Explorer
0 Likes

Hi,

I can see that FM is called immediately after definition of data. So no values for FOREIGN_AMOUNT, FOREIGN_CURRENCY,TYPE_OF_RATE is getting passed. Make sure that you pass some values into it.

RATE is optional. So you can either pass some value or comment it out.


Thanks,


Ashok Veer

Former Member
0 Likes

Hi Ashok, Right seems the above parameters are not getting any values as my key figure values are become a zero in SAP BW after DTP ran.


But i need to confirm one thing. If you see in SS, We have 0FISCAL YEAR/PERIOD as 2015007 but actually i have to treat it as 2015.01. whether it will cause to my issue.

I have exchange rates for 2015.01.

Could you please let me know where was the problem occurs?

Former Member
0 Likes

Hi Everybody.

I changed my code and it works fine.

Thanks everybody for help