FUNCTION zfc048_010.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(I_DATA) TYPE CHAR20
*" EXPORTING
*" REFERENCE(O_DATA) TYPE CHAR20
*"----------------------------------------------------------------------
DATA : zclen TYPE i,
n TYPE i,
zcstr(30) TYPE c,
zcstr2(30) TYPE c,
zctemp(3) TYPE c,
zflag(1) TYPE c VALUE '.',
zflag2 TYPE i VALUE 0,
zcdec(30) TYPE c, "记录小数部分.
znum(30),
znum_h(30),
ztotal(30),
ztotal_h(30),
l_tmp(1).
"zstr = ''.
znum = i_data.
CONDENSE znum NO-GAPS.
* znum_h = is_result-amount_h.
* ztotal = is_result-total.
* ztotal_h = is_result-total_h.
* CLEAR: is_result-amount,is_result-amount_h,is_result-total,is_result-total_h.
*---------------------------------------------------------------------------------------------*1
IF znum <> 0.
IF znum <= -1000.
zflag2 = 1.
znum = znum * ( -1 ).
ENDIF.
IF znum >= 1000.
zcstr = znum.
* 压缩字符串,去除前面的空格。
CONDENSE zcstr NO-GAPS.
* 分离整数与小数,好单独处理整数。
SPLIT zcstr AT zflag INTO zcstr zcdec.
zclen = strlen( zcstr ).
* 在循环中从右面在每三位的前面加上一个逗号。
WHILE zclen > 3.
n = zclen - 3.
zctemp = zcstr+n(3).
IF NOT zcstr2 IS INITIAL.
CONCATENATE zctemp zcstr2 INTO zcstr2 SEPARATED BY ','.
ELSE.
zcstr2 = zctemp.
ENDIF.
zclen = zclen - 3.
ENDWHILE.
* 将不剩下的不足三位数加到前面
CONCATENATE zcstr+0(zclen) zcstr2 INTO zcstr2 SEPARATED BY ','.
IF zflag2 = 1.
CONCATENATE '-' zcstr2 INTO zcstr2.
ENDIF.
CLEAR zcstr.
* 将处理过的整数与小数连接起来。
IF strlen( zcdec ) > 1.
CONCATENATE zcstr2 zcdec INTO zcstr SEPARATED BY zflag.
ELSE.
CONCATENATE zcdec '0' INTO zcdec.
CONCATENATE zcstr2 zcdec INTO zcstr SEPARATED BY zflag.
ENDIF.
* 将值返回
o_data = zcstr.
ELSE.
zclen = strlen( znum ).
SEARCH znum FOR '-' STARTING AT zclen.
IF sy-subrc = 0.
SPLIT znum AT '-' INTO znum l_tmp.
SHIFT znum LEFT DELETING LEADING space.
CONCATENATE '-' znum INTO znum.
SHIFT znum RIGHT DELETING TRAILING space.
CONDENSE znum NO-GAPS.
ENDIF.
o_data = znum.
ENDIF.
ENDIF.
CLEAR: zflag2,zcstr,zcdec,zclen,zctemp,zcstr2,n.
ENDFUNCTION.