Modernize Downcasting (CAST #( ) Expression & Inlining)
WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_CASTRemote Enabled
Overview
Modernize Downcasting (CAST #( ) & inlining).
ATC Finding Messages:
Prefer CAST #( ) constructor expression over ?= downcastCAST helper is read exactly once in the next statement; inline it
Rationale
The legacy ?= and MOVE ?TO operators are obsolete downcast statements that cannot be chained or used in modern expressions. The modern CAST #( ) expression creates cleanly typed references that can be used directly in chained calls or assignments. Furthermore, single-use downcast helper variables should be inlined into the consuming expression to prevent clutter and unnecessary temporary state.
Non-Compliant
abap
lo_child ?= lo_parent.
DATA(lo_node) = CAST lcl_node( io_obj ).
result = lo_node->get_tokens( ).Compliant
abap
lo_child = CAST #( lo_parent ).
result = CAST lcl_node( io_obj )->get_tokens( ).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 |
|---|---|---|---|
CHECK_CAST_SYNTAX | Boolean | true | Suggest modern ?= over obsolete downcast syntax |
CHECK_INLINE_CAST | Boolean | true | Suggest CAST #( ... ) constructor expression over intermediate temporary reference |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_CAST
" SAP CI_ prefix format:
... "#EC CI_PREF_CASTRelated Rules
- Prefer NEW #( ) over CREATE OBJECT —
#EC PREF_NEW_OPERATOR - Declare Constructor in PUBLIC SECTION —
#EC PREF_PUB_CTOR - Prefer CREATE_* Prefix for Factory Methods Returning Own Class —
#EC PREF_FACTORY_NAME
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_DOWNCAST - Implementation File: zcl_skylint_pref_downcast.clas.abap