Tuesday, March 15, 2011

ABAP FOR ALL Entries much better!

This morning, I have stumbled over this FOR ALL ENTRIES as I got missing entries on my result set.
I noticed that including FOR ALL ENTRIES statement resulted in a deletion of a duplicate records. Also, take note that if the internal table is blank, all entries will be considered in your table being selected.

RECOMMENDATIONs:

1. The primary key fields of the driver table should all be included to avoid duplicate of records.

2.  Use all keys of driver table against the db table.

2. Sort the driver table by its keys.

EX. If you want to get the hkont field in EKKN table, always include the ebeln and ebelp key fields.

SORT at_it_ekpo by ebeln. "

SELECT
   ebeln
   ebelp
   hkont
INTO at_it_ekkn FROM ekkn
FOR ALL ENTRIES OF at_it_ekpo
WHERE ebeln = at_it_ekpo-ebeln.

FOR ALL ENTRIES is like a join statement in open sql. This is a good alternative to minimize DB resources in your program.

No comments:

Post a Comment