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: 

CONVERT_TO_LOCAL_CURRENCY wrong values

former_member612567
Participant
0 Kudos

Hi Friends,

When I am using the FM : 'CONVERT_TO_LOCAL_CURRENCY' in one of the program as below

ex :

gf_output_k-kbetr   = 12.54


gf_output_k-konwa  = USD           


g_waers                   = TWD


it is giving the output Local amount (gf_output_k-l_pir )in decimal point as 4.08.


but when I pass the same details to the TCODE : EWCT  , It is giving the Targeted amount (Local Amount) as 408.


when I kept the break point in FM , then Excute the Tcode EWCT , some where   "refe " value is storing as 408.


in my program why it is giving the output in decimal places 4.08.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

         EXPORTING

*   CLIENT                  = SY-MANDT

           DATE                    = sy-datum

           FOREIGN_AMOUNT          = gf_output_k-kbetr    

           FOREIGN_CURRENCY        = gf_output_k-konwa 

           LOCAL_CURRENCY          = g_waers                 

*   RATE                    = 0

           TYPE_OF_RATE            = 'M'

*   READ_TCURR              = 'X'

         IMPORTING

*   EXCHANGE_RATE           =

*   FOREIGN_FACTOR          =

           LOCAL_AMOUNT            = gf_output_k-l_pir

*   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

1 ACCEPTED SOLUTION

former_member612567
Participant
0 Kudos
Re: CONVERT_TO_LOCAL_CURRENCY wrong values

Hi all,

Thankyou for all your response.

I got the solution.

I have done As suggested by Gerrit Beukema.

I  tied the amount field to the currency field in the field catalog of your ALV.

Below is the Example logic.



data: begin of gt_output_k occurs 0,

        KBETR                     LIKE KONP-KBETR,            "Amount

         KONWA                 LIKE KONP-KONWA,            "CONDITION CURRENCY

         waers                     like t001-waers,                         "Local currency

         L_PIR                     type EINE-NETPR,                               "PIR in local currency    

         end of gt_output_k,


        gf_output_k like gt_output_k occurs 0 with header line.


" Forign Amount

  ls_fc-fieldname = 'KBETR'.       

   ls_fc-tabname = 'gf_output_k'.

   ls_fc-ref_tabname = 'KONP'.

* Reference fields for Currency

   ls_fc-cfieldname = 'KONWA'.    

   APPEND ls_fc TO lt_fc.

   CLEAR ls_fc.



" Forign currency Key


  ls_fc-fieldname = 'KONWA'.       

   ls_fc-tabname = 'gf_output_k'.

   ls_fc-ref_tabname = 'KONP'.

   ls_fc-seltext_l = 'Curr'.

   APPEND ls_fc TO lt_fc.

   CLEAR ls_fc

" Local currency key

     ls_fc-fieldname = 'WAERS'.                

     ls_fc-tabname = 'gf_output_k'.

     ls_fc-ref_tabname = 'T001'.

     ls_fc-seltext_l = 'Local currency'.

     ls_fc-no_out = 'X'.                 

     ls_fc-TECH = 'X'.                  

     APPEND ls_fc TO lt_fc.

     CLEAR ls_fc.

" Local Amount

     ls_fc-fieldname = 'L_PIR'.       

     ls_fc-tabname = 'gf_output_k'.

     ls_fc-ref_tabname = 'gf_output_k'.

     ls_fc-cfieldname = 'WAERS'. " M04

     ls_fc-seltext_l = 'Local currency Rate'.

     APPEND ls_fc TO lt_fc.

     CLEAR ls_fc.

9 REPLIES 9

Former Member
0 Kudos

Hi ,

There is nothing wrong with the fm but the problem is with the decimal places of the currency.Check table TCURX.

Regards

Nav

Former Member
0 Kudos

Hi,

Also check the default setting for your decimal point in the User Settings.

Hope this helps.

raymond_giuseppi
Active Contributor
0 Kudos

Build a snippet to check your values as the FM is widely used

Add some code to "visually" understand currency in Abap.


WRITE gf_output_k-kbetr CURRENCY gf_output_k-konwa. " before

WRITE gf_output_k-l_pir CURRENCY g_waers. " after conversion

Regards,

Raymond

ipravir
Active Contributor
0 Kudos

Hi Dhana,

You can check the BAPI_CURRENCY_GETDECIMALS Function module to pass the local currency.

If it's return decimal value as ZERO, means you are getting the right information through CONVERT_TO_LOCAL_CURRENCY FM, only in display the decimal is added in final value.

Regards,

Praveer.

former_member612567
Participant
0 Kudos

Hi Thankyou all for your response,

My requirement is converting into Local currency.

When we are using the FM, the Imported :Local currency(  gf_output_k-l_pir ) is of type NETPR (i.e) it holds 2 decimal points. so it is giving the output in decimal format.that we displying in ALV List Display.

