Skip to content

Prefer READ TABLE WITH KEY over WHERE ​

WarningPerformance & Database#EC PREF_READ_KEYRemote Enabled

Overview ​

READ With WITH KEY Instead of WHERE.

ATC Finding Message: READ TABLE WHERE - use WITH KEY so the access benefits from key optimization

Rationale ​

READ TABLE ... WITH KEY is the documented single-line access form and allows the runtime to exploit table keys and sorted access for a direct hit. The WHERE variant of READ TABLE forces a row-by-row scan of the internal table. The rule only reports WHERE clauses that WITH KEY can express: pure equality comparisons ( = / EQ ) combined with AND. Conditions with other operators ( CS, GT, OR, IS, ... ) cannot be converted and are not flagged. Clean ABAP cheat sheet (Single Line Access) recommends WITH KEY for one-line lookups.

Non-Compliant ​

abap
READ TABLE lt_data INTO ls_data WHERE field1 = 'X'.

Compliant ​

abap
READ TABLE lt_data INTO ls_data WITH KEY field1 = 'X'.

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.