Like unit conversion , currency conversion is also one of the most needed operation. And for this kind of common operations we should have code snippets. Here is a sample usage for currency conversion.
*** Currency Conversion
if lv_waers_from ne lv_waers_to.
perform convert_currency using lv_waers_from
lv_waers_to
changing lv_wrbtr.
endif.
*-------------------------------------------
* Form convert_currency
*-------------------------------------------
FORM convert_currency USING p_from_waers
p_to_waers
CHANGING p_wrbtr.
DATA : lv_ukurs TYPE tcurr-ukurs .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
date = gv_keydate
foreign_amount = p_wrbtr
foreign_currency = p_from_waers
local_currency = p_to_waers
IMPORTING
exchange_rate = lv_ukurs
EXCEPTIONS
no_rate_found = 1
overflow = 2
no_factors_found = 3
no_spread_found = 4
derived_2_times = 5
OTHERS = 6.
CHECK sy-subrc EQ 0.
p_wrbtr = p_wrbtr * lv_ukurs.
ENDFORM. " convert_currency
No comments:
Post a Comment