<一> SAP ABAP 将数字转换成本地语言(中文、英文)大写

由于打印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

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ABAP幫助文檔,中文版 第一部份,ABAP/4基础 ABAP/4用户指南的第一部分描述了ABAP/4编程语言的基本组件。它们允许用户编写并运行包括所有主要操作的ABAP/4 程序。用户可以使用这些知识编写应用程序。 在第一部分的下列章节中,您将学习: 一、 ABAP/4程序结构: (一)、创建简单的ABAP/4程序 (二)、ABAP/4程序语法和格式 二、 数据处理: (一)、声明数据 (二)、将数据输出到屏幕 (三)、处理文本摘要 (四)、处理数据 三、 流控制:控制ABAP/4程序流 四、 特殊编程技术: (一)、创建和处理内表 (二)、模块化ABAP/4程序 (三)、使用字段符号 五、 存储数据: (一)、读取并处理数据库表 (二)、以簇方式存储数据对象 (三)、使用文件 一、ABAP/4程序结构 (一)、创建简单的APAP/4程序 本节描述如何创建简单的ABAP/4程序。了解如何创建ABAP/4程序将有助于了解本指南中的其它主题。 创建简单的ABAP/4程序涉及下列基本步骤: 命名程序=>指定程序属性=>编写程序代码=>测试程序 另外,本节也描述如何显示或更改现有程序以及如何从编辑器中启动程序。 此处描述的创建新ABAP/4程序的过程适用于报表和短培训程序。在开始编写报表程序之前,用户也许想先创建报表和短培训程序以熟悉ABAP/4语法。要为新事务创建模块存储,可以采用不同于报表程序的方式进行。关于如何为事务创建模块存储的详细信息,参见《ABAP/4模块池》。 关于ABAP/4编辑器和调试过程的详细信息,参见文档ABAP/4工作台工具。 本节讲述下列主题: 1) 命名程序 2) 指定程序属性 3) 编写程序 4) 测试程序 5) 显示或更改程序 6) 将事务代码分配给程序 1)、命名程序 要创建ABAP/4程序,步骤如下:  在“SAP R/3”初始屏幕上选择“工具->ABAP/4工作台”。出现“ABAP/4开发工作台”屏幕  选择“ABAP/4编辑器”,“ABAP/4编辑器初始屏幕”如下所示:  为在“程序”字段中创建的程序输入名称(关于创建程序名称的详细信息,参见《命名程序规则》)。  选择“创建”。 不论在“对象组件”下选择什么,都出现“ABAP/4:程序属性”屏幕。当命名并创建程序后,可以定义其属性(关于定义程序属性的详细信息,参见《指定程序属性》)。 创建ABAP/4程序还有其它过程。例如,可以:  选择“ABAP/4开发工作台”屏幕上的“对象浏览”。  选择“对象列表”下的“程序”。  选择“单一对象”下的“程序对象”。  输入程序名并单击“显示”。如果程序不存在,则询问是否要创建它。关于对象浏览器及创建程序其它过程的详细信息,参见文档《ABAP/4工作台工具》。 命名程序规则:当创建程序名称时请遵循如下规则:  使用至少1个但不超过8个字符。  不要使用下列字符: 句点(.);逗号(,);空格( );括号'('')';单引号(');双引号("); 等号(=);星号(*);元音变音( , , , , , )和' ';百分号(%)和下划线(_): 因为这些符号是SQL语句的通配符,所以也会导致问题(参见《在程序中为行选择指定条件》)。 SAP建议在程序名称中不要使用它们。 创建程序名称时请遵守这些命名约定:  报表程序(以列表格式输出数据分析):Yaxxxxxx或Zaxxxxxx。用应用程序区的分类字母替换a。任何有效字符替换x。注意SAP报表程序遵守相似的命名约定:Raxxxxxx。  任何其它ABAP/4程序(培训程序或事务程序):SAPMYxxx或SAPMZxxx。用有效字符替换x。注意标准SAPABAP/4程序遵守相似的命名约定:SAPMaxxx,其中a代表某应用程序区。 2)、指定程序属性 程序属性决定程序属于哪种应用程序以及程序所链接的逻辑数据库。必须谨慎输入属性以便系统能正确处理程序(有关程序属性的详细信息,参见《重要的程序属性》)。 已经将名称分配给程序并选择“ABAP/4编辑器初始屏幕”上的“创建”时,出现“ABAP/4:程序属性”屏幕,要输入程序属性,请进行如下操作:  在字段“标题”中输入程序标题。选择描述程序功能的标题。系统自动将标题与文本摘要合并。如果以后要更改标题,请按如下操作进行:  选择“ABAP/4编辑器初始屏幕”上的“文本摘要”或“属性”。  选择“更改”。  完成两个强制字段:  如果创建报表程序,则在“类型”字段中输入1,如果创建模块存储,则在“类型”字段中输入M。关于可能类型的列表,请单击可能条目箭头。  在“应用程序”字段中为应用程序输入分类字母,如财务会计输入F。  如果创建报表(类型

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值