05-25-2021 5:56 AM
Hello,
With ABAP 7.5 we can perform a select directly from an internal table. This feature is very useful to be used instead of For All Entries. The syntax is as follows:
SELECT a, b
FROM @itab
WHERE a EQ '1'.
However, this generates the following warning in the editor:
The primary key of "itab" is ignored because it is generic or is the standard key.
This warning message can be hidden using the pragma ITAB_KEY_IN_SELECT, but I would like to understand what it really means and how is it normally catered for.
Thanks,
Best Regards,
Pramod
05-25-2021 7:01 AM
Hi!
Yes, just as the warning message, the ABAP documentation for SELECT, FROM @itab also statest that:
The internal table should have an explicitly defined primary key (which can be empty). Generic primary keys and standard keys are not evaluated when read and a syntax check warning occurs.
So, if possible, you should either define a real and relevant key for your itab, or you declare it with WITH EMPTY KEY.
05-25-2021 7:01 AM
Hi!
Yes, just as the warning message, the ABAP documentation for SELECT, FROM @itab also statest that:
The internal table should have an explicitly defined primary key (which can be empty). Generic primary keys and standard keys are not evaluated when read and a syntax check warning occurs.
So, if possible, you should either define a real and relevant key for your itab, or you declare it with WITH EMPTY KEY.
05-25-2021 7:59 AM
Thanks Jörgen,
So if I understand it well, it is important to define the internal table with a Primary Key (or EMPTY KEY) so that it can be evaluated in the select.
In my current case I do not need a primary key and therefore I declared the table with EMPTY KEY.
I guess one of the best practices to add to our list is to use tables with Keys defined with the addition of SORTED / HASHED tables when required for efficient programming and execution.
05-25-2021 12:05 PM
That's right, Pramod!
There are a few hints about this in the ABAP documentation for DATA, key: