Skip to content

Place Definitions at Top of Routine ​

WarningClean ABAP & Modern Syntax#EC DEF_TOPRemote Enabled

Overview ​

Place definitions at beginning of routine.

ATC Finding Message: Reorder definitions to beginning of routine; avoid scattered DATA statements

Rationale ​

A declaration in the middle of executable code interrupts the reading flow and hides that the variable exists for the whole routine. It also makes accidental use before declaration harder to spot. Put DATA, TYPES, CONSTANTS, and FIELD-SYMBOLS at the top of the routine.

Non-Compliant ​

abap
METHOD calculate.
  DATA lv_total TYPE i.
  lv_total = 100.
  DATA lv_tax TYPE i.
ENDMETHOD.

Compliant ​

abap
METHOD calculate.
  DATA lv_total TYPE i.
  DATA lv_tax TYPE i.
  lv_total = 100.
ENDMETHOD.

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.