数量金额转成 中文金额显示(代码,复制可用)

2021-12-02 08:53发布


          点击此处--->   EasySAP.com 群内免费提供SAP练习系统(在群公告中)

加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)

FORM tran_money_big USING   f_source  TYPE bbwert CHANGING VALUE(f_result)  .

*   DATA : brtwr1 TYPE  i ,  brtwr2  TYPE ekpo-brtwr , lbrtwr  TYPE i   .

*   brtwr2  =   p_sum_brtwr * 100 .

*   brtwr1  = trunc( brtwr2 )  .

*   lbrtwr =  trunc( p_sum_brtwr ) .

  DATA: scr(30) TYPE c, res(60) TYPE c,fen(2) TYPE c .

  DATA: len TYPE i, c1 TYPE i, c2 TYPE i, c3 TYPE i, c4 TYPE i.

  DATA: d1(1) TYPE c, d2(1) TYPE c, d3 TYPE i.

  DATA: digit(2)  TYPE c, weight(2) TYPE c.

  DATA: rule1(20) TYPE c VALUE '零壹贰叁肆伍陆柒捌玖'.

  DATA: rule2(30) TYPE c VALUE '分角元拾佰仟万拾佰仟亿拾佰仟万' .

  IF sy-langu = 'M'.

    rule2 = '分角元拾佰仟萬拾佰仟億拾佰仟萬' .

  ENDIF.

  scr = f_source * 100 .

  CONDENSE scr NO-GAPS.

  IF scr = '0'.

    res = '零'.

  ELSE.

    len = strlen( scr )."strlen计算构成该字符串的字符个数

    c1 = 0.

    d1 = '0'.

    CLEAR res.

    DO len TIMES .

      c1 = c1 + 1.

      c2 = len - c1 .

      d2 = scr+c2(1) ."从最后一个字符开始截取字符串

      IF d2 = '0' .

        d3 = 0.

      ELSE .

        d3 = d2 * 1 .

      ENDIF .

      digit = rule1+d3(1) .  "转换成大写

      c3 = ( c1 - 1 ) * 1 .

      weight = rule2+c3(1) .   "算权位

      IF d2 = '0' .

        IF c1 = 3 .

          digit = ''.

        ELSEIF c1 = 7 .

          digit = ''.

          IF len > 10 .

            c4 = len - 10.

            IF scr+c4(4) = '0000'.

              weight = '' .

            ENDIF.

          ENDIF .

        ELSEIF c1 = 11 .

          digit = ''.

        ELSEIF d1 = '0' .

          digit = ''.

          weight = ''.

        ELSE .

          weight = ''.

        ENDIF .

      ENDIF .

*      CONCATENATE digit weight res INTO res. "汉字间是否加进空格

*      CONCATENATE digit weight res INTO res SEPARATED BY space.

      CONCATENATE digit weight res INTO res  .

      d1 = d2.

    ENDDO .

  ENDIF.

  len = strlen( res ) - 1 .

  fen = res+len(2).

  IF fen <> '分' .

    CONCATENATE res '整' INTO f_result.

  ELSE.

    f_result = res.

  ENDIF.

  CONDENSE f_result .

ENDFORM.


赞赏支持