Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

The Primary Key of "ITAB" is ignored because it is generic or is the standard key.

pramod_teewaree
Explorer

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

1 ACCEPTED SOLUTION

joltdx
Active Contributor

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.

3 REPLIES 3

joltdx
Active Contributor

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.

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.

joltdx
Active Contributor

That's right, Pramod!

There are a few hints about this in the ABAP documentation for DATA, key:

  • The declaration of the primary table key as a standard key can be critical for various reasons. It is best to specify key fields explicitly instead. In particular, it must be ensured that the declaration of the standard key is not added by mistake because the key was not specified explicitly.
  • The addition EMPTY KEY can provide clarity in all situations in which the definition of a table key is not important.
  • In general, it is recommended that the addition EMPTY KEY is used instead of not specifying a key definition, since otherwise the standard key is used, which often produces unexpected results.