Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Currency conversions

$
0
0

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:

CURRENCY_CONVERSION01.png

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:

CURRENCY_CONVERSION02.png

Original of the article is at my blog (oprsteny.com)


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>