SAP ABAP – Transfer number to chinese character function module
Only Chinese Project will use this funtion module.Usually in account document print.
To english character,we can use spell_amout.
FUNCTION z_convert_numeric_to_chinese. *";---------------------------------------------------------------------- *";*";Local interface: *"; IMPORTING *"; REFERENCE(PI_MONEY) LIKE BSEG-DMBTR *"; EXPORTING *"; REFERENCE(PO_CHINESE) *"; EXCEPTIONS *"; WRONG_MONEY *";---------------------------------------------------------------------- IF pi_money = 0. po_chinese = '零'. EXIT. ENDIF. DATA:money_str(13). money_str = pi_money. 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:po_chinese,units_off. lastd = 0. units_off = 0. curnt_off = STRLEN( money_str ) - 1. WHILE curnt_off >;= 0. curntd = money_str+curnt_off(1). i = curntd * 2. cword = digts+i(2). weight = units+units_off(2). i = units_off / 2. 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 po_chinese INTO po_chinese. lastd = curntd. SUBTRACT 1 FROM curnt_off. ADD 2 TO units_off. ENDWHILE. IF po_chinese NS '分'. CONCATENATE po_chinese '整' INTO po_chinese. ELSE. cword = po_chinese. IF cword = '零'. SHIFT po_chinese BY 2 PLACES. ENDIF. ENDIF. *-----------------BEGIN---------------------------- *&; 当数值为100,000,000.01 时,调用该函数 *&; ,显示出来为壹亿万元零壹分,加上该段 *&; ,则读为壹亿元零壹分。 SEARCH po_chinese FOR '亿 万'. IF sy-subrc = 0. REPLACE '亿 万' WITH '亿' INTO po_chinese. ENDIF. *-----------------END------------------------------ CONDENSE po_chinese NO-GAPS. ENDFUNCTION.