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: 

FM convert_to_local_currency

Former Member
0 Kudos

Hi experts,

i am trying to use the FM covert to local curreny to convert currency to USD. But the local amount shows up 100 times the actual. Please suggest.

Below is my code.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

    EXPORTING

      date              = re_outtab_purchdoc-bedat

      foreign_amount    = re_outtab_purchdoc-netwr

      foreign_currency  = re_outtab_purchdoc-waers

      local_currency    = LV_CURR

*     RATE              = 0

*     TYPE_OF_RATE      = 'M'

*     READ_TCURR        = 'X'

    IMPORTING

*     EXCHANGE_RATE     =

*     FOREIGN_FACTOR    =

      local_amount      = re_outtab_purchdoc-NETVALC

*     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.

25 REPLIES 25

SharathSYM
Contributor
0 Kudos

Hi,

try this.......

CALL FUNCTION 'READ_EXCHANGE_RATE'

           EXPORTING

             date             = sy-datlo

             foreign_currency = foreign_currency

             local_currency   = lv_curr

             type_of_rate     = 'P'       "Standard translation for cost planning

           IMPORTING

             exchange_rate    = l_kursf

           EXCEPTIONS

             error_message    = 1.


CALL FUNCTION 'CURRENCY_AMOUNT_DISPLAY_TO_SAP'

EXPORTING

           currency        =  foreign_currency

           amount_display  =  foreign_amount

         IMPORTING

           amount_internal = converted_amount

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

    EXPORTING

      date              = re_outtab_purchdoc-bedat

      foreign_amount    = converted_amount

      foreign_currency  = foreign_currency

      local_currency    = LV_CURR

     rate             = l_kursf

     type_of_rate     = 'P'               "Standard translation for cost planning

     date             = sy-datlo

IMPORTING

           local_amount     = lv_amount

CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'

           EXPORTING

             currency        = LV_CURR      

             amount_internal = lv_amount

           IMPORTING

             amount_display  = lv_amount          "FINAL AMOUNT Converted

Thanks,

Sharath

Former Member
0 Kudos

Hi,

i tried it in this way:

and it works. Have also a look into table TCURR.

Regards, Dieter

0 Kudos

Hi,

Can you try the same with local currency = 'KWD'?

Please observe the o/p.

100 USD = 29.48 KWD


Regards

Sreekanth

VenkatRamesh_V
Active Contributor
0 Kudos

Hi,

Try,

CALL FUNCTION 'CONVERT_AMOUNT_TO_CURRENCY'

Hope it helpful.

Regards,

Venkat.

Former Member
0 Kudos

Local amount is 100x more then it should be or its just appear on output 100x more? Because i had this problem with CURR 22 5 - in debug mode it had correct value, but in ALV output it was 100x more. My solution(and I admitt - not very good) was to add one more CURR field for output with 13 length 5 decimals.

0 Kudos

local amounts are appearing 100 times more. eg: instead of 1 USD it appears as 100 USD

0 Kudos

Try to use for output variable:

DATA: lv_out_amout  TYPE p LENGTH 13 DECIMALS 5.

lv_out_amount  =  re_outtab_purchdoc-netwr

Former Member
0 Kudos

Hi ,

  What 's  your local currency. Some small currency will be enlarge when it display.

pls check first.

Hope this will help you..

Former Member
0 Kudos

none of above are working for me.

0 Kudos

Hi,

did you have a look into TCURR?

Regards, Dieter

0 Kudos

TCURR is having the exchange rate for the currencies which i am trying to convert. is there anything else that i have to look into TCURR?

Former Member
0 Kudos

hi lavanya,

You have to use fm 'CONVERSION_EXIT_EXCRT_OUTPUT'

to get correct exchange rate

CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT'

   EXPORTING

     input         = IT_OUTPUT-EXR

IMPORTING

   OUTPUT        = ex_rate.


ex_rate will have correct exchange rate.



0 Kudos

hi,

may i know what is it_output-exr

and also should i use this FM before CONVERT_TO_LOCAL_CURRENCY' or after?

0 Kudos

it_output-exr or exr is the exchange rate.

add in your code like this

    IMPORTING

     EXCHANGE_RATE     = exr

*     FOREIGN_FACTOR    =

      local_amount      = re_outtab_purchdoc-NETVALC

*     LOCAL_FACTOR      =

after this (CONVERT_TO_LOCAL_CURRENC)  use fm 'CONVERSION_EXIT_EXCRT_OUTPUT'


and check the values ex_rate.

0 Kudos

