SAP汇率转换的操作

今天碰到需要进行汇率转换的操作,下面代码挺有用的。

REPORT  z_barry_convert_currency                .

DATA: jine  LIKE bseg-wrbtr  .
DATA: date LIKE sy-datum .
DATA: curr_ex LIKE bapicurr-bapicurr .

date = '20060831' .

DATA: fa LIKE bseg-wrbtr ,
      fc LIKE t001-waers ,
      lc LIKE t001-waers ,
      ty LIKE tcurr-kurst .

fa = 100.
fc = 'JPY' .
lc = 'RMB' .
ty = 'M'.

curr_ex = fa .
CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_INTERNAL'
  EXPORTING
    currency             = fc
    amount_external      = curr_ex
    max_number_of_digits = 13
  IMPORTING
    amount_internal      = fa.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
  EXPORTING
    date             = date
    foreign_amount   = fa
    foreign_currency = fc
    local_currency   = lc
    type_of_rate     = ty
  IMPORTING
    local_amount     = jine
  EXCEPTIONS
    no_rate_found    = 1
    OTHERS           = 2.


WRITE:/ jine .

 

REPORT ztest.

DATA: USD TYPE WRBTR, JPY TYPE WRBTR, JPY_E TYPE BAPICURR-BAPICURR.
DATA: USD_K TYPE WAERS, JPY_K TYPE WAERS.
DATA: RET TYPE BAPIRETURN.

JPY = '10000.01'.
USD_K = 'USD'.
JPY_K = 'JPY'.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
  EXPORTING
    date                    = SY-DATUM
    foreign_amount          = JPY
    foreign_currency        = JPY_K
    local_currency          = USD_K
IMPORTING
   LOCAL_AMOUNT            = USD
          .

WRITE: JPY CURRENCY JPY_K, JPY_K,
       USD CURRENCY USD_K, USD_K.

ULINE.

JPY_E = JPY.

CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_INTERNAL'
  EXPORTING
    currency                   = JPY_K
    amount_external            = JPY_E
    max_number_of_digits       = 23
IMPORTING
   AMOUNT_INTERNAL            = JPY
   RETURN                     = RET
          .

IF RET IS NOT INITIAL.
  MESSAGE ID RET-CODE(2) TYPE RET-TYPE NUMBER RET-CODE+2(3)
    WITH RET-MESSAGE_V1 RET-MESSAGE_V2 RET-MESSAGE_V3 RET-MESSAGE_V4.
ENDIF.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
  EXPORTING
    date                    = SY-DATUM
    foreign_amount          = JPY
    foreign_currency        = JPY_K
    local_currency          = USD_K
IMPORTING
   LOCAL_AMOUNT            = USD.

WRITE: JPY CURRENCY JPY_K, JPY_K,
       USD CURRENCY USD_K, USD_K.

 

 

注意点:

1.Exporting各个参数一定不能用常量,要用变量

2.汇率存放在表:TCURR中,另外TCUR*有关于汇率的其他数据

3.碰到比较变态的货币,例如日元,它们是没有小数点的,系统内存储的和你看到的不同,有个BAPI可以使用:BAPI_CURRENCY_CONV_TO_INTERNAL

4.维护汇率的Tcode:OB07、OB08

5.汇率转换的函数都在LSCUNUXX程序中

其他链接:

http://www.itpub.net/thread-898494-1-1.html#

http://kemiya.net/forum.php?mod=viewthread&tid=538

 

你可能感兴趣的:(ABAP,Code)