Skip to content

Prefer CAST #( ) over ?= ​

WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_CASTRemote Enabled

Overview ​

Prefer modern CAST #( ) expression over ?=.

ATC Finding Message: Prefer CAST #( ) constructor expression over ?= downcast

Rationale ​

The ?= downcast operator is legacy syntax and cannot be nested inside expressions. CAST #( ) returns a typed reference and can be used directly in call chains or constructor expressions. Use CAST for downcasts and let # infer the target type.

Non-Compliant ​

abap
lo_invoice ?= lo_document.

Compliant ​

abap
lo_invoice = CAST #( lo_document ).

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 PREF_CAST

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

Technical Details ​

Released under the MIT License.