由于打印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.
  data: mod type i,integer1 type i,point_str(12) type 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(1) ne 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(15) type c,
        text1(10) type c,text2(8) type c,text3(14) type 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(7) type  c.

check p_point ne 0.
*  amount_str+0(p_leng2) = p_point.
  while p_point+counter(1) ne 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,我这段代码属于多余而已。

转载自:http://blog.csdn.net/paulun/article/details/3288678

lt;一 SAP ABAP 将数字转换成本地语言(中文、英文)大写相关推荐

  1. 如何将数字金额转成中文人民币大写

    直接给出代码,复制即用 public static String arabiaToChinese(String number){if(isBlank(number)){return "零&q ...

  2. sap abap好用的函数

    函数名 描述 SD_VBAP_READ_WITH_VBELN 根据销售订单读取表vbap中的信息 EDIT_LINES 把READ_TEXT返回的LINES中的行按照TDFORMAT="*& ...

  3. 2019.9.27,SAP成都研究院数字创新空间团队建设,射箭和游泳

    2019年9月27日,秋高气爽,SAP成都研究院数字创新团队全体成员又迎来了一次团队建设活动.这次的主题是:射箭. 在正式活动之前,大家先享用了一顿泰式海鲜火锅: 吃饱喝足之后,我们来到了名为&quo ...

  4. SAP ABAP BDC(批量数据通信)-018

    SAP ABAP BDC(批量数据通信)-018 批量输入简介 批处理输入通常用于将数据从非 R/3 系统传输到 R/3 系统或在 R/3 系统之间传输数据. 它是一种数据传输技术,允许您将数据集自动 ...

  5. SAP ABAP PA certification 培训笔记 part 4

    SAP ABAP PA certification 培训笔记 part 4 [@more@] 课前复习 Table key 由三部分构成 1. Components:组成key的字段 2. Seque ...

  6. SAP ABAP基础

    一.SAP ABAP简介: 典型SAP系统的3层客户端/服务器体系结构如下所示: 表示层包含可用于控制SAP系统的任何输入设备. 这可以是web浏览器,移动设备等. 所有中央处理都在应用程序服务器中进 ...

  7. SAP ABAP 基础语法随笔

    SAP ABAP 基础笔记随笔 基础 1.move-corresponding 2.IF终止循环 3.CONSTANTS 4.LOOP AT 5.CLEAR & REFRESH 6.获取sel ...

  8. SAP ABAP 报告编程-08

    SAP ABAP 报告编程-08 SAP-ABAP支持两种类型的程序 - 报告程序和对话程序.报表 程序在需要显示大量数据时使用 在本教程中,您将学习: 选择屏幕 ABAP 报告计划中的事件 设置报表 ...

  9. SAP abap内表分类与增删改查操作

    SAP abap内表分类与增删改查操作 1.内表的分类 1.1.标准表 (standard table ) 系统为该表每一行生成一个院级索引.填表是可以将数据附加在现有行之后,也可以插入到指定的位置, ...

最新文章

  1. div img span 垂直居中问题
  2. mysql高性能学习笔记03_MySQL高性能学习笔记
  3. 火出圈的1688,能扣响C2M的扳机吗?
  4. boost::hana::power用法的测试程序
  5. [网络安全自学篇] 二十六.Shodan搜索引擎详解及Python命令行调用
  6. RHEL6入门系列之三十,服务管理
  7. 在MonoTouch中正确而简单的使用 Sqlite 数据库
  8. Javascript对象探讨
  9. 044-PHP获得多个类对应的反射信息
  10. python图片分类毕业设计成果报告书_毕业设计成果报告书模板.doc
  11. 实践torch.fx第一篇——基于Pytorch的模型优化量化神器
  12. JavaBean递归拷贝工具类Dozer
  13. Redis 的过期策略
  14. [概率统计]商务与经济统计知识点总结 Part 2
  15. 软件需求,概要设计,详细设计(文档)怎么做,做什么?
  16. java 修改pdf文档的页面的大小
  17. SpringCloud微服务网关技术——Gateway网关的使用
  18. c语言中invert什么意思_C语言中init 是什么意思?
  19. 项目管理工具DHTMLX Gantt灯箱元素配置教程:配置灯箱元素
  20. linux服务器的Gzip文件压缩方法[转]

热门文章

  1. 转-iOS- GPUImage README.md
  2. openjdk Font实现斜体
  3. 【转】阿里巴巴社招内推
  4. 轻蜗牛直租平台-业务背景介绍
  5. wpf APlayer 播放
  6. R语言学习| 马氏距离mahanobis函数
  7. VR与360环物实现详细过程
  8. K8s系列之:DNS服务搭建指南
  9. 获取子进程终止状态:wait和waitpid
  10. 关于netty的IllegalReferenceCountException refCnt: 0, decrement: 1