Skip to content

Avoid WITH DEFAULT KEY ​

WarningAnti-Patterns & Bad PracticesQuickFix Ready#EC DEFAULT_KEYRemote Enabled

Overview ​

Avoid WITH DEFAULT KEY; prefer EMPTY KEY or explicit keys.

ATC Finding Message: Avoid WITH DEFAULT KEY; specify EMPTY KEY or explicit key

Rationale ​

WITH DEFAULT KEY makes every non-numeric field part of the implicit table key, so which rows count as duplicates depends on the structure definition. Adding a field later silently changes the key and can introduce unexpected duplicates or sort behavior. Use WITH EMPTY KEY for standard tables that are accessed by index, or declare an explicit key for sorted and hashed tables.

Non-Compliant ​

abap
DATA lt_open_orders TYPE STANDARD TABLE OF ty_open_order WITH DEFAULT KEY.

Compliant ​

abap
DATA lt_open_orders TYPE STANDARD TABLE OF ty_open_order WITH EMPTY KEY.

Automated QuickFix ​

This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):

  1. Position the cursor on the flagged statement.
  2. Press Ctrl + 1 (Quick Assist).
  3. Select the automated refactoring to apply the clean syntax immediately.

Suppression ​

To suppress findings for this rule, append the pseudo-comment to the statement:

abap
" Standard pseudo-comment:
... "#EC DEFAULT_KEY

" SAP CI_ prefix format:
... "#EC CI_DEFAULT_KEY

Technical Details ​

Released under the MIT License.