先来看一下SAP系统中的3种数字格式:
SAP中的数字格式.png这里分3种情况:
1.用户设置成'空'格式,转换成其他两种格式: 第一种情况.png
2.用户设置成'X'格式,转换成其他两种格式: 第2种情况.png
3.用户设置成'Y'格式,转换成其他两种格式,这时转换就有点麻烦了,这里写成一个FORM,直接调用即可:
IF lv_dcpfm = 'Y'."用户默认格式
PERFORM conversion_num USING lv_strtmp p_dn lv_strtmp.
ENDIF.
FORM conversion_num USING input TYPE any
o_format TYPE xudcpfm
output.
STATICS ss_usr01 TYPE usr01.
DATA lv_data TYPE REF TO data.
DATA: l_thousands_i TYPE c LENGTH 1,
l_decimal_i TYPE c LENGTH 1,
l_mark TYPE c LENGTH 2.
DATA: l_thousands_o TYPE c LENGTH 1,
l_decimal_o TYPE c LENGTH 1,
l_decimal_o2 TYPE c LENGTH 1.
DATA: i_format TYPE xudcpfm.
FIELD-SYMBOLS: <l_input> TYPE ANY.
CREATE DATA lv_data LIKE input.
ASSIGN lv_data->* TO <l_input>.
IF i_format IS INITIAL.
SELECT SINGLE * FROM usr01 INTO ss_usr01 WHERE bname EQ sy-uname.
i_format = ss_usr01-dcpfm.
ENDIF.
IF i_format EQ o_format.
output = input.
RETURN.
ENDIF.
<l_input> = input.
CASE i_format.
WHEN space. " 1.234.567,89
l_thousands_i = '.'.
l_decimal_i = ','.
WHEN 'X'. " 1,234,567.89
l_thousands_i = ','.
l_decimal_i = '.'.
WHEN 'Y'. " 1 234 567,89
l_thousands_i = space.
l_decimal_i = ','.
ENDCASE.
CASE o_format.
WHEN space. " 1.234.567,89
l_thousands_o = '.'.
l_decimal_o = 'X'.
l_decimal_o2 = ','.
WHEN 'X'. " 1,234,567.89
l_thousands_o = ','.
l_decimal_o = 'X'.
l_decimal_o2 = '.'.
WHEN 'Y'. " 1 234 567,89
l_thousands_o = space.
l_decimal_o = 'X'.
l_decimal_o2 = ','.
ENDCASE.
REPLACE ALL OCCURRENCES OF l_decimal_i IN <l_input> WITH l_decimal_o.
IF l_thousands_o NE space.
IF l_thousands_i NE space.
REPLACE ALL OCCURRENCES OF l_thousands_i IN <l_input> WITH l_thousands_o.
ELSE.
CLEAR: l_mark.
CONCATENATE l_thousands_i 'Y' INTO l_mark SEPARATED BY space.
TRANSLATE <l_input> USING l_mark.
REPLACE ALL OCCURRENCES OF 'Y' IN <l_input> WITH l_thousands_o.
ENDIF.
ELSE.
CLEAR: l_mark.
CONCATENATE l_thousands_i space INTO l_mark.
TRANSLATE <l_input> USING l_mark.
ENDIF.
REPLACE ALL OCCURRENCES OF l_decimal_o IN <l_input> WITH l_decimal_o2.
output = <l_input>.
ENDFORM. " CONVERSION_NUM
网友评论