function z_convert_numeric_to_chinese.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(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.
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.
endfunction.
FUNCTION Z_DIGITAL_LOWER_TO_UPPER.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(DIGITALIN) TYPE C
*" EXPORTING
*" REFERENCE(DIGITALOUT) TYPE C
*"----------------------------------------------------------------------
CASE digitalin.
WHEN '0'.
digitalout = '零'.
WHEN '1'.
digitalout = '壹'.
WHEN '2'.
digitalout = '贰'.
WHEN '3'.
digitalout = '叁'.
WHEN '4'.
digitalout = '肆'.
WHEN '5'.
digitalout = '伍'.
WHEN '6'.
digitalout = '陆'.
WHEN '7'.
digitalout = '柒'.
WHEN '8'.
digitalout = '捌'.
WHEN '9'.
digitalout = '玖'.
WHEN OTHERS.
digitalout = 'E'.
ENDCASE.
ENDFUNCTION.
*---------------------------------------------------------------
* CREATE BY:
* CREATE DATE:
* MODIFY BY:
* MODIFY DATE:
*
* 函数功能:完成金额从小写向中文大写的转换。
*
* 其他说明:效率不高,有改进空间。
*---------------------------------------------------------------
FUNCTION z_money_lower_to_upper.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(MONEYIN) TYPE SALK3 DEFAULT 1
*" EXPORTING
*" REFERENCE(MONEYOUT) TYPE C
*"----------------------------------------------------------------------
DATA: ipos TYPE i,
iwan TYPE i,
imod TYPE i,
pin TYPE p DECIMALS 2,
strint TYPE c LENGTH 10,
strdec TYPE c LENGTH 3,
strintt TYPE c,
strintd TYPE c,
strintu TYPE c LENGTH 40,
strdect TYPE c,
strdecd TYPE c,
strdecu TYPE c LENGTH 4.
pin = moneyin.
IF pin EQ 0.
ipos = 0.
ELSE.
ipos = FLOOR( LOG10( pin ) ) + 1. "计算数值pin的整数位数。
ENDIF.
*write / ipos.
*计算小数部分
pin = pin * 100. "将数值的百分位变为个位,便于处理。
strdect = pin - pin DIV 10 * 10. "获取数值的百分位,也就是分。
IF strdect NE '0'. "如果值为0,则不显示该值,直接跳过。
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER' "调用数值小写转大写的函数,获得大写的数字。
EXPORTING
digitalin = strdect
IMPORTING
digitalout = strdecd.
CONCATENATE strdecd '分' INTO strdecu. "生成金额的“分”。
ENDIF.
pin = pin DIV 10. "将十分位变为个位。
strdect = pin - pin DIV 10 * 10. "获取数值的十分位,也就是角。
IF strdect EQ '0' AND strdecu EQ ''. "如果角为0,分也为0,则金额的小数部分就没有。
strdecu = ''.
ELSEIF strdect EQ '0' AND strdecu NE ''. "如果角为0,分不为0,则角位只写“零”不写“角”。
CONCATENATE '零' strdecu INTO strdecu.
ELSE. "如果角不为0,则直接与前面生成的分进行拼接。
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER' "调用数值小写转大写的函数。
EXPORTING
digitalin = strdect
IMPORTING
digitalout = strdecd.
CONCATENATE strdecd '角' strdecu INTO strdecu. "生成金额的“角”和“分”
ENDIF.
pin = pin DIV 10. "恢复原来的整数位。
iwan = 0. "万位标记,四个数值位为一“万”,从个位开始,所以iwan的初值为0。
*计算整数部分
DO ipos TIMES.
strintt = pin - pin DIV 10 * 10.
imod = iwan MOD 4.
IF imod EQ 0.
IF iwan = 0.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
strintu = strintd.
ENDIF.
ELSEIF iwan = 4.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
ELSE.
strintd = ''.
ENDIF.
CONCATENATE strintd '万' strintu INTO strintu.
ELSEIF iwan = 8.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
ELSE.
strintd = ''.
ENDIF.
CONCATENATE strintd '亿' strintu INTO strintu.
ENDIF.
ENDIF.
IF imod EQ 1.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
CONCATENATE strintd '拾' strintu INTO strintu.
ELSEIF strintd NE '零'.
CONCATENATE '零' strintu INTO strintu.
ENDIF.
ENDIF.
IF imod EQ 2.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
CONCATENATE strintd '佰' strintu INTO strintu.
ELSEIF strintd NE '零'.
CONCATENATE '零' strintu INTO strintu.
ENDIF.
ENDIF.
IF imod EQ 3.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
CONCATENATE strintd '仟' strintu INTO strintu.
ELSEIF strintd NE '零'.
CONCATENATE '零' strintu INTO strintu.
ENDIF.
ENDIF.
pin = pin DIV 10.
iwan = iwan + 1.
* write: / iwan, strintt, strintu, imod.
ENDDO.
*连接整数位和小数位。
CONCATENATE strintu '元' strdecu INTO moneyout.
*把“零亿”、“零万”、“零元”都替换掉。
REPLACE '零零' WITH '零' INTO moneyout.
REPLACE '零亿' WITH '亿' INTO moneyout.
REPLACE '零万' WITH '万' INTO moneyout.
REPLACE '零元' WITH '元' INTO moneyout.
IF ipos EQ 0.
moneyout = '零元'.
ENDIF.
ENDFUNCTION.