I always explain this concept to all my junior team members. The importance of selecting all the primary keys of a table while doing a FAE, even though we might not use some of the key fields later in the logic.
If we do not select all primary keys, there would be data loss at run time and it would be difficult to figure out the root cause, if the volume of data is big.There are numerous documents on this topic. And I do not want to flood the already over crowded topic with theory. Here, I am trying to provide the run-time screenshots and results, so that even the non technical personnel would understand the concept (specially our young ABAPers).
Example: Total 24 entries are present in MARC table for material 106599.
Case 1: FAE select without all primary keys
Execute the above code snippet with one material:
Runtime behaviour of FAE select: Check only two records are selected from the MARC table. Where are the rest 22?
SAP internally selects 24 entries with these two columns (matnr and mmsta in this case), but before it passes it to the internal table, it deletes adjacent duplicates. Since only one primary key is selected, in this process, rest 22 rows which are replica of row 1, i.e. matnr 106599 and mmsta blank, they all get removed.Had the second primary key, werks, would have been selected as well, then all 24 entries would have been unique and it would not have been deleted internally and would have returned correctly.
Case 2: FAE select with all primary keys
Runtime behaviour of FAE select: Check all 24 records are selected from the MARC table.
Hope you understood the importance of selecting all primary keys. So, please make a note, there is no harm in selecting all the keys. In fact, it is a good programming practice to select all primary keys whenever multiple rows of data are being fetched from any table… with FAE or normal select.
You might like to check our other post on Good Programming Practice.
Image source : via Free Stock Photos foter.com