转自哪里忘记了,要是有幸被您看到,请指出,麻烦了 谢谢。
关于程序优化的问题
这个很重要
实例,如下图,有对比,有运行时间
里面可以自己写 进行对比
注意:
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 分析程序运行时间
结果例,如下: