RFC接口金额分隔符乱码处理
程序员文章站
2022-03-11 18:06:29
...
SAP与OA的RFC接口中的金额字段有时会出现分隔符乱码问题,导致SAP更新表数据的时候DOWN掉,现在需要将金额中的乱码删除,只保留小数点和纯数字。
示例代码:
START-OF-SELECTION.
PERFORM program_main.
FORM program_main.
DATA: lv_dmbtr1 TYPE char30,
lv_dmbtr2 TYPE dmbtr.
lv_dmbtr1 = '64<177<507.90'.
PERFORM deal_dmbtr_sign USING lv_dmbtr1 lv_dmbtr2.
WRITE: lv_dmbtr2.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form deal_dmbtr_sign
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->pv_dmbtr text
* -->cv_dmbtr text
*----------------------------------------------------------------------*
FORM deal_dmbtr_sign USING pv_dmbtr TYPE char30
CHANGING cv_dmbtr TYPE dmbtr.
DATA: lo_matcher TYPE REF TO cl_abap_matcher.
DATA: ls_result TYPE match_result.
DATA: lt_result TYPE match_result_tab.
DATA: lv_text TYPE char30,
lv_dmbtr_c TYPE char30,
lv_str TYPE char1.
CHECK pv_dmbtr IS NOT INITIAL.
CLEAR cv_dmbtr.
lv_text = pv_dmbtr.
CONDENSE lv_text NO-GAPS.
lo_matcher = cl_abap_matcher=>create( pattern = '[0123456789.]' text = lv_text ).
lt_result = lo_matcher->find_all( ).
LOOP AT lt_result INTO ls_result.
CLEAR lv_str.
lv_str = lo_matcher->text+ls_result-offset(ls_result-length).
CONCATENATE lv_dmbtr_c lv_str INTO lv_dmbtr_c.
ENDLOOP.
CONDENSE lv_dmbtr_c NO-GAPS.
cv_dmbtr = lv_dmbtr_c.
ENDFORM.
注:如有疏漏之处,还请不吝赐教!
推荐阅读