获取SAP汇率
OB08配置的汇率
CALL FUNCTION 'READ_EXCHANGE_RATE'
EXPORTING
client = sy-mandt
date = p_datuv "当前日期
foreign_currency = gw_output-konwa "外币
local_currency = 'CNY'
type_of_rate = 'M'
exact_date = ' '
IMPORTING
exchange_rate = lv_rate.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
外币显示 获取转换因子 如JPY 越南币
CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
EXPORTING
currency = gw_output-konwa
IMPORTING
factor = l_factor
EXCEPTIONS
too_many_decimals = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
gw_output-price = gw_output-price * l_factor.
外部金额转内部金额
IF gw_output-konwa <> 'CNY'.
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
date = p_datuv
foreign_amount = gw_output-price_js "外部金额 必须是两位小数
foreign_currency = gw_output-konwa "币种
local_currency = 'CNY'
* rate = gw_output-zhl
type_of_rate = 'M'
IMPORTING
local_amount = gw_output-kbetr
EXCEPTIONS
no_rate_found = 1
OTHERS = 2.
ELSE.
gw_output-kbetr = gw_output-price.
ENDIF.
该段代码主要展示了在SAP中如何通过CALLFUNCTION调用READ_EXCHANGE_RATE和CURRENCY_CONVERTING_FACTOR函数来获取汇率并进行货币转换。首先,它获取指定日期的外币对人民币的汇率,然后处理可能的错误。接着,计算外币到其他货币的转换因子。如果货币不是人民币,则将外部金额转换为本地货币(人民币)。
2424

被折叠的 条评论
为什么被折叠?



