Skip to content

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 ?= downcast
  • CAST 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):

  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.

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault ValueDescription & Guidance
CHECK_CAST_SYNTAXBooleantrueSuggest modern ?= over obsolete downcast syntax
CHECK_INLINE_CASTBooleantrueSuggest 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_CAST

Technical Details ​

Released under the MIT License.