FUNCTION CONVERSION_EXIT_ZTHOU_OUTPUT. *"---------------------------------------------------------------------- *"*"區域介面: *" IMPORTING *" VALUE(INPUT) *" EXPORTING *" VALUE(OUTPUT) *"---------------------------------------------------------------------- DATA : ZCLEN TYPE I, N TYPE I, ZCSTR TYPE STRING, ZCSTR2 TYPE STRING, ZCTEMP(3) TYPE C, * ZFLAG(1) TYPE C VALUE '.', ZFLAG2 TYPE C, ZCDEC TYPE STRING, "记录小数部分. ZNUM(30), ZNUM_H(30), ZTOTAL(30), ZTOTAL_H(30). CONDENSE: INPUT. IF '-' CA INPUT. ZFLAG2 = 'X'. INPUT = ABS( INPUT ). ENDIF. *---------------------------------------------------------------------------------------------*1 IF INPUT IS NOT INITIAL. * 分离整数与小数,好单独处理整数。 * 压缩字符串,去除前面的空格。 SPLIT INPUT AT '.' INTO ZCSTR ZCDEC. CONDENSE: 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. ELSE. ZCSTR2 = ZCTEMP. ENDIF. ZCLEN = ZCLEN - 3. ENDWHILE. * 将不剩下的不足三位数加到前面 IF ZCLEN > 0. IF ZCSTR2 IS NOT INITIAL. CONCATENATE ZCSTR+0(ZCLEN) ',' ZCSTR2 INTO ZCSTR2. ELSE. CONCATENATE ZCSTR+0(ZCLEN) '' INTO ZCSTR2. ENDIF. ENDIF. IF ZFLAG2 = 'X'. CONCATENATE '-' ZCSTR2 INTO ZCSTR2. ENDIF. CLEAR ZCSTR. * 将处理过的整数与小数连接起来。 IF ZCDEC IS NOT INITIAL. CONCATENATE ZCSTR2 '.' ZCDEC INTO OUTPUT. ELSE. OUTPUT = ZCSTR2. * CONCATENATE ZCDEC '00' INTO ZCDEC. * CONCATENATE ZCSTR2 ZCDEC INTO ZCSTR SEPARATED BY ZFLAG. ENDIF. * 将值返回 * IS_RESULT-AMOUNT = ZCSTR. ELSE. * IS_RESULT-AMOUNT = ZNUM. OUTPUT = INPUT. ENDIF. ENDFUNCTION.View Code
标签:ZCDEC,ZCLEN,ZCSTR2,千分,ZCSTR,ABAP,分隔符,INPUT,INTO From: https://www.cnblogs.com/chaguoguo/p/17664055.html