SAP将数字转换成英文大写

     由于打印invoice和packing list时需要将数量和金额转换成英文大写,所以写了段代码进行转换。

    利用此段代码可以将所有数字类型的值转换成英文大写。源代码如下:

 

if total_amount ne 0.
perform get_num_len using total_amount
      changing integer point leng1 leng2.
perform write_integer using integer leng1 changing amount_text.
perform write_point using point leng2 changing amount_text.

if amount_text ns 'HUNDRED' and amount_text ns 'THOUSAND'
  and amount_text ns 'MILLION' and amount_text ns 'BILLION'
  and amount_text cs 'AND'.
    replace 'AND' with space into amount_text..
endif.
concatenate amount_text 'ONLY' into amount_text separated by space.
elseif total_amount = 0.
  amount_text = 'ZERO'.
endif.
condense amount_text.

 

 

  form get_num_len using  value(p_total_amount)
                     changing p_integer p_point p_leng1 p_leng2.
  datamod type i,integer1 type i,point_str(12type c,
        counter type i value 0.
  p_integer = trunc( p_total_amount ).
  point_str = frac( p_total_amount ).
  integer1 = p_integer.
  if point_str cs '.'.
      p_leng2 = sy-fdpos + 1.
  endif.
  while integer1 ne 0.
    mod = integer1 mod 10.
    integer1 = integer1 - mod.
    integer1 = integer1 / 10.
    p_leng1 = p_leng1 + 1.
  endwhile.
  while point_str+p_leng2(1ne space.
    p_point+counter(1) = point_str+p_leng2(1).
    add 1 to p_leng2.
    add 1 to counter.
  endwhile.
  p_leng2 = counter + 1.

  endform"get_num_len

**********************************************************************
* FORM    :  write_integer
* Created :  21.08.2008 09:35:54
**********************************************************************
form write_integer using  value(p_integer) value(p_leng1)
                     changing p_amount_text.
  data: counter type i value 0,ind type i,
        num1 type i,num2 type i,num3 type i,
        amount_str(15type c,
        text1(10type c,text2(8type c,text3(14type c.
  if p_integer eq 0.
    p_amount_text = 'ZERO'.
  else.
    amount_str+0(p_leng1) = p_integer.
    while p_leng1 gt 0.
      counter = counter + 1.
      p_leng1 = p_leng1 - 2.
      if p_leng1 ge 0.
        num2 = amount_str+p_leng1(1).
        case num2.
          when 0.
            text2 = ' '.
          when 1.

              ind = 1.
            text2 = ' '.
          when 2.
            text2 = 'TWENTY'.
          when 3.
            text2 = 'THIRTY'.
          when 4.
            text2 = 'FORTY'.
          when 5.
            text2 = 'FIFTY'.
          when 6.
            text2 = 'SIXTY'.
          when 7.
            text2 = 'SEVENTY'.
          when 8.
            text2 = 'EIGHTY'.
          when 9.
            text2 = 'NINETY'.
        endcase.
      endif.

      p_leng1 = p_leng1 + 1.
      if p_leng1 ge 0.

          num1 = amount_str+p_leng1(1).
        case num1.
          when 0.
            if ind = 1.
              text1 = 'TEN'.
            else.
              text1 = ' '.
            endif.
          when 1.
            if ind = 1.
              text1 = 'ELEVEN'.
            else.
              text1 = 'ONE'.
            endif.
          when 2.
            if ind = 1.
              text1 = 'TWELVE'.
            else.
              text1 = 'TWO'.
            endif.
          when 3.
            if ind = 1.

                text1 = 'THIRTEEN'.
            else.
              text1 = 'THREE'.
            endif.
          when 4.
            if ind = 1.
              text1 = 'FOURTEEN'.
            else.
              text1 = 'FOUR'.
            endif.
          when 5.
            if ind = 1.
              text1 = 'FIFTEEN'.
            else.
              text1 = 'FIVE'.
            endif.
          when 6.
            if ind = 1.
              text1 = 'SIXTEEN'.
            else.
              text1 = 'SIX'.
            endif.
          when 7.
            if ind = 1.
              text1 = 'SEVENTEEN'.
            else.

                text1 = 'SEVEN'.
            endif.
          when 8.
            if ind = 1.
              text1 = 'EIGHTEEN'.
            else.
              text1 = 'EIGHT'.
            endif.
          when 9.
            if ind = 1.
              text1 = 'NINETEEN'.
            else.
              text1 = 'NINE'.
            endif.
        endcase.
      endif.

      p_leng1 = p_leng1 - 2.
      if p_leng1 ge 0.
        num3 = amount_str+p_leng1(1).
        case num3.
          when 0.
            text3 = ' '.
          when 1.
            text3 = 'ONE HUNDRED'.
          when 2.

              text3 = 'TWO HUNDRED'.
          when 3.
            text3 = 'THREE HUNDRED'.
          when 4.
            text3 = 'FOUR HUNDRED'.
          when 5.
            text3 = 'FIVE HUNDRED'.
          when 6.
            text3 = 'SIX HUNDRED'.
          when 7.
            text3 = 'SEVEN HUNDRED'.
          when 8.
            text3 = 'EIGHT HUNDRED'.
          when 9.
            text3 = 'NINE HUNDRED'.
        endcase.
      endif.
      case counter.
        when 1.
          if text1 ne space or text2 ne space.
            concatenate text3 'AND' text2 text1 into p_amount_text
            separated by space.
          else.
            concatenate text3 text2 text1 into p_amount_text
            separated by space.
          endif.
          clear text1.clear text2.clear text3.
        when 2.

            concatenate text3 text2 text1 'THOUSAND' p_amount_text into
    p_amount_text separated by space.
          clear text1.clear text2.clear text3.
        when 3.
          concatenate text3 text2 text1 'MILLION' p_amount_text into
    p_amount_text separated by space.
          clear text1.clear text2.clear text3.
        when 4.
          concatenate text3 text2 text1 'BILLION' p_amount_text into
    p_amount_text separated by space.
          clear text1.clear text2.clear text3.
      endcase.
    endwhile.
  endif.
  clear counter.clear ind.
endform"write_integer

**********************************************************************
* FORM    :  write_point
* Created :  21.08.2008 09:36:16
**********************************************************************
form write_point using  value(p_point) value(p_leng2)
                     changing p_amount_text.
  data"amount_str(5) type c,
        counter type i value 0,
        num type i,text(7type   c.

    check p_point ne 0.
*  amount_str+0(p_leng2) = p_point.
  while p_point+counter(1ne space.
    num = p_point+counter(1).
    case num.
      when 0.
        text = 'ZERO'.
      when 1.
        text = 'ONE'.
      when 2.
        text = 'TWO'.
      when 3.
        text = 'THREE'.
      when 4.
        text = 'FOUR'.
      when 5.
        text = 'FIVE'.
      when 6.
        text = 'SIX'.
      when 7.
        text = 'SEVEN'.
      when 8.
        text = 'EIGHT'.
      when 9.
        text = 'NINE'.
    endcase.

 
      if counter = 0.
        concatenate p_amount_text 'POINT' text into p_amount_text separated by space.
      else.
        concatenate p_amount_text text into p_amount_text separated by space.
      endif.

    add 1 to counter.
  endwhile.
endform"write_point

 

前段时间发现将数字转换为英文大写,SAP已提供相关函数执行这个功能,函数名称为:SPELL_AMOUNT,我这段代码属于多余而已。

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值