Application Development and Automation 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: 
Read only

Convert currency

Former Member
0 Likes
1,483

Hi,

I have amount value in a local variable lf_kzwi3 which I get from table vbap. I have to compare the document currency (vbak-waerk) with company code currency (t001-waers) and if it is not equal then I have to convert the kzwi3 value to company code currency and into EUR.

My query is that how do I convert the amount value in lf_kwzi3 to company code currency and EUR ?

Thank You,

SB.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,307

Below is the code for converting currency values from one currency to another. For demonstration purposes this example converts 10 euros into GBP. Please note when you display this value you may first need to convert it from its internal SAP value to the proper external display value. See here for more details.


 

DATA: gd_fcurr TYPE tcurr-fcurr,
      gd_tcurr TYPE tcurr-tcurr,
      gd_date  TYPE sy-datum,
      gd_value TYPE i.

gd_fcurr = 'EUR'.
gd_tcurr = 'GBP'.
gd_date  = sy-datum.
gd_value = 10.

PERFORM currency_conversion USING gd_fcurr
                                  gd_tcurr
                                  gd_date
                         CHANGING gd_value.



* Convert value to Currency value 
*&---------------------------------------------------------------------*
*&      Form  currency_conversion
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GD_FCURR  text
*      -->P_GD_TCURR  text
*      -->P_GD_DATE   text
*      <--P_GD_VALUE  text
*----------------------------------------------------------------------*
FORM currency_conversion  USING    p_fcurr
                                   p_tcurr
                                   p_date
                          CHANGING p_value.

  DATA: t_er        TYPE tcurr-ukurs,
        t_ff        TYPE tcurr-ffact,
        t_lf        TYPE tcurr-tfact,
        t_vfd       TYPE datum,
        ld_erate(12)   TYPE c.

  CALL FUNCTION 'READ_EXCHANGE_RATE'
    EXPORTING
*       CLIENT                  = SY-MANDT
      date                    = p_date
      foreign_currency        = p_fcurr
      local_currency          = p_tcurr
      TYPE_OF_RATE            = 'M'
*       EXACT_DATE              = ' '
   IMPORTING
      exchange_rate           = t_er
      foreign_factor          = t_ff
      local_factor            = t_lf
      valid_from_date         = t_vfd
*       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
            .
  IF sy-subrc EQ 0.
    ld_erate = t_er / ( t_ff / t_lf ).
    p_value = p_value * ld_erate.
  ENDIF.
ENDFORM. 
 

reward points if it is usefull ....

Girish

Hi,

I have amount value in a local variable lf_kzwi3 which I get from table vbap. I have to compare the document currency (vbak-waerk) with company code currency (t001-waers) and if it is not equal then I have to convert the kzwi3 value to company code currency and into EUR.

My query is that how do I convert the amount value in lf_kwzi3 to company code currency and EUR ?

Thank You,

SB.

5 REPLIES 5
Read only

Former Member
0 Likes
1,307

Convert the currency using FM - CONVERT_TO_LOCAL_CURRENCY

Reward Points if it is helpful

Thanks

Seshu

Read only

0 Likes
1,307

Thank You Seshu,

Can you please tell me what parameters I have to pass in the FM.

Thank You,

SB

Read only

0 Likes
1,307

I am not system and do where used list in SE37 Transaction

Read only

former_member194669
Active Contributor
0 Likes
1,307

May be u can use

fm CONVERT_TO_FOREIGN_CURRENCY

aRs

Read only

Former Member
0 Likes
1,308

Below is the code for converting currency values from one currency to another. For demonstration purposes this example converts 10 euros into GBP. Please note when you display this value you may first need to convert it from its internal SAP value to the proper external display value. See here for more details.


 

DATA: gd_fcurr TYPE tcurr-fcurr,
      gd_tcurr TYPE tcurr-tcurr,
      gd_date  TYPE sy-datum,
      gd_value TYPE i.

gd_fcurr = 'EUR'.
gd_tcurr = 'GBP'.
gd_date  = sy-datum.
gd_value = 10.

PERFORM currency_conversion USING gd_fcurr
                                  gd_tcurr
                                  gd_date
                         CHANGING gd_value.



* Convert value to Currency value 
*&---------------------------------------------------------------------*
*&      Form  currency_conversion
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GD_FCURR  text
*      -->P_GD_TCURR  text
*      -->P_GD_DATE   text
*      <--P_GD_VALUE  text
*----------------------------------------------------------------------*
FORM currency_conversion  USING    p_fcurr
                                   p_tcurr
                                   p_date
                          CHANGING p_value.

  DATA: t_er        TYPE tcurr-ukurs,
        t_ff        TYPE tcurr-ffact,
        t_lf        TYPE tcurr-tfact,
        t_vfd       TYPE datum,
        ld_erate(12)   TYPE c.

  CALL FUNCTION 'READ_EXCHANGE_RATE'
    EXPORTING
*       CLIENT                  = SY-MANDT
      date                    = p_date
      foreign_currency        = p_fcurr
      local_currency          = p_tcurr
      TYPE_OF_RATE            = 'M'
*       EXACT_DATE              = ' '
   IMPORTING
      exchange_rate           = t_er
      foreign_factor          = t_ff
      local_factor            = t_lf
      valid_from_date         = t_vfd
*       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
            .
  IF sy-subrc EQ 0.
    ld_erate = t_er / ( t_ff / t_lf ).
    p_value = p_value * ld_erate.
  ENDIF.
ENDFORM. 
 

reward points if it is usefull ....

Girish