技术开发 频道

ABAP实例:将数字金额转换为人民币大写字符串

  2 Unicode Version

    FUNCTION zfuc_numeric_to_chinese.
    
*"----------------------------------------------------------------------
    *"*"Local Interface:
    
*"  IMPORTING
    *"     REFERENCE(IV_MONEY) TYPE  BF_DMBTR
    *"  EXPORTING
    *"     REFERENCE(EV_MONEY)
    *"  EXCEPTIONS
    *"      WRONG_MONEY
    *"----------------------------------------------------------------------
      IF iv_money = 0.
        ev_money
= ''.
        EXIT.
      ENDIF.
      DATA:money_str(
33).
      money_str
= iv_money.
       CONDENSE money_str NO
-GAPS.
      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:ev_money,units_off.
      lastd
= 0.
      curnt_off
= STRLEN( money_str ) - 1.
      WHILE curnt_off
>= 0.
        curntd
= money_str+curnt_off(1).
        i
= curntd.
        cword
= digts+i(1).

        weight
= units+units_off(1).

        i
= units_off / 1.
        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 ev_money INTO ev_money.
        lastd
= curntd.
        SUBTRACT
1 FROM curnt_off.
        ADD
1 TO units_off.
      ENDWHILE.
      IF ev_money NS
''.
        CONCATENATE ev_money
'' INTO ev_money.
      ELSE.
        cword
= ev_money.
        IF cword
= ''.
          SHIFT ev_money BY
1 PLACES.
        ENDIF.
      ENDIF.

    ENDFUNCTION.
0
相关文章