zoukankan      html  css  js  c++  java
  • ABAP 程序优化总结

    1.最主要的是尽量减少I/O操作,然后是内存占用,再就是CPU的负载。CPU的负载可以通过优化程序来改善,在程序中尽量使用诸如SUM(SQL语句)或者COLLECT(ABAP语句)。
    
    2.尽可能多地使用表的索引作为Where分句的条件选项,尽可能让程序只读取一定范围内的记录(比如说,你只准备操作一个月之内的业务数据,那么对于这一个月的业务就应该有一定的范围取值,如1000~2000)。
    
    3.尽量使用Select A B C INTO TABLE ITAB这样的语句。这个操作会将所有符合条件的数据一次性地读进内表,这比在Select A B C INTO ITAB… ENDSELECT的循环中添加数据到内表要快。
    
    4.尽可能使用Select SINGLE语句。
    
    5.使用ABAP排序而不使用order by 。
    
    6.可以使用视图来代表基本表的查询。
    
    7.可以使用一些聚合函数、GROUP BY …HAVING,来进行计算和分组统计,也可以来改善查询的效率。
    
    例如:
    
    不推荐
    
    Maxnu = 0.
    
    Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
    
    Check zflight-fligh > maxnu.
    
    Maxnu = zflight-fligh.
    
    Endselect.
    
    推荐
    
    Select max( fligh ) from zflight into maxnu where airln = ‘LF’ and cntry = ‘IN’.
    
    8.使用where语句 
    
    不推荐
    
    Select * from zflight.
    
    Check : zflight-airln = ‘LF’ and zflight-fligh = ‘BW222’.
    
    Endselect.
    
    推荐
    
    Select * from zflight where airln = ‘LF’ and fligh = ‘222’.
    
    Endselect.
    
    9.使用批量修改内表代替逐行修改
    
    不推荐
    
    Loop at int_fligh.
    
    If int_fligh-flag is initial.
    
    Int_fligh-flag = ‘X’.
    
    Endif.
    
    Modify int_fligh.
    
    
    Endloop.
    
    推荐
    
    Int_fligh-flag = ‘X’.
    
    Modify int_fligh transporting flag where flag is initial..
    
    10.使用二分法查询,提高查询内表数据速度
    
    不推荐
    
    Read table int_fligh with key airln = ‘LF’.
    
    推荐
    
    Read table int_fligh with key airln = ‘LF’ binary search.
    
    11.两个内表添加使用批量增加代替逐行
    
    不推荐
    
    Loop at int_fligh1.
    
    Append int_fligh1 to int_fligh2.
    
    Endloop.
    
    推荐
    
    Append lines of int_fligh1 to int_fligh2.
    
    12.使用FOR ALL Entries
    
    不推荐
    
    Loop at int_cntry. 
    
    Select single * from zfligh into int_fligh where cntry = int_cntry-cntry. 
    
    Append int_fligh. 
    
    Endloop.
    
    推荐
    
    Select * from zfligh appending table int_fligh
    
    For all entries in int_cntry 
    
    Where cntry = int_cntry-cntry.
    
    1 数据——>工作区,工作区——>内表,
    
    2 数据——>内表 
    
    很明显少了一个过程 效率自然高了 如果数据量越大,效果是可想而知的
    
    13.避免使用SELECT DISTINCT语句
    
    使用的 ABAP SORT + DELETE ADJACENT DUPLICATES 代替.
    
    14.        更多地使用动态数据对象来访问内表。
    
    例:
    
     不推荐:
    
     LOOP AT itab.
    
                READ TABLE itab_jest
    
                   WITH KEY objnr = itab-objnr.
    
          ENDLOOP.
    
          推荐:
    
     
    
          FIELD-SYMBOLS:
    
               <ls_itab> TYPE typ_jhgb.
    
     LOOP AT itab ASSIGNING <ls-itab>.
    
                READ TABLE itab_jest
    
                   WITH KEY objnr = <ls-itab>-objnr.
    
          ENDLOOP.
  • 相关阅读:
    mybatis 调用mysql存储过程 带输出输入参数
    MyBatis 通过包含的jdbcType类型和java中对应的数据类型
    大型网站架构之分布式消息队列
    加密解密(2)*客户端,服务器,CA(Certificate Authority),公钥,私钥,证书,签名,验证
    AlertDialog与DialogFragment
    从日期对象中获取(年份、月份、日期、时间等数字)
    LayoutInflater的获取方式
    php——会话控制
    什么是虚假唤醒 spurious wakeup
    Linux互斥锁、条件变量和信号量
  • 原文地址:https://www.cnblogs.com/huangjianisgood/p/2725719.html
Copyright © 2011-2022 走看看