從字面看好像作用是相同的储玫,但具體使用以來還是有區(qū)別的。如果都是從數(shù)據(jù)庫表中select一次數(shù)據(jù)驯镊,添加到內(nèi)表中葫督,他們的作用相同;但是多次板惑,他們的作用則有很大差別橄镜,INTO TABLE:將數(shù)據(jù)select出來添加到內(nèi)表時會將內(nèi)表先清空再添加,而APPENDING TABLE則會直接追加冯乘,實現(xiàn)累計效果洽胶。
解釋事例:
DATA:BEGIN OF lt_matnr OCCURS 0,
matnr TYPE mara-matnr,
END OF lt_matnr.
WRITE :/ '兩次INTO TABLE,內(nèi)表數(shù)據(jù):'.
SELECT matnr UP TO 1 ROWS INTO TABLE lt_matnr FROM mara.
SELECT matnr UP TO 1 ROWS INTO TABLE lt_matnr FROM mara.
LOOP AT lt_matnr.
WRITE:/ lt_matnr-matnr.
ENDLOOP.
REFRESH :lt_matnr.
WRITE :/ '-----------------------------------------------------------'.
WRITE :/ '兩次APPENDING TABLE,內(nèi)表數(shù)據(jù):'.
SELECT matnr UP TO 1 ROWS APPENDING TABLE lt_matnr FROM mara.
SELECT matnr UP TO 1 ROWS APPENDING TABLE lt_matnr FROM mara.
LOOP AT lt_matnr.
WRITE:/ lt_matnr-matnr.
ENDLOOP.
運行結(jié)果
實戰(zhàn)中的用法:
例如我們預(yù)計需新建的表數(shù)據(jù)會達到億級別數(shù)據(jù),從查詢性能的角度考慮裆馒,我們需要將表按照一定的數(shù)據(jù)維度姊氓,將表拆分成幾個去存儲數(shù)據(jù)丐怯。那么在查詢是就需要將幾張表的數(shù)據(jù)都放到一個內(nèi)表中,由于這種場景中多表的結(jié)構(gòu)基本相同翔横,所以使用APPENDING TABLE將會大大簡化代碼
SELECT matnr
lifnr
werks_d AS werks
oder_flag
APPENDING TABLE lt_zpu_matnr
FROM zpu_matnr_d
WHERE matnr = ls_mepoitem-matnr
AND lifnr IN (ls_mepoitem-charg,'')
AND werks_d = lv_lgort1
AND datae >= sy-datum
AND datab <= sy-datum
AND oder_flag = space
AND del_flag = space
AND enable = 'X'.
SELECT matnr
lifnr
werks_d AS werks
oder_flag
APPENDING TABLE lt_zpu_matnr
FROM zpu_matnr_l
WHERE matnr = ls_mepoitem-matnr
AND lifnr IN (ls_mepoitem-charg,'')
AND werks_d = lv_lgort1
AND datae >= sy-datum
AND datab <= sy-datum
AND oder_flag = space
AND del_flag = space
AND enable = 'X'.
SELECT matnr
lifnr
werks_s AS werks
oder_flag
APPENDING TABLE lt_zpu_matnr
FROM zpu_matnr_p
WHERE matnr = ls_mepoitem-matnr
AND lifnr IN (ls_mepoitem-charg,'')
AND werks_s = lv_lgort1
AND datae >= sy-datum
AND datab <= sy-datum
AND oder_flag = space
AND del_flag = space
AND enable = 'X'.
SELECT matnr
lifnr
werks_s AS werks
oder_flag
APPENDING TABLE lt_zpu_matnr
FROM zpu_matnr_s
WHERE matnr = ls_mepoitem-matnr
AND lifnr IN (ls_mepoitem-charg,'')
AND werks_s = lv_lgort1
AND datae >= sy-datum
AND datab <= sy-datum
AND oder_flag = space
AND del_flag = space
AND enable = 'X'.
http://bbs.sapclub.cc/thread-301-1-1.html
(出處: SAP顧問圈)