In this article I'd like to show an easy approach on how to convert an amount given in one currency to another currency and warn you before a possible bug in SAP standard FM used for currency conversions.
DATA:
l_in(15) TYPE p DECIMALS 5,
l_out(15) TYPE p DECIMALS 5.
l_in = 1.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
date = sy-datum
foreign_amount = l_in
foreign_currency = 'EUR'
local_currency = 'DKK'
IMPORTING
local_amount = l_out
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: l_in, 'EUR = ', l_out, 'DKK'.
ENDIF.
Result of the program is:
IMPORTANT NOTE (valid at 2014-05-27): It is VERY important to use variables defined equally - having the same precision/decimal places and length. Otherwise the results might be VERY surprising: check the following modification with different decimal precision on INPUT and OUTPUT
DATA:
l_in(15) TYPE p DECIMALS 5,
l_out(15) TYPE p DECIMALS 3.
l_in = 1.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
date = sy-datum
foreign_amount = l_in
foreign_currency = 'EUR'
local_currency = 'DKK'
IMPORTING
local_amount = l_out
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: l_in, 'EUR = ', l_out, 'DKK'.
ENDIF.
Result of the second example:
Original of the article is at my blog (oprsteny.com)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Subject | Kudos |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User | Count |
---|---|
5 | |
5 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 |