转自:http://www.dasunny.com/wordpress/sapnotes/2015113091.html
SAP标准的数值转换函数 SPELL_AMOUNT,
仅对整数部分进行了处理,小数部分未处理。
FUNCTION Z_RMBDX.
DATA: BEGIN OF RMB,
BY TYPE C,
SY TYPE C,
Y TYPE C,
QW TYPE C,
BW TYPE C,
SW TYPE C,
W TYPE C,
Q TYPE C,
B TYPE C,
S TYPE C,
G TYPE C,
D TYPE C,
J TYPE C,
F TYPE C,
N TYPE C,
END OF RMB.
DATA: BEGIN OF RMBDX,
BY(2) TYPE C,
BY1(4) TYPE C,
SY(2) TYPE C,
SY1(4) TYPE C,
Y(2) TYPE C,
Y1(2) TYPE C,
QW(2) TYPE C,
QW1(4) TYPE C,
BW(2) TYPE C,
BW1(4) TYPE C,
SW(2) TYPE C,
SW1(4) TYPE C,
W(2) TYPE C,
W1(4) TYPE C,
Q(2) TYPE C,
Q1(4) TYPE C,
B(2) TYPE C,
B1(4) TYPE C,
S(2) TYPE C,
S1(4) TYPE C,
G(2) TYPE C,
D(2) TYPE C,
J(2) TYPE C,
J1(2) TYPE C,
F(2) TYPE C,
F1(2) TYPE C,
Z(2) TYPE C,
END OF RMBDX.
DATA: Y(1) TYPE C.
RMB = RMBXX.
IF NOT ( RMB-BY IS INITIAL ) AND RMB-BY NE '0'.
PERFORM DX USING RMB-BY CHANGING RMBDX-BY.
Y = 'X'.
IF RMB-BY NE '0'.
IF RMB-SY EQ '0' AND RMB-Y EQ '0'.
RMBDX-BY1 = '佰亿'.
ELSE.
RMBDX-BY1 = '佰'.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-SY IS INITIAL ).
IF RMB-SY NE '0' OR RMB-Y NE '0'.
PERFORM DX USING RMB-SY CHANGING RMBDX-SY.
Y = 'X'.
IF RMB-SY NE '0'.
IF RMB-Y EQ '0'.
RMBDX-SY1 = '拾亿'.
ELSE.
RMBDX-SY1 = '拾'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-Y IS INITIAL ).
IF RMB-Y NE '0' OR RMB-QW NE '0'.
PERFORM DX USING RMB-Y CHANGING RMBDX-Y.
Y = 'X'.
IF RMB-Y NE '0'.
RMBDX-Y1 = '亿'.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-QW IS INITIAL ).
IF RMB-QW NE '0' OR RMB-BW NE '0'.
PERFORM DX USING RMB-QW CHANGING RMBDX-QW.
Y = 'X'.
IF RMB-QW NE '0'.
IF RMB-BW EQ '0' AND RMB-SW EQ '0' AND RMB-W EQ '0'.
RMBDX-QW1 = '仟万'.
ELSE.
RMBDX-QW1 = '仟'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-BW IS INITIAL ).
IF RMB-BW NE '0' OR RMB-SW NE '0'.
PERFORM DX USING RMB-BW CHANGING RMBDX-BW.
Y = 'X'.
IF RMB-BW NE '0'.
IF RMB-SW EQ '0' AND RMB-W EQ '0'.
RMBDX-BW1 = '佰万'.
ELSE.
RMBDX-BW1 = '佰'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-SW IS INITIAL ).
IF RMB-SW NE'0' OR RMB-W NE '0'.
PERFORM DX USING RMB-SW CHANGING RMBDX-SW.
Y = 'X'.
IF RMB-SW NE '0'.
IF RMB-W EQ '0'.
RMBDX-SW1 = '拾万'.
ELSE.
RMBDX-SW1 = '拾'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-W IS INITIAL ).
IF RMB-W NE '0' OR RMB-Q NE '0'.
PERFORM DX USING RMB-W CHANGING RMBDX-W.
Y = 'X'.
IF RMB-W NE '0'.
RMBDX-W1 = '万'.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-Q IS INITIAL ).
IF RMB-Q NE '0' OR RMB-B NE '0'.
PERFORM DX USING RMB-Q CHANGING RMBDX-Q.
Y = 'X'.
IF RMB-Q NE '0'.
RMBDX-Q1 = '仟'.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-B IS INITIAL ).
IF RMB-B NE '0' OR RMB-S NE '0'.
PERFORM DX USING RMB-B CHANGING RMBDX-B.
Y = 'X'.
IF RMB-B NE '0'.
RMBDX-B1 = '佰'.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-S IS INITIAL ).
IF RMB-S NE'0' OR RMB-G NE '0'.
PERFORM DX USING RMB-S CHANGING RMBDX-S.
Y = 'X'.
IF RMB-S NE '0'.
RMBDX-S1 = '拾'.
ENDIF.
ENDIF.
ENDIF.
IF NOT ( RMB-G IS INITIAL ) AND RMB-G NE '0'.
PERFORM DX USING RMB-G CHANGING RMBDX-G.
Y = 'X'.
ENDIF.
IF Y EQ 'X'.
RMBDX-D = '圆'.
ENDIF.
IF NOT ( RMB-J IS INITIAL ) AND RMB-J NE '0'.
PERFORM DX USING RMB-J CHANGING RMBDX-J.
RMBDX-J1 = '角'.
ENDIF.
IF NOT ( RMB-F IS INITIAL ) AND RMB-F NE '0'.
PERFORM DX USING RMB-F CHANGING RMBDX-F.
RMBDX-F1 = '分'.
ELSE.
RMBDX-Z = '整'.
ENDIF.
CONDENSE RMBDX NO-GAPS.
IF RMBXX = 0.
CLEAR RMBDX.
ENDIF.
RMBDX1 = RMBDX.
CLEAR Y.
ENDFUNCTION.
FORM DX USING VALUE(X) CHANGING DXX.
CASE X.
WHEN '0'.
DXX = '零'.
WHEN '1'.
DXX = '壹'.
WHEN '2'.
DXX = '贰'.
WHEN '3'.
DXX = '叁'.
WHEN '4'.
DXX = '肆'.
WHEN '5'.
DXX = '伍'.
WHEN '6'.
DXX = '陆'.
WHEN '7'.
DXX = '柒'.
WHEN '8'.
DXX = '捌'.
WHEN '9'.
DXX = '玖'.
ENDCASE.
ENDFORM.