阅读更多
调用:PERFORM frm_get_rate USING u_t-pswsl 'RMB' l_date1
CHANGING l_wrbtr.
函数定义:
1:FORM frm_get_rate USING u_fc TYPE bapi1093_1-from_curr
u_tc TYPE bapi1093_1-from_curr
u_date TYPE bapi1093_2-trans_date
CHANGING c_tot TYPE bapibp_bal_amt2.
DATA: l_return TYPE bapiret1,
l_msg(100) TYPE c.
CALL FUNCTION 'Z_EXCHANGERATE_CONVERSION'
EXPORTING
rate_type = 'M'
from_curr = u_fc
to_currncy = u_tc
date = u_date
IMPORTING
return = l_return
CHANGING
amount = c_tot.
* 汇率获取失败的信息提示
IF l_return IS NOT INITIAL.
CONCATENATE u_date u_fc
'<->' u_tc '的汇率不存在'
INTO l_msg.
MESSAGE e000(z03) WITH l_msg.
ENDIF.
ENDFORM. " FRM_GET_RATE
2:FUNCTION Z_EXCHANGERATE_CONVERSION.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(RATE_TYPE) TYPE BAPI1093_1-RATE_TYPE DEFAULT 'M'
*" VALUE(FROM_CURR) TYPE BAPI1093_1-FROM_CURR
*" VALUE(TO_CURRNCY) TYPE BAPI1093_1-TO_CURRNCY
*" VALUE(DATE) TYPE BAPI1093_2-TRANS_DATE DEFAULT SY-DATUM
*" EXPORTING
*" VALUE(RETURN) TYPE BAPIRET1
*" CHANGING
*" VALUE(AMOUNT) TYPE BAPIBP_BAL_AMT2
*"----------------------------------------------------------------------
DATA: V_CHAR_E TYPE C VALUE 'E',
V_CHAR_A TYPE C VALUE 'A'.
DATA: EXCH_RATE LIKE BAPI1093_0.
** Clear output parameters
CLEAR: EXCH_RATE,
RETURN.
CHECK FROM_CURR <> TO_CURRNCY.
CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
EXPORTING
RATE_TYPE = RATE_TYPE
FROM_CURR = FROM_CURR
TO_CURRNCY = TO_CURRNCY
DATE = DATE
IMPORTING
EXCH_RATE = EXCH_RATE
RETURN = RETURN.
IF RETURN IS NOT INITIAL.
CLEAR: EXCH_RATE,
RETURN.
CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
EXPORTING
RATE_TYPE = RATE_TYPE
FROM_CURR = TO_CURRNCY
TO_CURRNCY = FROM_CURR
DATE = DATE
IMPORTING
EXCH_RATE = EXCH_RATE
RETURN = RETURN.
IF RETURN IS NOT INITIAL.
** Error, don't get the exchange rate
** and error information had been saved into parameter RETURN
ELSE.
** success to get indirect exchange rate
IF EXCH_RATE-TO_FACTOR = 0.
EXCH_RATE-TO_FACTOR = 1.
ENDIF.
IF EXCH_RATE-EXCH_RATE = 0.
EXCH_RATE-EXCH_RATE = 1.
ENDIF.
AMOUNT = AMOUNT / EXCH_RATE-EXCH_RATE * EXCH_RATE-FROM_FACTOR
/ EXCH_RATE-TO_FACTOR.
ENDIF.
ELSE.
** success to get direct exchange rate
IF EXCH_RATE-FROM_FACTOR = 0.
EXCH_RATE-FROM_FACTOR = 1.
ENDIF.
AMOUNT = AMOUNT * EXCH_RATE-EXCH_RATE * EXCH_RATE-TO_FACTOR
/ EXCH_RATE-FROM_FACTOR.
ENDIF.
ENDFUNCTION.