Skip to content

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):

  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_CLAMP

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

Technical Details ​

Released under the MIT License.