Modernize READ TABLE (Table Expressions & line_exists)
WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_TAB_EXPRRemote Enabled
Overview
Modernize READ TABLE (table expressions & line_exists).
ATC Finding Messages:
Prefer table expression itab[ ... ] over READ TABLEPrefer line_exists( ... ) instead of READ TABLE ... TRANSPORTING NO FIELDS
Rationale
Legacy READ TABLE requires procedural work areas, field symbols, and error-prone sy-subrc checks. Modern ABAP provides table expressions (itab[ ... ]) for direct value and reference retrieval, and line_exists( ... ) for existence checks. Modernizing READ TABLE simplifies code, avoids mutable intermediary variables, and embeds seamlessly into functional expressions.
Non-Compliant
abap
READ TABLE lt_orders INTO ls_order WITH KEY order_id = lv_id.
READ TABLE lt_customers TRANSPORTING NO FIELDS WITH KEY customer_id = lv_id.
IF sy-subrc = 0.
process( ).
ENDIF.Compliant
abap
ls_order = VALUE #( lt_orders[ order_id = lv_id ] OPTIONAL ).
IF line_exists( lt_customers[ customer_id = lv_id ] ).
process( ).
ENDIF.Automated QuickFix
This rule provides an automated QuickFix directly in Eclipse ABAP Development Tools (ADT):
- Position the cursor on the flagged statement.
- Press Ctrl + 1 (Quick Assist).
- Select the automated refactoring to apply the clean syntax immediately.
Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
USE_OPTIONAL | Boolean | true | Suggest OPTIONAL addition in table expressions to prevent CX_SY_ITAB_LINE_NOT_FOUND dumps |
CHECK_TAB_EXPR | Boolean | true | Suggest table expressions (lt_tab[ ... ]) instead of READ TABLE INTO |
CHECK_LINE_EXISTS | Boolean | true | Suggest line_exists( ) instead of READ TABLE TRANSPORTING NO FIELDS |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_TAB_EXPR
" SAP CI_ prefix format:
... "#EC CI_PREF_TAB_EXPRRelated Rules
- Prefer lines( ) over DESCRIBE TABLE —
#EC PREF_LINES - Prefer FILTER for a Simple LOOP with IF and APPEND —
#EC PREF_FILTER - Avoid WITH DEFAULT KEY —
#EC NO_DEFAULT_KEY
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_READ_TABLE - Implementation File: zcl_skylint_pref_read_table.clas.abap