thanks for your response. but my doubt is we are only getting the exc rate but how is the currency getting processed here?

i got a dump when i tried the above FM

0 Kudos

please give some values(actual parameters each one) so that it can be tried as per your requirement.

0 Kudos

in the standard ME2N transaction i have implemented the below enhancement

DATA: COMM_CUR TYPE EKKO-WAERS,

        LV_CURR  TYPE EKKO-WAERS.

*  Import common currency entered on the selection-screen

   IMPORT COMM_CUR TO LV_CURR FROM MEMORY ID 'ZME2N'.

   re_outtab_purchdoc-WAERSC = LV_CURR.

* If the common currency on the selection-screen is not same as the currency in PO

* then do the currency conversion

   if re_outtab_purchdoc-waers ne LV_CURR and not lv_curr is initial.

     CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

    EXPORTING

      date              = re_outtab_purchdoc-bedat

      foreign_amount    = re_outtab_purchdoc-netwr

      foreign_currency  = re_outtab_purchdoc-waers

      local_currency    = LV_CURR

*     RATE              = 0

*     TYPE_OF_RATE      = 'M'

*     READ_TCURR        = 'X'

    IMPORTING

*     EXCHANGE_RATE     =

*     FOREIGN_FACTOR    =

      local_amount      = re_outtab_purchdoc-NETVALC

*     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.

   ELSE.

     re_outtab_purchdoc-NETVALC = re_outtab_purchdoc-netwr.

   endif.

now because of this enhancement value re_outtab_purchdoc-NETVALC is coming 100 time more

i do not understand where is the flaw.

please suggest

0 Kudos

please give the values of

1) LV_CURR.

2) re_outtab_purchdoc-bedat

3) re_outtab_purchdoc-netwr

4) re_outtab_purchdoc-waers

you can get these values while debug

0 Kudos

1) LV_CURR.- USD

2) re_outtab_purchdoc-bedat   20150204    

3) re_outtab_purchdoc-netwr    4.06

4) re_outtab_purchdoc-waers   XAF

0 Kudos

can you share the result after you run this piece of code:

DATA: XRATE TYPE F,
       FAMT TYPE P DECIMALS 2,
       FFACT TYPE F,
       LFACT TYPE F.

PARAMETERS: FCURR LIKE TCURC-WAERS,
             LCURR LIKE TCURC-WAERS,
             LAMT TYPE P DECIMALS 2.

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
   EXPORTING
     DATE                    = SY-DATUM
     FOREIGN_CURRENCY        = FCURR
     LOCAL_AMOUNT            = LAMT
     LOCAL_CURRENCY          = LCURR
  IMPORTING
    EXCHANGE_RATE           = XRATE
    FOREIGN_AMOUNT          = FAMT
    FOREIGN_FACTOR          = FFACT
    LOCAL_FACTOR            = LFACT
           .


IF SY-SUBRC EQ 0.
   WRITE: / LAMT, 'CONVERTED FROM', LCURR, 'TO', FCURR, 'IS:', FAMT.
   WRITE: / 'EXCHANGE RATE: ', XRATE,
          / 'FOREIGN FACTOR:', FFACT,
          / 'LOCAL FACTOR:', LFACT.
ELSE.
   WRITE: 'UNABLE TO CONVERT'.
ENDIF.

former_member202818
Active Contributor
0 Kudos

Hi Lavanya,

Unchecked the fixed point arithmetic in program attribute.

And re_outtab_purchdoc-NETVALC should be a variable with 2 decimal places.

Regards

Sreekanth

former_member202818
Active Contributor
0 Kudos

Better to do this in a separate subroutine pool program and create a form(refer attachment).

call this form from your program as shown..

PERFORM currency_to_local(zsmm_create_fcurr_to_lcurr)

                                        USING fc_waers

                                                   lc_waers

                                                   netpr

                                                   kdatu

                                                   kkurs

                                                   kufix.

0 Kudos

it is a standard transaction and i do not think i can do this

0 Kudos

Its possible.

se38->create a program of type subroutine pool(say zsmm_create_fcurr_to_lcurr ) and create the form as I said. Remember to uncheck Fixed point arithmetic in this subroutine pool.

Then call the form.

PERFORM currency_to_local(zsmm_create_fcurr_to_lcurr)

                                        USING fc_waers

                                                     lc_waers

                                                     netpr

                                                     kdatu

                                                     kkurs

                                                     kufix.

What is the type of re_outtab_purchdoc?

Former Member
0 Kudos

Hi,

did you try my example esp. the declaration of the variables?

Can you please Show your declarations.

Regards, Dieter