SAP 越南小写金额转大写金额 amount in word

FUNCTION zfun_convert_money_vi.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_INPUT) TYPE  WERTV12
*"  EXPORTING
*"     VALUE(E_OUTPUT) TYPE  STRING
*"----------------------------------------------------------------------
  DATA: i_value   TYPE char100,        "入参
        e_value   TYPE char255,        "出参
        v_intege  TYPE c LENGTH 23,   "整数部分   最大23位
        v_decimal TYPE c LENGTH 2.    "小数部分   默认2位

  DATA: text_tab    TYPE TABLE OF char_4,
        wa_text_tab TYPE  char_4,
        length      TYPE i.

  DATA: v_lenth TYPE i,                           "整数部分长度
        v_cache TYPE c LENGTH 1.                  "缓存

  "输入
  i_value = i_input.

  SHIFT i_value LEFT DELETING LEADING '0'.          "删除前导0
  CONDENSE i_value NO-GAPS.                         "删除空格

  "拆分金额的整数小数
  SPLIT i_value AT '.' INTO v_intege v_decimal.

  PERFORM frm_string_reverse CHANGING v_intege.     "翻转intege sting

  CALL FUNCTION 'SCMS_STRING_TO_FTEXT'             "四个一拆分
    EXPORTING
      text      = |{ v_intege }|
    IMPORTING
      length    = length
    TABLES
      ftext_tab = text_tab.

  LOOP AT text_tab INTO wa_text_tab.
    CASE sy-tabix.
      WHEN 1.
        CONCATENATE e_value 'Đồng'  INTO e_value.
      WHEN 2.
        IF wa_text_tab <> '0000'.
          CONCATENATE 'Mười nghìn' e_value INTO e_value.
        ENDIF.
      WHEN 3.
        IF wa_text_tab <> '0000'.
          CONCATENATE 'Trăm triệu' e_value INTO e_value.
        ENDIF.
      WHEN 4.
        IF wa_text_tab <> '0000'.
          CONCATENATE 'Nghìn tỷ' e_value INTO e_value.
        ENDIF.
      WHEN 5.
        IF wa_text_tab <> '0000'.
*          CONCATENATE '亿亿' e_value INTO e_value.
        ENDIF.
      WHEN 6.
        IF wa_text_tab <> '0000'.
*          CONCATENATE '万亿亿' e_value INTO e_value.
        ENDIF.
    ENDCASE.

    CLEAR: v_lenth.
    DO strlen( wa_text_tab ) TIMES.
      v_cache = wa_text_tab+v_lenth(1).
      IF v_cache <> 0.
        CASE v_lenth.
          WHEN 0.
            CONCATENATE v_cache e_value INTO e_value.
          WHEN 1.
            CONCATENATE v_cache 'Mười' e_value INTO e_value.
          WHEN 2.
            CONCATENATE v_cache 'Trăm' e_value INTO e_value.
          WHEN 3.
            CONCATENATE v_cache 'Nghìn' e_value INTO e_value.
        ENDCASE.
      ELSE.
        CONCATENATE v_cache e_value INTO e_value.
      ENDIF.
      v_lenth = v_lenth + 1.
    ENDDO.
  ENDLOOP.

  IF e_value <> '0Đồng'.
*    REPLACE ALL OCCURRENCES OF REGEX '0+万亿亿' IN e_value WITH '万亿亿0'.
*    REPLACE ALL OCCURRENCES OF REGEX '0+亿亿' IN e_value WITH '亿亿0'.
    REPLACE ALL OCCURRENCES OF REGEX '0+Nghìn tỷ' IN e_value WITH 'Nghìn tỷ0'.
    REPLACE ALL OCCURRENCES OF REGEX '0+Trăm triệu' IN e_value WITH 'Trăm triệu0'.
    REPLACE ALL OCCURRENCES OF REGEX '0+Mười nghìn' IN e_value WITH 'Mười nghìn0'.
    REPLACE ALL OCCURRENCES OF REGEX '0+Đồng' IN e_value WITH 'Đồng'.               "排除掉  100000.01 显示 壹拾万零元零壹分 的情况
  ENDIF.

CONCATENATE e_value 'Chẵn' INTO e_value.                        "单独加 整 字

  "处理小数部分;越南语无小数部分处理
*  IF v_decimal = '00'.
*    CONCATENATE e_value '整' INTO e_value.
*  ELSE.
*    IF v_decimal+1(1) <> 0.
*      IF v_decimal+0(1) <> 0.
*        CONCATENATE e_value v_decimal+0(1)  '角' INTO e_value.
*      ELSE.
*        CONCATENATE e_value v_decimal+0(1) INTO e_value.
*      ENDIF.
*      CONCATENATE e_value v_decimal+1(1)  '分' INTO e_value.
*    ELSE.
*      CONCATENATE e_value v_decimal+0(1)  '角' INTO e_value.
*    ENDIF.
*
*  ENDIF.

  "  替换e_value中的数字  正则表达式
  REPLACE ALL OCCURRENCES OF REGEX '0+'   IN e_value WITH ''.        "多个零时,只输出一个零
  REPLACE ALL OCCURRENCES OF REGEX '1{1}' IN e_value WITH 'Một'.
  REPLACE ALL OCCURRENCES OF REGEX '2{1}' IN e_value WITH 'Hai'.
  REPLACE ALL OCCURRENCES OF REGEX '3{1}' IN e_value WITH 'Ba'.
  REPLACE ALL OCCURRENCES OF REGEX '4{1}' IN e_value WITH 'Bốn'.
  REPLACE ALL OCCURRENCES OF REGEX '5{1}' IN e_value WITH 'Năm'.
  REPLACE ALL OCCURRENCES OF REGEX '6{1}' IN e_value WITH 'Sáu'.
  REPLACE ALL OCCURRENCES OF REGEX '7{1}' IN e_value WITH 'Bảy'.
  REPLACE ALL OCCURRENCES OF REGEX '8{1}' IN e_value WITH 'Tám'.
  REPLACE ALL OCCURRENCES OF REGEX '9{1}' IN e_value WITH 'Chín'.

  "输出
  e_output = e_value.

ENDFUNCTION.
上一篇:数字按千分位分隔


下一篇:JavaScript正则表达式replace的一个坑