FUNCTION zf_cn_num.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IV_MONEY) TYPE BSEG-DMBTR
*" EXPORTING
*" REFERENCE(EV_MONEY) TYPE CHAR100
*"----------------------------------------------------------------------
IF iv_money = 0.
ev_money = '零'.
EXIT.
ENDIF.
DATA:money_str(33).
money_str = iv_money.
CONDENSE money_str NO-GAPS.
IF money_str CN '0123456789. '.
RAISE wrong_money.
ENDIF.
DATA:i TYPE i.
IF money_str CS '.'.
i = sy-fdpos + 1.
money_str+sy-fdpos = money_str+i.
ENDIF.
CONDENSE money_str NO-GAPS.
DATA:units_off TYPE i,
curnt_off TYPE i.
DATA:lastd TYPE n,curntd TYPE n.
DATA:cword(2),weight(2).
DATA:units(30) VALUE '分角元拾佰仟万拾佰仟亿拾佰仟万',
digts(20) VALUE '零壹贰叁肆伍陆柒捌玖'.
* clear:ev_money,units_off.
lastd = 0.
curnt_off = strlen( money_str ) - 1.
WHILE curnt_off >= 0.
curntd = money_str+curnt_off(1).
i = curntd.
cword = digts+i(1).
weight = units+units_off(1).
i = units_off / 1.
IF curntd = 0. "Current digit is 0
IF i = 2 OR i = 6 OR i = 10.
CLEAR:cword.
IF curnt_off = 0.
CLEAR:weight.
ENDIF.
ELSEIF lastd = 0.
CLEAR:cword,weight.
ELSE.
CLEAR:weight.
ENDIF.
ENDIF.
CONCATENATE cword weight ev_money INTO ev_money.
lastd = curntd.
SUBTRACT 1 FROM curnt_off.
ADD 1 TO units_off.
ENDWHILE.
IF ev_money NS '分'.
CONCATENATE ev_money '整' INTO ev_money.
ELSE.
cword = ev_money.
IF cword = '零'.
SHIFT ev_money BY 1 PLACES.
ENDIF.
ENDIF.
ENDFUNCTION.
网友评论