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

Function Module for Currency conversion

SG141
Active Participant
0 Likes
7,231

I there any FM available for Currency Conversion from one to another....

9 REPLIES 9
Read only

Former Member
0 Likes
2,483

Karthik,

Use

<b>CONVERT_TO_LOCAL_CURRENCY

CONVERT_TO_FOREIGN_CURRENCY</b>

Regards

Aneesh.

Read only

SG141
Active Participant
0 Likes
2,483

I mean the exchange rate between two currencies on a given date...(typically sy-datum)

Read only

Former Member
0 Likes
2,483

Yes this will work for a given date...

Read only

Former Member
0 Likes
2,483

Hello

Check this sample I found on sdn:

Please check this..for sure it will help you.

First get the Exchange rate for the Currency.

Then get the Currency conversion factor, and Multiply the Document cuurency * Exchange rate * Conversion factor.

CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 5.

*

  • If Document Currncy in SGD, Donot Display Exchange Rate XXX

  • Condition for SGD and SGD4

IF wa_bkpf-waers+0(3) NE 'SGD'.

*

v_fmcur = wa_bkpf-waers.

  • Get Current Exchange Rate - Ref: SD Logic

IF ( NOT v_fmcur IS INITIAL ) AND ( NOT wa_bkpf-budat IS INITIAL ).

*

CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'

EXPORTING

rate_type = 'M'

from_curr = 'SGD'

to_currncy = v_fmcur

date = wa_bkpf-budat

IMPORTING

exch_rate = v_kurs2.

ENDIF.

  • Get Conversion Factor

CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'

EXPORTING

currency = wa_bkpf-waers

importing

factor = v_fact

exceptions

too_many_decimals = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE s208(00) WITH

'May be too many Decimals for Currency Factor'(013).

ENDIF.

*

IF v_kurs2-exch_rate NE 0.

  • Inverse the Exchange Rate from USD to SGD

v_exrat = 1 / ( v_kurs2-exch_rate ).

*

WRITE v_exrat TO wa_summary-exrat DECIMALS 4.

*

v_wrbtr = ( v_tamnt * v_exrat * v_fact ).

v_taxsum1 = ( v_taxsum * v_exrat * v_fact ).

v_ntotl = ( v_dmbtr * v_exrat * v_fact ).

ELSE.

WRITE:/ 'Over flow, Exchange rate is ZERO'(005).

ENDIF.

CLEAR v_kurs2.

ELSE.

wa_summary-exrat = 1.

v_wrbtr = ( v_tamnt * 1 ).

v_taxsum1 = ( v_taxsum * 1 ).

v_ntotl = ( v_dmbtr * 1 ).

ENDIF.

*

ENDCATCH.

IF sy-subrc = 5.

WRITE: / 'Overflow! Sum can not be calculated.'(011).

ENDIF.

<b><REMOVED BY MODERATOR></b>

Gabriel

Message was edited by:

Alvaro Tejada Galindo

Read only

Former Member
0 Likes
2,483

Karthik,

Try,

<b>READ_EXCHANGE_RATE

CALCULATE_EXCHANGE_RATE</b>

If those wont work you have to code it urself.

All the exchange rates are stored in <b>TCURR</b>

Regards

Aneesh.

Read only

SG141
Active Participant
0 Likes
2,483

read_exchange_rate and

convert_to_local_currency are returing exceptions when i am test on it....

can some one let me know how to use it....

Read only

Former Member
0 Likes
2,483

CONVERT_TO_LOCAL_CURRENCY

Read only

Former Member
0 Likes
2,483

You can take a look at these two FMs.

CONVERT_TO_FOREIGN_CURRENCY

CONVERT_TO_LOCAL_CURRENCY

Read only

Former Member
0 Likes
2,483

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