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 Conversion- Urgent

Former Member
0 Likes
698

Hi

Currency S_WAERS is in my selection screen.

If i enter USD For S_waers the amount should convert to USD.

If i leave blank it should take local currency.

Any one pls give me the coding for this.

Thanks

Kumar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
669

Just search SE37 with CONVERTCURRENCY* or the CURRENCYCONVERT* you will find lots of FM.

Regards,

Atish

Hi

Currency S_WAERS is in my selection screen.

If i enter USD For S_waers the amount should convert to USD.

If i leave blank it should take local currency.

Any one pls give me the coding for this.

Thanks

Kumar

4 REPLIES 4
Read only

peter_ruiz2
Active Contributor
0 Likes
669

hi kumar,

use this FM

CONVERT_CURRENCY_BY_RATE

regards,

Peter

Read only

0 Likes
669

Hi

what are the mandatory fields for this FM. I tried this. But it is not working properly

Read only

Former Member
0 Likes
670

Just search SE37 with CONVERTCURRENCY* or the CURRENCYCONVERT* you will find lots of FM.

Regards,

Atish

Read only

Former Member
0 Likes
669

Hi,

First, you should judge the amount's reference currency.

I take other currency as example, that is, the amount stores as neither USD nor local currency.

Functions will be used:

get local currency's FM:

1) LOCAL_CURRENCY_GET:

(this function returns the local currency by sales organization and distribution chanel or plant )

CALL FUNCTION 'LOCAL_CURRENCY_GET'

EXPORTING

PI_VKORG = ??sales organization

PI_VTWEG = ? distribution chanel

PI_WERKS = ? Plant

IMPORTING

PE_HWAER = ? local currency

EXCEPTIONS

INVALID_INPUT = 1

CURRENCY_NOT_DETERMINED = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

2) FMR3_GET_LOCAL_CURRENCY:

(this function returns the local currency by company code)

CALL FUNCTION 'FMR3_GET_LOCAL_CURRENCY'

EXPORTING

I_BUKRS = ? company code

IMPORTING

E_HWAER = ? local currency

  • E_FIKRS =

  • E_KOKRS =

  • EXCEPTIONS

  • INVALID_WAERS = 1

  • WRONG_BUKRS = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

convert the amount to the target currency amont:

CONVERT_TO_LOCAL_CURRENCY

(this function returns the target amount)

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

EXPORTING

DATE = SY-DATUM

FOREIGN_AMOUNT = ? amount

FOREIGN_CURRENCY = ? currency the amount stores

LOCAL_CURRENCY = ? target currency

IMPORTING

LOCAL_AMOUNT = ? target amount

IF SY-SUBRC <> 0.

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

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

ENDIF.

Therefore, the logic is :

if usd, CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY' set the target currency as USD then you'll get target amount

if blank, call the get local currency's FM and CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY' ,set the target currency as the local currency you get.

Hope it can help you.

regards

vincent.