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: 

currency conversion

Former Member
0 Kudos

Hi experts,

Can anybody give me the Function Module name to convert one currency into another currency with the mandatory parameters. I used a Function module HR_ECM_CONVERT_CURRENCY to convert amount from EUR to DEM but if i give 1, the amount in DEM comes as 0. if i give 1.0, then it returns, 2. and for 1.00, it returns 20. So for a same number with different decimal places, it returns a dfferent amount. What is the actual conversion taking place here. Using which FM will provide the correct conversion.

Thanks in advance,

Shanthi.

4 REPLIES 4

Former Member
0 Kudos

Hi Shanthi,

Try CONVERT_TO_FOREIGN_CURRENCY

Have a look at the below link for an example.

Regards,

Lijo Joseph

*Reward if useful

Message was edited by:

Lijo Vazhappilly

Former Member

0 Kudos

Hiii ,

You can use the field kursk from vbrp directly to get the rate of dollar or dem at that date and directly multipy the rate with it .You will get the local currency amount .

Or else u can use the function module suggested by others

Regards,

Rupa

Former Member
0 Kudos

Hi

CURRENCY_AMOUNT_SAP_TO_DISPLAY

Convert currency value from value stored in SAP to displayed currency

CURRENCY_AMOUNT_DISPLAY_TO_SAP

Convert currency value from displayed currency value to value stored in SAP

CONVERT_TO_FOREIGN_CURRENCY

Convert local currency to foreign currency.

CONVERT_TO_LOCAL_CURRENCY

Convert from foreign currency to local currency

HRWPC_RFC_CURCY_TEXT_GET

Get text description for Currency Key

<b>This is a sample report to convert EUR to GBP</b>

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.                    " currency_conversion

<b>This report is to convert USD to JPY</b>

data: w_dec1 like tcurx-currdec,
w_amt like ekpo-netwr,
w_rate like tcurr-ukurs,
w_fact1 like tcurr-ffact,
w_fact2 like tcurr-ffact.
 
 
parameters:
p_curr1 like tcurc-waers default 'USD',
p_amt1 like ekpo-netwr default '100',
p_curr2 like tcurc-waers default 'JPY',
pdate like sy-datum default sy-datum.
 
end-of-selection.
  write:
  / 'Entered:',
  / ' from currency:', p_amt1 currency p_curr1, p_curr1, '<-', p_amt1,
  / ' to currency :', p_curr2,
  / ' on :', pdate.
  CALL FUNCTION 'FWOS_CURRENCY_DECIMALS_READ'
    EXPORTING
      I_CURRENCY         = p_curr1
    IMPORTING
      E_DECIMALS         = w_dec1
    EXCEPTIONS
      I_CURRENCY_INITIAL = 1
      OTHERS             = 2.
  IF SY-SUBRC <> 0.
    w_dec1 = 2.
  ENDIF.
  p_amt1 = p_amt1 * 10 ** ( w_dec1 - 2 ).
  write:
  / 'after adjusting using currency decimals:',
  / ' from currency', p_amt1 currency p_curr1, p_curr1,
  '<-', p_amt1, '(', w_dec1, ')'.
 
  CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
  EXPORTING
* CLIENT = SY-MANDT
  DATE = pdate
  FOREIGN_CURRENCY = p_curr2
  LOCAL_AMOUNT = p_amt1
  LOCAL_CURRENCY = p_curr1
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
  IMPORTING
  EXCHANGE_RATE = w_rate
  FOREIGN_AMOUNT = w_amt
  FOREIGN_FACTOR = w_fact1
  LOCAL_FACTOR = w_fact2
* EXCHANGE_RATEX =
* DERIVED_RATE_TYPE =
* FIXED_RATE =
  EXCEPTIONS
  NO_RATE_FOUND = 1
  OVERFLOW = 2
  NO_FACTORS_FOUND = 3
  NO_SPREAD_FOUND = 4
  DERIVED_2_TIMES = 5
  OTHERS = 6.
  IF SY-SUBRC <> 0.
    write: / 'Conversion to for.curr. failed:',
    p_curr1, '->', p_curr2, 'err.code=', sy-subrc.
  ELSE.
    write: / 'to For.curr:', p_amt1 currency p_curr1, p_curr1, '->',
    w_amt currency p_curr2, p_curr2,
    '(', w_rate, ')', w_fact1, w_fact2.
  ENDIF.
 
  CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
  EXPORTING
* CLIENT = SY-MANDT
  DATE = pdate
  FOREIGN_AMOUNT = p_amt1
  FOREIGN_CURRENCY = p_curr1
  LOCAL_CURRENCY = p_curr2
* RATE = 0
* TYPE_OF_RATE = 'M'
* READ_TCURR = 'X'
  IMPORTING
  EXCHANGE_RATE = w_rate
  FOREIGN_FACTOR = w_fact1
  LOCAL_AMOUNT = w_amt
  LOCAL_FACTOR = w_fact2
* 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 <> 0.
    write: / 'Conversion to loc.curr. failed:',
    p_curr1, '->', p_curr2, 'err.code=', sy-subrc.
  ELSE.
    write: / 'to Loc.curr:', p_amt1 currency p_curr1, p_curr1, '->',
    w_amt currency p_curr2, p_curr2,
    '(', w_rate, ')', w_fact1, w_fact2.
  ENDIF.

Check this link

http://www.sapdevelopment.co.uk/fmodules/curr_distosap.htm

Reward all helpfull answers

Regards

Pavan