`
Jack Wu
  • 浏览: 887246 次
  • 来自: ...
社区版块
存档分类
最新评论

abap--一个改变程序性能的样例,给初学者一个编程的思路,请大家指点

阅读更多

Suppose you have the following program. What can you do to improve performance changing the fewest lines of code?

tables: cooi,                          " Purchase Order Open Items
        ekbe.                          " PO History (paid invoices)

data: begin of po_tab occurs 10,
        refbn        like ekko-ebeln,
        mitacct(5)   type c,           " classic account
        openamt      like ppvar-wcost,
        paidamt      like ppvar-wcost,
        mitdesc(50).
data: end of po_tab.

  select * from cooi where wrttp = '22' "get po commitments
                     order by refbn.

    if w_purcord is initial.
      move cooi-refbn to w_purcord.
    endif.
    if cooi-refbn ne w_purcord.
      move cooi-refbn to w_purcord.
      perform extract_po.
    endif.
   
    move: cooi-whgbtr       to po_tab-openamt.
    if cooi-beknz = 'H'.
      po_tab-openamt = po_tab-openamt * -1.
    endif.
    collect po_tab.

    ...lots of detail processing against all po line items...

    select * from ekbe where ebeln = cooi-refbn
                         and ebelp = cooi-rfpos
                         and zekkn = cooi-rfknt+3(2)
                         and vgabe = '2'.

    ...more processing...

      move: ekbe-dmbtr         to po_tab-paidamt.
      if ekbe-shkzg = 'H'.
        po_tab-paidamt = po_tab-paidamt * -1.
      endif.
      collect po_tab.

    endselect.
  endselect.

  perform extract_po.

form extract_po.
  loop at po_tab.
    check po_tab-openamt > 0.
    ...more processing...
  endloop.
endform.
Both selects can be converted to go directly into internal tables. The following changes can cut run time down by 1/2 with very few lines of code needing to be changed.

data: t_cooi like cooi occurs 0. "add internal table like transparent one

data: begin of t_ekbe occurs 0, "add internal table w/fields of interest
        dmbtr like ekbe-dmbtr,         " amount
        shkzg like ekbe-shkzg,         " debit/credit indicator
      end of t_ekbe.

  select * from cooi into table t_cooi where wrttp = '22'.
  sort t_cooi by refbn.

  loop at t_cooi into cooi.       "places each row into table work area

    "none of the code referencing cooi needs to be changed
    "since data from the internal table is being placed into cooi

    "internal table below saves the most time because the select is
    "issued repeated times for each item within cooi (cooi holds all the
    "account assignments for all the line items for all the POs)

    select dmbtr shkzg from ekbe into table t_ekbe
                       where ebeln = cooi-refbn
                         and ebelp = cooi-rfpos
                         and zekkn = cooi-rfknt+3(2)
                         and vgabe = '2'.

    if sy-subrc <> 0.
      continue.                      "get next PO
    endif.

    loop at t_ekbe.
      move: t_ekbe-dmbtr         to po_tab-paidamt.
      if t_ekbe-shkzg = 'H'.
        po_tab-paidamt = po_tab-paidamt * -1.
      endif.
      collect po_tab.
    endloop.              "loop through po history for paid amt

  endloop.                 "loop through line items for all POs
In order to take the job from a 6 hour job to a 1 hour job, a better understanding of the underlying data was necessary. The following change was added to the above changes to complete the performance enhancement:

data: begin of t_open occurs 0, "add internal table for open docs only
        refbt like cooi-refbt,         " ref doc category (POs, reqs)
        refbn like cooi-refbn,         " ref doc number
      end of t_open.

  "only a small percentage of POs have open amounts!

  select distinct refbt refbn from cooi into table t_open
         where wrttp = '22' and
         whgbtr > 0.     "get only document numbers with open amts

  sort t_open by refbn.                "sort by document number

  loop at t_open.
  
    "process all the line items for any open PO

    select * from cooi into table t_cooi
          where refbt = t_open-refbt and  " ref doc category PO
                refbn = t_open-refbn.     "assoc w/POs w/open balances
    sort t_cooi by rfpos.

    loop at t_cooi into cooi.       

      select dmbtr shkzg from ekbe into table t_ekbe
                         where ebeln = cooi-refbn
                           and ebelp = cooi-rfpos
                           and zekkn = cooi-rfknt+3(2)
                           and vgabe = '2'.

      if sy-subrc <> 0.
        continue.                      "get next PO
      endif.

      ...lots of detail processing against OPEN po line items...

      loop at t_ekbe.
        move: t_ekbe-dmbtr         to po_tab-paidamt.
        if t_ekbe-shkzg = 'H'.
          po_tab-paidamt = po_tab-paidamt * -1.
        endif.
        collect po_tab.
      endloop.              "loop through po history for paid amt

    endloop.                "loop though all line items for each open PO

  endloop.                  "loop through open POs

  perform extract_po.

form extract_po.
  loop at po_tab.
    check po_tab-openamt > 0.   "no longer necessary because
    ...more processing...       "POs with no open amount not being
  endloop.                      "processedendform.

 

分享到:
评论

相关推荐

    ABAP751 ABAP - Keyword Documentation

    ABAP - Keyword Documentation This documentation describes the syntax and meaning of the keywords of the ABAP language and its object-oriented part ABAP Objects. Alongside this, language frameworks ...

    SAP中文教材全系列之ABAP-BC400_ZH

    本文档是《SAP中文教材全系列之ABAP-BC400_ZH》,为SAP ABAP编程语言的学习提供参考。文档包含了详细的ABAP课程内容,旨在帮助学员理解并掌握ABAP编程的基础知识和高级技能。以下将详细阐释文档所涵盖的知识点。 ...

    CD260-ABAP-in-Eclipse-开发-CN

    CD260-ABAP-in-Eclipse-开发-CN CD260-ABAP-in-Eclipse-开发-CNCD260-ABAP-in-Eclipse-开发-CNCD260-ABAP-in-Eclipse-开发-CN

    eclipse-abap-keywordcolors-master.rar

    eclipse-abap-keywordcolors eclipse-abap-关键字颜色

    ABAP-培训教材目录

    ABAP-培训教材附录 ABAP-培训教材ABAP-培训教材ABAP-培训教材ABAP-培训教材

    ABAP-4目前最完美学习手册

    以上概述了《ABAP-4目前最完美学习手册》中提到的关键知识点,旨在帮助初学者快速掌握ABAP/4编程的基础与进阶技巧。通过这些内容的学习,开发者能够更好地理解和运用ABAP/4语言来开发高质量的SAP应用程序。

    ABAP-EXCEL编程

    "ABAP-EXCEL编程"的主题旨在教授如何使用ABAP与Microsoft Excel进行交互。 在ABAP中操作Excel文件,主要涉及到以下知识点: 1. **RFC函数调用**:SAP与外部系统交互,包括Excel,常常通过Remote Function Call ...

    实战SAP程序开发——从实例学SAP ABAP编程.rar

    对于想要深入理解SAP编程的初学者,实战SAP程序开发——从实例学SAP ABAP编程这个资源提供了宝贵的实践机会。 SAP ABAP是一种结构化编程语言,主要用于创建用户界面、业务逻辑和报表。以下是一些核心的SAP ABAP知识...

    ABAP-OLE开发[汇编].pdf

    ABAP-OLE开发是SAP系统中的一种技术,它允许ABAP编程语言与外部对象链接和嵌入(OLE)应用程序进行交互。OLE自动化是Windows环境中的一种技术,它使得不同的应用程序可以共享数据和服务,通常用于控制一个应用程序...

    ABAP-ALV进阶

    "ABAP-ALV进阶知识点详解" ABAP-ALV进阶是指在SAP系统中使用ABAP语言开发的高级列表查看器(ALV)。ALV是SAP系统中心的列表标准,可以在ABAP程序中进行报表输出。下面是ABAP-ALV进阶的知识点详解: 一、ALV概要 ...

    ABAP-学习笔记-通用

    ABAP-学习笔记-通用

    SAP ABAP程序性能调优介绍.pptx

    程序跟踪是 SAP 系统性能调优的另一个重要工具,包括 ABAP Trace、SAT 和 SQL Trace。这些工具可以帮助管理员跟踪程序的执行过程,identify 性能瓶颈并进行优化。 程序调优是 SAP 系统性能调优的核心部分,包括内表...

    三月精通ABAP--快速入门

    《三月精通ABAP——快速入门》是一本旨在帮助初学者快速掌握ABAP编程语言的教程。ABAP,全称Advanced Business Application Programming,是SAP系统中的主要编程语言,用于开发企业级应用,特别是在供应链管理(SCM...

    ABAP-子程序宏函数学习笔记.py

    ABAP-子程序宏函数学习笔记.py

    ABAP--ALV

    这可以通过在程序中定义多个内部表并将它们合并到一个统一的视图中来实现。 #### 六、ALV中的交互报表程序 (Interactive Reporting in ALV) 交互报表允许用户在运行报表的过程中与报表进行互动,例如实时排序、...

    abap-ALV.rar_ABAP系统ALV_abap_abap开发alv

    REUSE_ALV_GRID_DISPLAY_LVC函数是ABAP ALV编程中常用的一个函数模块,它负责初始化并显示ALV网格。这个函数的主要步骤包括: 1. 初始化ALV:调用FUNCTION模块`REUSE_ALV_GRID_DISPLAY`,并传递必要的参数,如选择的...

    ABAP-EXCEL 编程的统一接口的 使用方法

    在本文中,我们将探讨如何使用ABAP-Excel编程的统一接口来满足三种常见的Excel输出需求:在特定位置输出单字段、在指定行下方插入多行以及删除原有模板的某些行。 首先,我们需要理解基本概念。在ABAP中,要操作...

Global site tag (gtag.js) - Google Analytics