上次介紹了Performace tuning 有介紹將internal table改用hash table,
用read 的方式因為hash table內key值為唯一值,故速度上來看會比較快一點點
通常直接用select的,有可能因為撈的資料不是table的key值,若直接into table會造成ABAP DUMP
或是說要做任何運算後,要撈取最新的資料等…
所以我們會Into internal table,做排除重覆之後,再置入hash table內,切記一定要排序喲!
排除重覆的語法「DELETE ADJACENT DUPLICATES FROM "it_table" COMPARING "key 值".」
接下來我們來看範例囉!
DATA: BEGIN OF it_marc OCCURS 0,
matnr LIKE marc-matnr, "物料號碼
mmsta LIKE marc-mmsta, "特定工廠的物料狀態
END OF it_marc.
DATA: ht_marc LIKE HASHED TABLE OF it_marc
WITH UNIQUE KEY matnr
WITH HEADER LINE.
SELECT matnr mmsta
INTO TABLE it_marc
FROM marc
WHERE werks = p_werks
AND mmsta IN ('01').
SORT it_marc BY matnr.
DELETE ADJACENT DUPLICATES FROM it_marc
COMPARING matnr.
ht_marc[] = it_marc[].
以上,分享完畢,若有錯誤,歡迎大家指教告知,謝謝!
留言列表