Skip to content

Avoid Repeating the Same String Literal ​

WarningAnti-Patterns & Bad Practices#EC NO_DUP_LITERALSRemote Enabled

Overview ​

Avoid repeating the same string literal.

ATC Finding Message: Replace repeated literals with a constant

Rationale ​

Repeating the same string literal in several places couples unrelated code to an unnamed value and makes a later change error-prone. Define a constant with a meaningful name and reuse it. The check focuses on fixed string literals that occur at least three times.

Non-Compliant ​

abap
IF lv_status = 'ACTIVE'.
  lv_text = 'ACTIVE'.
ENDIF.

Compliant ​

abap
CONSTANTS c_active TYPE string VALUE 'ACTIVE'.
IF lv_status = c_active.
  lv_text = c_active.
ENDIF.

Configuration & Thresholds ​

This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:

Parameter NameData TypeDefault ValueDescription & Guidance
MIN_OCCURRENCESInteger3Minimum occurrences of identical string literal before reporting (default: 3)
MIN_LENGTHInteger3Minimum character length of string literal to inspect (default: 3)

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.