Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
1,441

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)

1 Comment
Labels in this area