Prefer nmin/nmax or clamp Expressions over Manual IF Clamping
WarningClean ABAP & Modern SyntaxQuickFix Ready#EC PREF_CLAMPRemote Enabled
Overview
Prefer nmin/nmax over manual IF clamp.
ATC Finding Message:
Manual range clamping detected; consider using nmin( ) and nmax( )
Rationale
Manually clamping a variable between lower and upper bounds using IF/ELSEIF statements is verbose and imperative. Modern ABAP provides built-in functions like nmin( ) and nmax( ) or clamp( ) that express range containment concisely and without branch complexity.
Non-Compliant
abap
IF lv < lo.
lv = lo.
ELSEIF lv > hi.
lv = hi.
ENDIF.Compliant
abap
lv = nmin( val1 = hi
val2 = nmax( val1 = lo
val2 = lv ) ).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.
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC PREF_CLAMP
" SAP CI_ prefix format:
... "#EC CI_PREF_CLAMPRelated Rules
- Prefer BETWEEN for Inclusive Range Checks —
#EC PREF_BETWEEN - Prefer COND #( ) Expression over IF/ELSEIF/ELSE —
#EC PREF_COND - Prefer SWITCH #( ) Expression over CASE Statement —
#EC PREF_SWITCH
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_CLAMP - Implementation File: zcl_skylint_pref_clamp.clas.abap