转:关于程序优化的问题 [根据某文件 自己总结下]

本文提供了一系列程序优化的方法,包括避免在循环中更新数据库、使用二分查找法、减少SELECT语句的使用、合理利用索引等。同时介绍了如何通过缓存表、避免DISTINCT语句等方式提升程序效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转自哪里忘记了,要是有幸被您看到,请指出,麻烦了 谢谢。

 

关于程序优化的问题

 

这个很重要

 

实例,如下图,有对比,有运行时间

 

 

里面可以自己写 进行对比

 

 

注意:

1:for all entries in itab  . itab[]一定要确定不是空值

 

2:insert sbook from table itab. 尽量不要在loop 内更新数据库表,其他操作同理

 

3:使用二分查找法

      先排序sort itab by [field]

      read table itab with key field = 'XX' binary search.

 

4: 避免使用

    select ...

       select ...

       endselect.

    endselect.

 

5: select ... where 条件尽量加主键

 

6:select * from db into wa where (connid = '0300' or connid = '0302') and carrid <> 'LH'.

     应:select * from db into wa where connid in ('0300' , '0302') and carrid in ('AA', 'QM').

 

7:select 语句尽量避免 order by

     可:select into table itab.

           sort itab by field1 field2.

 

8: 嵌套表的处理

    loop at itab1 assiging <fs_1>.

       loop at wa_1-itab_2 assiging <fs_2>.

          <fs_2>-f1 = <v1>.

       endloop.

    endloop.

 

9: 使用Index 索引

    index = 1.

    loop at sort_vbak assiging <fs_vbak>.

       loop at sort_vabp assiging <fs_vbap> from index.

        if <fs_vbap>-vbeln <> <fs_vbak>-vbeln.

           index = sy-tabix.  EXIT.

        endif.

       endloop.

    endloop.

 

10: 建议使用move 取代move-corresponidng 语句

 

11:推荐使用缓存表因为它可以显著提高程序速度    

      (1)Select distinct      

      (2)Select … for update

      (3)Order by, group by, having字段

      (4)Joins

      (5)select 命令后面使用 bypass buffer 附加语句可以明确跳过缓存表。

 

12: 避免使用distinct 语句, 可采用数据到内部后,用delete adjacent duplicates语句来消除重复行。

 

13: 循环内表,在loop内添加到新内表。

        append lines of itab1 to itab2.

 

14: 只拷贝部分需要的数据

      read table itab1 into wa_1 transporting field1 field2 with key mandt = '' and ... .

 

15: read table ... index <n>.  standard/sorted table

      read table ... from <wa>.  sorted/hashed table

      read table ... with key <f1> = '' ...  正常sorted table  read table with key .. binary search . standard table

      read table with table key ... . key must be fully specified . hashed table / 正常 sorted table

     

16:在loop 里删数据,可:

      delete table itab where ... . where 条件尽量是按照索引。 modify 同delete

 

TCODE: SCI/ST05/ST30/ST03N/SE30

 

 

T-CODE:SE30  分析程序运行时间

结果例,如下:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值