如何提高ABAP程序性能_第1頁
如何提高ABAP程序性能_第2頁
如何提高ABAP程序性能_第3頁
如何提高ABAP程序性能_第4頁
如何提高ABAP程序性能_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、影響程序性能的問題:abap tuning1. loop嵌套select查詢(多條)類別loop內(nèi)的select查詢loopbffi用select 查詢說明在loop內(nèi)使用select查詢時(shí),因?yàn)榘闯蔀閘oop對象的internal table的記錄數(shù)運(yùn)行sclec t的原因,internal table的記錄數(shù)越大,時(shí)間成幾何數(shù)增加。右側(cè)的代碼在select中使 用for al 1 entries in,內(nèi)部 loop 中使用 sorted table, field symbol 可以縮短時(shí)間。代碼data:gt_bkpf type table 0 f bkpfzgt_bseg type t

2、able 0f bseg.data:gs_bkpf like line of g t_bkpf,gs_bseg like line of gt _bseg select * from bkpf into corresponding fields of tab legt_bkpf up to 3000 rowsloop at gt_bkpf into gs_bkp fselect * from bseg intocorresponding fields of tab legt_bseg wherebukrs = gs_bkpf-bukrs andbelnr = gs_bkpf-belnr and

3、gjahr = gs_bkpf-gjahr.*endloop data:gt_bkpf type table of bkpf, gt_bkpf_tmp like gt_bkpf, gt_bseg type sorted table 0 f bsegwith unique key bukrs belnr gj ahr buzei,gt_bseg_tmp like gt_bseg data:gs_bkpf like line of gt_bkpfz gs_bseg like line of gt_bse g-field-symbols :<fs_gs_bkpf> like gs_bkp

4、f,<fs_gs_bseg> like gs_bsegselect bukrs belnr gjahr into corresponding fields of table gt_ b kpffrom bkpf up to 3000 rows gt_bkpf_tmp = gt_bkpf.delete adjacent duplicates from gt _bkpf_tmpcomparing bukrs belnr gjahr select bukrs belnr gjahr buzei buz idinto corresponding fields of tabl e gt_bs

5、egfrom bsegfor all entries in gt_bkpf_tmp where bukrs = gt_bkpf_tmp-bukr s andbelnr = gt_bkpf_tmp-belnr andgjahr = gt_bkpf_tmp-gjahr.loop at gt_bkpf assigning <fs_gs_b kpf > clear gt_bseg_tmp>loop at gt_bseg assigning <fs_gs _bseg>where bukrs = <fs_gs_bkpf>-bukrs a ndbelnr = <

6、;fs_gs_bkpf>-be1nr andgjahr = <fs_gs_bkpf>-gjahr append <fs_gs_bseg> to gt_bseg _tmp.endloop.*endloop結(jié)果2,734,515 microseconds1,068,422 microseconds2. loop嵌套select查詢(單條)類別loop內(nèi)的select查詢?nèi)绻麖膌oop內(nèi)部帶來的記錄是一個(gè)一個(gè)的,使用read table把對象internaltable聲明成h說明ashed table。data : gt_bseg type table of bsdat

7、a : gt_bseg type table of bseg.eg.data : gs_bkpf type bkpf.gt_bseg_tmp like gt_bsegs_bseg like line of gt_g.bseg gt_bkpf type hashed table ofselect * from bsegbkpf with unique key bukinto corresponding fields ofrstable gt_bseg up to 3000 rob ews.lnr代碼loop at gt_bseg into gs_bseg.g jselect single * f

8、rom bkpfahr into corresponding fields of gfield-symeols :s_bkpf<fs_gs_bseg> like line of gt_bwhere bukrs = gs_bseg-bukrseg,s and<fs_gs_bkpf> like line of gt_belnr = gs_bseg-belnbkpf.r andgjahr = gs_bseg-gjahselect bukrs belnr gjahr from br segendloopinto corresponding fields 0ftable gt_b

9、seg up to 3000 rowsgt_bseg_tmp = gt_bseg.select bukrs belnr gjahrinto corresponding fields oftable gt_bkpffrom bkpffor all entries in gt_bseg_tm pwhere bukrs = gt_bseg_tmp-bukrs andbelnr = gt_bseg_tmp-belnr andgjahr = gt_bseg_tmp-gjahr loop at gt_bseg_tmpassigning <fs_gs_bseg>.read table gt_bk

10、pf with table keybukrs = <f s_gs_bseg>-bukrsbelnr = <fs_gs_bseg>-belnrgjahr = <fs_gs_bseg>-g jahrassigning <fs_gs_bkpf>.*endloop結(jié)果1,627,939 microseconds310,731 microseconds3.在程序中使用binary search效果好(前提是被用來檢索的內(nèi)表必須是sorted table)類別線二諭疇內(nèi)表說明internal table的數(shù)據(jù)如果是20個(gè)以上,使用1 inear search