It is working correct for some scenarioes.

but when I convert the currency from USD to TWD also it is giving the converted amount in decimal points. but for TWD currency it shold not disply in Decimal point.

How can I Achieve this prolem (i.e) for other currency conversion it should show in decimal format and when we converting into TWD it should not show Decimal format.

0 Kudos

You need to tie the amount field to the currency field in the field catalog of your ALV, then it will display with the correct number of decimal places.

See SAP help and

0 Kudos

Hi Beukema,

I have tried binding the reference field to field catalog still it is not working for all scenarios.

Ex Logic :

gf_output_k is the final table which we are pasiing to ALV grid.


data: begin of gt_output_k occurs 0,

        KBETR  LIKE KONP-KBETR,            "Amount

         KONWA  LIKE KONP-KONWA,            "CONDITION CURRENCY

         waers  like t001-waers,                         "Local currency

         L_PIR type char20,                               "PIR in local currency     

         end of gt_output_k,


        gf_output_k like gt_output_k occurs 0 with header line.

  ls_fc-fieldname = 'KBETR'.        " Amount

   ls_fc-tabname = 'gf_output_k'.

   ls_fc-ref_tabname = 'KONP'.

* Reference fields for Currency

   ls_fc-cfieldname = 'KONWA'.     

   APPEND ls_fc TO lt_fc.

   CLEAR ls_fc.


  ls_fc-fieldname = 'KONWA'.        " COND CURR

   ls_fc-tabname = 'gf_output_k'.

   ls_fc-ref_tabname = 'KONP'.

   ls_fc-seltext_l = 'Curr'.

   APPEND ls_fc TO lt_fc.

   CLEAR ls_fc.

    ls_fc-fieldname = 'WAERS'.        " Local currency

     ls_fc-tabname = 'gf_output_k'.

     ls_fc-ref_tabname = 'T001'.

     ls_fc-seltext_l = 'Local currency'.

     APPEND ls_fc TO lt_fc.

     CLEAR ls_fc.

    ls_fc-fieldname = 'L_PIR'.        " Local Amount

     ls_fc-tabname = 'gf_output_k'.

     ls_fc-ref_tabname = 'gf_output_k'.

     ls_fc-cfieldname = 'WAERS'. " M04

     ls_fc-seltext_l = 'Local currency Rate'.

     APPEND ls_fc TO lt_fc.

     CLEAR ls_fc.

0 Kudos

Hi Dhana,

When you are converting the currency the value gets converted to the default currency (suppose your default currency is INR then the value gets converted to it and as it has two decimal places the value appears in two decimal places format) So you can multiply it with 10 raised to n to get the exact value you want.

Regards

Nav

former_member612567
Participant
0 Kudos
Re: CONVERT_TO_LOCAL_CURRENCY wrong values

Hi all,

Thankyou for all your response.

I got the solution.

I have done As suggested by Gerrit Beukema.

I  tied the amount field to the currency field in the field catalog of your ALV.

Below is the Example logic.



data: begin of gt_output_k occurs 0,

        KBETR                     LIKE KONP-KBETR,            "Amount

         KONWA                 LIKE KONP-KONWA,            "CONDITION CURRENCY

         waers                     like t001-waers,                         "Local currency

         L_PIR                     type EINE-NETPR,                               "PIR in local currency    

         end of gt_output_k,


        gf_output_k like gt_output_k occurs 0 with header line.


" Forign Amount

  ls_fc-fieldname = 'KBETR'.       

   ls_fc-tabname = 'gf_output_k'.

   ls_fc-ref_tabname = 'KONP'.

* Reference fields for Currency

   ls_fc-cfieldname = 'KONWA'.    

   APPEND ls_fc TO lt_fc.

   CLEAR ls_fc.



" Forign currency Key


  ls_fc-fieldname = 'KONWA'.       

   ls_fc-tabname = 'gf_output_k'.

   ls_fc-ref_tabname = 'KONP'.

   ls_fc-seltext_l = 'Curr'.

   APPEND ls_fc TO lt_fc.

   CLEAR ls_fc

" Local currency key

     ls_fc-fieldname = 'WAERS'.                

     ls_fc-tabname = 'gf_output_k'.

     ls_fc-ref_tabname = 'T001'.

     ls_fc-seltext_l = 'Local currency'.

     ls_fc-no_out = 'X'.                 

     ls_fc-TECH = 'X'.                  

     APPEND ls_fc TO lt_fc.

     CLEAR ls_fc.

" Local Amount

     ls_fc-fieldname = 'L_PIR'.       

     ls_fc-tabname = 'gf_output_k'.

     ls_fc-ref_tabname = 'gf_output_k'.

     ls_fc-cfieldname = 'WAERS'. " M04

     ls_fc-seltext_l = 'Local currency Rate'.

     APPEND ls_fc TO lt_fc.

     CLEAR ls_fc.