關於在SAP中SQL語句的效能

qiujun發表於2007-02-12
DATA: BEGIN OF it_mara OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
END OF it_mara.
第一種寫法:
Select matnr
INTO it_mara
FROM mara.
APPEND it_mara.
ENDSelect.
第二種寫法(high performace):
Select matnr
INTO TABLE it_mara
FROM mara.
==========================================
DATA: BEGIN OF it_mara OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
END OF it_mara.
DATA: BEGIN OF it_makt OCCURS 0,
matnr LIKE mara-matnr,
maktx LIKE makt-maktx,
END OF it_makt.
第一種寫法:
LOOP AT it_mara.
Select SINGLE maktx
INTO it_mara-maktx
FROM makt
Where matnr = it_mara-matnr AND
spras = sy-langu.
MODIFY it_mara TRANSPORTING maktx.
ENDLOOP.
第二種寫法(high performace)
Select matnr maktx
INTO TABLE it_makt
FROM makt
FOR ALL ENTRIES IN it_mara
Where matnr = it_mara-matnr and
spras = sy-langu.
=========================================

1 資料——>工作區,工作區——>內表,
2 資料——>內表
很明顯少了一個過程 效率自然高了 如果資料量越大,效果是可想而知的
=========================================
1 每遍歷內表一下 都要select一下 select 本身就是迴圈 迴圈套迴圈 時間消耗度是n*n
2select出已經存在內表中的所有滿足條件的值 不敢說時間消耗度是n*n 但至少時間上大大地打了一下折

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/90072/viewspace-899318/,如需轉載,請註明出處,否則將追究法律責任。

相關文章