SAP汇率转换函数[BAPI_EXCHANGERATE_GETDETAIL]

BAPI_EXCHANGERATE_GETDETAIL 用法:

tables : tcurr .

data :  g_waers  type   tcurr-UKURS  .

data :  exr   type BAPI1093_0 ,
           exr2 type BAPI1093_0 .

"定义一个宏
define ZWAERS .
  clear: exr , exr2 .
  CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
    EXPORTING
      RATE_TYPE          =  'M'
      FROM_CURR         =  &1
      TO_CURRNCY       =  &2
      DATE                    =  sy-datum
   IMPORTING
     EXCH_RATE          = exr
*     RETURN           =
            .
  CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
    EXPORTING
      RATE_TYPE         =  'M'
      FROM_CURR        =  &2
      TO_CURRNCY      =  &1
      DATE                   =  sy-datum
   IMPORTING
     EXCH_RATE         = exr2
*     RETURN           =
            .
   if exr-valid_from >= exr2-valid_from .
      &3 = exr-EXCH_RATE .            "如果日期為 0 ,則rate為0
   else.
      &3 = 1 / exr2-EXCH_RATE .      "exr2肯定不為0
   endif.
 end-of-definition .

"调用宏

 ZWAERS  原货币  目标货币   g_waers .

 

金额缩放

1、使用function module CURRENCY_CONVERTING_FACTOR进行转换

DATA:LV_FACTOR   TYPE ISOC_FACTOR

DATA:lv_wrbtr TYPE bseg-wrbtr.

DEFINE  DEFINE_CURY_CONVER.
  CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
  EXPORTING
    currency = &1
  IMPORTING
    factor   = &2.
END-OF-DEFINITION.

DEFINE_CURY_CONVER 币种 LV_FACTOR.

lv_wrbtr = lv_wrbtr * lv_factor.

2.使用function module CURRENCY_AMOUNT_SAP_TO_DISPLAY或CURRENCY_AMOUNT_DISPLAY_TO_SAP进行转换

DATA:lv_amount TYPE wmto_s-amount.

SELECT SINGLE wrbtr INTO lv_amount FROM bseg WHERE bukrs = '1210' AND belnr = '0100000006'.

WRITE:/'JPY转换前:',lv_amount.

CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
EXPORTING
currency = 'JPY'
amount_internal = lv_amount
IMPORTING
amount_display = lv_amount
EXCEPTIONS
internal_error = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE:/'JPY转换后:',lv_amount.
ENDIF.

posted @ 2022-03-16 13:58  下一詀110  阅读(648)  评论(0编辑  收藏  举报