【IT168 技术文章】
FUNCTION zfi_convert_to_capitalization.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(P_AMOUNT) TYPE WERTV8
*" EXPORTING
*" REFERENCE(P_CAPITALIZATION) TYPE STRING
*"----------------------------------------------------------------------
DATA:
v_s00(2) VALUE '零',
v_s01(2) VALUE '壹',
v_s02(2) VALUE '贰',
v_s03(2) VALUE '叁',
v_s04(2) VALUE '肆',
v_s05(2) VALUE '伍',
v_s06(2) VALUE '陆',
v_s07(2) VALUE '柒',
v_s08(2) VALUE '捌',
v_s09(2) VALUE '玖',
v_w00(2) VALUE '',
v_w01(2) VALUE '拾',
v_w02(2) VALUE '佰',
v_w03(2) VALUE '仟',
v_w04(2) VALUE '万',
v_w05(4) VALUE '拾万',
v_w06(4) VALUE '佰万',
v_w07(4) VALUE '仟万',
v_w08(2) VALUE '亿',
v_w09(4) VALUE '拾亿',
v_w10(4) VALUE '佰亿',
v_w11(4) VALUE '仟亿',
v_w12(4) VALUE '万亿',
v_sy(2) VALUE '元',
v_sj(2) VALUE '角',
v_sf(2) VALUE '分',
v_amount(16),"将金额转换成字符型
v_len TYPE i,"v_amount或p_capitalization的长度
v_var(5),"v_s0,v_s1,...,v_w0,v_w1,...
v_num(2) TYPE n,"每一位的数值
v_s_num(2),"v_s0,v_s1,...中的值
v_weight(2) TYPE n,"权数
v_w_num(4),"v_w0,v_w1,...中的值
v_flag0 TYPE i VALUE 1,"是否输出'零',0不输出,1输出
v_n TYPE i VALUE 0.
v_amount = p_amount.
SHIFT v_amount LEFT DELETING LEADING space.
SHIFT v_amount LEFT DELETING LEADING '0'.
*-计算分-----------------------------------------
v_len = strlen( v_amount ).
v_len = v_len - 1.
v_num = v_amount+v_len(1).
IF v_num <> '0'.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE v_s_num v_sf p_capitalization INTO p_capitalization.
ENDIF.
*-计算角-----------------------------------------
v_len = strlen( v_amount ).
v_len = v_len - 2.
v_num = v_amount+v_len(1).
IF v_num <> '0'.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE v_s_num v_sj p_capitalization INTO p_capitalization.
ENDIF.
*-输出‘整’字-------------------------------------
IF p_capitalization = ' '.
CONCATENATE '整' p_capitalization INTO p_capitalization.
ENDIF.
*-计算整数---------------------------------------
v_len = strlen( v_amount ).
v_len = v_len - 3.
if v_len = 0.
exit.
endif.
v_amount = v_amount(v_len)." 整数部分
*-输出‘元’字-------------------------------------
CONCATENATE v_sy p_capitalization INTO p_capitalization.
v_n = v_len - 1.
v_weight = 0.
DO v_len TIMES.
* 从个位开始
v_num = v_amount+v_n(1).
IF v_num <> '0'.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE 'v_w' v_weight INTO v_var.
WRITE (v_var) TO v_w_num.
CONCATENATE v_s_num v_w_num p_capitalization INTO p_capitalization.
v_flag0 = 1.
ELSE.
IF v_flag0 = 1.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE v_s_num p_capitalization INTO p_capitalization.
v_flag0 = 0.
ENDIF.
ENDIF.
v_weight = v_weight + 1.
v_n = v_n - 1.
ENDDO.
*-删除个位可能出现'零'的情况-----------------
SEARCH p_capitalization FOR '元'.
IF sy-subrc = 0.
v_n = sy-fdpos - 2.
IF p_capitalization+v_n(2) = v_s00.
v_len = strlen( p_capitalization ).
CONCATENATE p_capitalization(v_n) p_capitalization+sy-fdpos INTO p_capitalization.
ENDIF.
ENDIF.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(P_AMOUNT) TYPE WERTV8
*" EXPORTING
*" REFERENCE(P_CAPITALIZATION) TYPE STRING
*"----------------------------------------------------------------------
DATA:
v_s00(2) VALUE '零',
v_s01(2) VALUE '壹',
v_s02(2) VALUE '贰',
v_s03(2) VALUE '叁',
v_s04(2) VALUE '肆',
v_s05(2) VALUE '伍',
v_s06(2) VALUE '陆',
v_s07(2) VALUE '柒',
v_s08(2) VALUE '捌',
v_s09(2) VALUE '玖',
v_w00(2) VALUE '',
v_w01(2) VALUE '拾',
v_w02(2) VALUE '佰',
v_w03(2) VALUE '仟',
v_w04(2) VALUE '万',
v_w05(4) VALUE '拾万',
v_w06(4) VALUE '佰万',
v_w07(4) VALUE '仟万',
v_w08(2) VALUE '亿',
v_w09(4) VALUE '拾亿',
v_w10(4) VALUE '佰亿',
v_w11(4) VALUE '仟亿',
v_w12(4) VALUE '万亿',
v_sy(2) VALUE '元',
v_sj(2) VALUE '角',
v_sf(2) VALUE '分',
v_amount(16),"将金额转换成字符型
v_len TYPE i,"v_amount或p_capitalization的长度
v_var(5),"v_s0,v_s1,...,v_w0,v_w1,...
v_num(2) TYPE n,"每一位的数值
v_s_num(2),"v_s0,v_s1,...中的值
v_weight(2) TYPE n,"权数
v_w_num(4),"v_w0,v_w1,...中的值
v_flag0 TYPE i VALUE 1,"是否输出'零',0不输出,1输出
v_n TYPE i VALUE 0.
v_amount = p_amount.
SHIFT v_amount LEFT DELETING LEADING space.
SHIFT v_amount LEFT DELETING LEADING '0'.
*-计算分-----------------------------------------
v_len = strlen( v_amount ).
v_len = v_len - 1.
v_num = v_amount+v_len(1).
IF v_num <> '0'.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE v_s_num v_sf p_capitalization INTO p_capitalization.
ENDIF.
*-计算角-----------------------------------------
v_len = strlen( v_amount ).
v_len = v_len - 2.
v_num = v_amount+v_len(1).
IF v_num <> '0'.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE v_s_num v_sj p_capitalization INTO p_capitalization.
ENDIF.
*-输出‘整’字-------------------------------------
IF p_capitalization = ' '.
CONCATENATE '整' p_capitalization INTO p_capitalization.
ENDIF.
*-计算整数---------------------------------------
v_len = strlen( v_amount ).
v_len = v_len - 3.
if v_len = 0.
exit.
endif.
v_amount = v_amount(v_len)." 整数部分
*-输出‘元’字-------------------------------------
CONCATENATE v_sy p_capitalization INTO p_capitalization.
v_n = v_len - 1.
v_weight = 0.
DO v_len TIMES.
* 从个位开始
v_num = v_amount+v_n(1).
IF v_num <> '0'.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE 'v_w' v_weight INTO v_var.
WRITE (v_var) TO v_w_num.
CONCATENATE v_s_num v_w_num p_capitalization INTO p_capitalization.
v_flag0 = 1.
ELSE.
IF v_flag0 = 1.
CONCATENATE 'v_s' v_num INTO v_var.
WRITE (v_var) TO v_s_num.
CONCATENATE v_s_num p_capitalization INTO p_capitalization.
v_flag0 = 0.
ENDIF.
ENDIF.
v_weight = v_weight + 1.
v_n = v_n - 1.
ENDDO.
*-删除个位可能出现'零'的情况-----------------
SEARCH p_capitalization FOR '元'.
IF sy-subrc = 0.
v_n = sy-fdpos - 2.
IF p_capitalization+v_n(2) = v_s00.
v_len = strlen( p_capitalization ).
CONCATENATE p_capitalization(v_n) p_capitalization+sy-fdpos INTO p_capitalization.
ENDIF.
ENDIF.
ENDFUNCTION.