Skip to content

Prefer Early Return to Reduce Nesting (Guard Clauses) ​

WarningClean ABAP & Modern Syntax#EC PREF_GUARD_METHODRemote Enabled

Overview ​

Prefer early return or continue over nested IF blocks.

ATC Finding Messages:

  • Invert IF condition and use RETURN to reduce nesting in method
  • Invert IF condition and use CONTINUE to reduce nesting in loop

Rationale ​

Wrapping the whole method body in IF is_valid( ) creates unnecessary nesting and pushes the happy path to the right. Guard clauses reject invalid input at the top and leave the main logic flat and easy to read. Return early for preconditions and error cases instead of indenting the successful path.

Non-Compliant ​

abap
METHOD process_order.
  IF is_valid( ).
    execute_order( ).
    log_order( ).
  ENDIF.
ENDMETHOD.

Compliant ​

abap
METHOD process_order.
  IF NOT is_valid( ).
    RETURN.
  ENDIF.
  execute_order( ).
  log_order( ).
ENDMETHOD.

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_METHOD_RETURNBooleantrueSuggest early RETURN guard clause for top-level method validation IFs
CHECK_LOOP_CONTINUEBooleantrueSuggest early CONTINUE guard clause for loop item validation IFs

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.