11、時(shí)會耗用很多時(shí)間。這時(shí)tabl e排列后,可使用binary search和用sorted table來做兩種方法。檢索算法中,binary se arch和1 inear search的search次數(shù)最差的情況下是分別為(long2(n)和()(n) 代碼* entries: 1000f line width: 100 entries: 1000f line width: 100 key width:20* the read ends with sy-subrc=4read table itab into wawith key k = x key width :20 the read en

12、ds with sy-subrc=4read table itab into wawith key k = 'x*binary search.結(jié)果78 microseconds1 microseconds4.在loop中使用where條件類別key access with l(x)p/checkkey access with loop . whereloop/check的情況下,確認(rèn)interna 1 table所有entry的同時(shí)運(yùn)行check,但是loop/where說明的情況下,只check滿足wh已re條件句的entry更有效率。這里可能的話where條件句中加上from il

13、 and/or to i2會出現(xiàn)更高的性能。 entries: 1000, line width: 50* entries: 1000, line width: 5000key width:2*key width:200 5 entries of which match the* 5 entries of which match the代碼key conditionkey conditionloop at itab into waloop at itab into wa where k = 'x'.check wa-k = 'x'if ff endloop en

14、dloop結(jié)杲38 microseconds22 microseconds5.順序檢索使用sorted table比hash table效率高類別fwuhdrdtabletable說明左側(cè)代碼,hashed table中使用loop來ful 1 table scan,效率不高。這時(shí)(使用loop)使用sorted table較好。 entries: 10000, entries: 10000fline width: 100line width: 100 key width: 60f key width: 60,subkey width: 20subkey width: 20 htab i s

15、a hashed tablef 2 00* stab is a sorted tablef0 entries are read2000 entries are read代碼 key fields: kf data key fields: k, dataloop at htab into wa whereloop at stab into wa wherek = subkeyrrk = subkey endloop endloop.結(jié)果2,297 microseconds685 microseconds6.刪除內(nèi)表中的重復(fù)數(shù)據(jù)類別比較字段然后刪除說明使用delete adjacent dupli

16、cates可刪除重復(fù)的數(shù)據(jù)。但是,如果通過db access補(bǔ)internal table時(shí),select時(shí)delete adjacent duplicates比較有效。* entries: 1000f line width: 10 entries : 1000f line width : 1 000* 500 pairs of duplicates 500 pairs of duplicatesdelete adjacent duplicates from代碼read table itab index 1itab comparing kinto prev_lineloop at itab f

17、rom 2 into waif wa = prev_line.delete itab.else prev_line = waend it endloop結(jié)果246 microseconds62 microseconds7. nested loop 的情況類別straightforward nested loopmore sojiiisticated loop: parallel cursors如果itabl有 n 1, itab2有 n2 個(gè)數(shù)據(jù),nested loop 時(shí)運(yùn)行 nl*n2 次loop。nl和 n2 分別是1000和100,足有100,000次反復(fù)運(yùn)行。但是,paral lei

18、 cursor approach 時(shí)是 nl+n2說明次,即只有1100次的loop運(yùn)行,效率很高??墒侵荒苁窃趇tab2的數(shù)據(jù)是itab1數(shù)據(jù)的一 部分時(shí)才可以。如果這個(gè)假設(shè)不成立,和nested loop沒什么差別。* entries: 100 (itabl)f* entries: 100 (itabl)f1000 (itab2)1000 (itab2)* line width: 100 line width: 100* both tables sorted by key k both tables sorted by key kloop at itabl into waii = 1loo

19、p at itab2 into wa2loop at itabl into wai代碼where k = wa1-kloop at itab2 into wa2 from i.ff if wa2-k <> wa1-k.endloop i = sy-tabixendloop exit endif99 endloopendloop結(jié)果21,060 microseconds453 microseconds8. case比if效率高類別ifcase說明case文比if文更清楚,性能更快。data c type cdata c type cifc =* a'.write'1c

20、ase cwhen 'a1write1 1 '.elseifc =®write* 2when 'b1write*2 '.when c write*3'.elseifc =write'3when 'd* write*4 '.when *ef write*5* .elseifc =dwrite* 4when 'f1write1 6'.when g.write代碼elseifc =write'5when 'h*.write*8'.!endcaseelseifc =匸write* 6els

21、eif!c =gwrite* 7elseif!c =write'8endif.結(jié)果1 microseconds0 microsecondssql tuning:i .使用where比case效率高類別select+check statementselect with where condition說明為核對data,比起使用check語句,指定where condition更好。如使用where語句,db system 使用i ndex (可能的情況下),network的負(fù)荷顯著減小。代碼select * from sbookinto sbook_wa.check: sbook_wa-

22、carrid = *lh1and sbook_wa-connid =select * from sbookinto sbook_wawhere carrid = 1lh1 andconnid = 1 0400 * .0400 endselect.endselect結(jié)果1,101,669 microseconds43,132 microseconds類別select *select with select list2 判斷表中是否有數(shù)據(jù)的高效方法類別select and exitselect up to 1 rows說明為確認(rèn)table中是否有data, select中給出了up to 1 ro

23、ws的option,不會帶給network不必要的負(fù)荷。select * from sbook into sboselect * from sbook into sbook_waok_wa代碼where carrid = *lh* up to 1 rowsexit where carrid = 'lh1endselect.endselect.結(jié)果2,104 microseconds142 microseconds3. max, min, sum, avg count select時(shí)可以一次進(jìn)行類別select where + checkselect using an aggregate function說叨單純地求最大值,最小值,合計(jì),平均,個(gè)數(shù)等的時(shí)候,利用sql文的函數(shù)可以很大程度上 減小ne twork的負(fù)荷。data: max_msgnr type tloo-msgndata: max_msgnr type tloo-msgnr r max_msgnr = 1 0001 .select max( msgnr ) from t100select * from t100 into t100_wainto max_msgnr代碼wher

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論