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

currency selection

Former Member
0 Likes
833

Hi,

I am working on conversion of currency into local currency and USD. I have two put radio buttons

1. Radio button for USD (it will display the total value in USD)

suggest me the function module to convert the given currency into USD along with the total value here the input is currency and date to the FM. Please provide me the sample code to this.

2. Radio buttonLocal currency (Which display the total value in local currency)

I am finding the currency from T001 based on company code.I need to convert this currency into local currency.

suggest me the function module to do this and how to use the function module means, what are the parameters we need to (currency and date as input parameters) pass and in what parameters the required value is returned. Please provide me the sample code to this.

Please provide me the solution ASAP.

Thanks and Regards,

Latha.

3 REPLIES 3
Read only

Former Member
0 Likes
609

Hi,

ok this is how to do it:

Code:

-


Calculate_currency - convert currency to local *

-


FORM calculate_currency

USING

lv_date LIKE wa_data-fldate "date is needed as on current date should be set exchange rate (be carefull with type i left my original)

lv_foreign_amount LIKE lv_totalprice "number

lv_foreign_currency LIKE wa_data-currency "currency identificator

lv_local_currency TYPE c "currency identificator

CHANGING

lv_local_amount TYPE p. "number

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

EXPORTING

CLIENT = SY-MANDT

date = lv_date

foreign_amount = lv_foreign_amount

foreign_currency = lv_foreign_currency

local_currency = lv_local_currency

RATE = 0

TYPE_OF_RATE = 'M'

READ_TCURR = 'X'

IMPORTING

EXCHANGE_RATE =

FOREIGN_FACTOR =

local_amount = gv_local_amount

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

.

IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. "Calculate_currencytake a look on exceptions which you get after, it might be helpfull

Regards

Read only

Former Member
0 Likes
609

Hi,

For both cases, you can use FM CONVERT_TO_LOCAL_CURRENCY.

For the first option, pass LOCAL_CURRENCY as 'USD'.

For the second option, pass LOCAL_CURRENCY as T001-WAERS.

As per SAP documentation on 'CONVERT_TO_LOCAL_CURRENCY'

An amount in local currency is calculated from a specified foreign currency amount. For this, you may either specify the translation rate manually (Parameter RATE) or have the system determine it from table TCURR on the basis of the rate type, date and currency key. Because the ratios for the units of the currencies involved in the translation are significant for this translation, table TCURF is always read by the program, and there must be a valid entry there for the data specified. IF exchange rate fixing is defined for the exchange rate type TYPE_OF_RATE or an alternative exchange rate is defined for the currency pair, this information is transferred to the calling program.

When table TCURR is read, the foreign currency key is always taken as the first part of the key and the local currency as the second part.

Sample call-up:


  CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
    EXPORTING   DATE             = BKPF-WWERT
                FOREIGN_CURRENCY = BKPF-WAERS
               LOCAL_CURRENCY   = T001-WAERS
                FOREIGN_AMOUNT   = BSEG-WRBTR
                 RATE             = BKPF-KURSF
                 TYPE_OF_RATE     = 'M'
    IMPORTING   EXCHANGE_RATE    = KURS
                 LOCAL_AMOUNT     = BSEG-DMBTR
                FOREIGN_FACTOR   = FAKTOR-F
                 LOCAL_FACTOR     = FAKTOR-L
                 FIXED_RATE       = FIXKURS
    EXCEPTIONS  NO_RATE_FOUND    = 4
                NO_FACTORS_FOUND = 8.

Hope this helps.

Thanks,

Balaji

Read only

Former Member
0 Likes
609

hi try this code here int_display is internal table which i used...u have to use ur internal table and field....

LOOP AT int_display WHERE pstdat <> '00000000' AND waers <> ''.

CALL FUNCTION 'READ_EXCHANGE_RATE'

EXPORTING

client = sy-mandt

date = int_display-pstdat

foreign_currency = int_display-waers

local_currency = 'EUR'

type_of_rate = 'M'

  • EXACT_DATE = ' '

IMPORTING

exchange_rate = int_display-ukurs

  • FOREIGN_FACTOR =

  • LOCAL_FACTOR =

  • VALID_FROM_DATE =

  • 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 <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

int_display-lcamount = int_display-ukurs * int_display-amount.

ltot_hdr = ltot_hdr + int_display-LCamount.

<REMOVED BY MODERATOR>

thanks Amit

Edited by: Alvaro Tejada Galindo on Mar 18, 2008 6:19 PM