1、影响程序性能的问题:ABAPTuning1.Loop嵌套Select查询(多条)类别Loop内的Select查询Loop外使用Select查询说明在Loop内使用select查询时,因为按成为loop对象的InternalTable的记录数运行select的原因,InternalTable的记录数越大,时间成几何数增加。右侧的代码在select中使用forallentriesin,内部loop中使用sortedtable,fieldsymbol可以缩短时间。代码DATA:gt_bkpf TYPE TABLE OF bkpf, gt_bseg TYPE TABL
2、E OF bseg.DATA:gs_bkpf LIKE LINE OF gt_bkpf, gs_bseg LIKE LINE OF gt_bseg.SELECT * FROM bkpf INTO CORRESPONDING FIELDS OF TABLE gt_bkpf UP TO 3000 ROWS.LOOP AT gt_bkpf INTO gs_bkpf. SELECT * FROM bseg INTO CORRESPONDING FIELDS OF TABLE gt_bsegWHERE bukrs = gs_bkpf-bukrs AND belnr
3、= gs_bkpf-belnr AND gjahr = gs_bkpf-gjahr.* .....ENDLOOP.DATA:gt_bkpf TYPE TABLE OF bkpf, gt_bkpf_tmp LIKE gt_bkpf, gt_bseg TYPE SORTED TABLE OF bseg WITH UNIQUE KEY bukrs belnr gjahr buzei, gt_bseg_tmp LIKE gt_bseg.DATA:gs_bkpf LIKE LINE OF gt_bkpf, gs_bseg LIKE LINE
4、OF gt_bseg.FIELD-SYMBOLS : LIKE gs_bkpf, LIKE gs_bseg.SELECT bukrs belnr gjahr INTO CORRESPONDING FIELDS OF TABLE gt_bkpf FROM bkpf UP TO 3000 ROWS.gt_bkpf_tmp = gt_bkpf.DELETE ADJACENT DUPLICATES FROM gt_bkpf_tmp COMPARING bukrs belnr gjahr.SELECT bukrs be
5、lnr gjahr buzei buzid INTO CORRESPONDING FIELDS OF TABLE gt_bseg FROM bseg FOR ALL ENTRIES IN gt_bkpf_tmp WHERE bukrs = gt_bkpf_tmp-bukrs AND belnr = gt_bkpf_tmp-belnr AND gjahr = gt_bkpf_tmp-gjahr.LOOP AT gt_bkpf ASSIGNING . CLEAR gt_bseg_tmp. LOOP AT gt_
6、bseg ASSIGNING WHERE bukrs = -bukrs AND belnr = -belnr AND gjahr = -gjahr. APPEND TO gt_bseg_tmp. ENDLOOP.* .....ENDLOOP.结果2,734,515microseconds1,068,422microseconds1.Loop嵌套Select查询(单条)类别Loop内的Select查询Loop外查询说明如
7、果从Loop内部带来的记录是一个一个的,使用readtable把对象InternalTable声明成hashedtable。代码DATA : gt_bseg TYPE TABLE OF bseg.DATA : gs_bkpf TYPE bkpf, gs_bseg LIKE LINE OF gt_bseg.SELECT * FROM bseg INTO CORRESPONDING FIELDS OF TABLE gt_bseg UP TO 3000 ROWS.LOOP AT gt_bseg INTO gs_bseg. SELECT SI