Skip to content

Avoid Wrong Wildcards in LIKE, CP, and NP ​

WarningAnti-Patterns & Bad Practices#EC NO_WRONG_WILDCARDRemote Enabled

Overview ​

Avoid wrong wildcards in LIKE, CP, and NP.

ATC Finding Messages:

  • Use % or _ as wildcards in LIKE comparisons instead of *
  • Use * or + as wildcards in CP and NP comparisons instead of %

Rationale ​

ABAP SQL LIKE statements use '%' (matching any sequence of characters) and '_' (matching a single character) as wildcards. In contrast, ABAP logical comparison operators CP and NP use '' and '+' as wildcards. Using '' in LIKE or '%' in CP/NP indicates confusion between SQL pattern matching and ABAP string matching.

Non-Compliant ​

abap
SELECT SINGLE carrid FROM scarr WHERE carrid LIKE '*LH*' INTO @lv_text.
IF lv_text CP 'prefix%'.
  RETURN.
ENDIF.

Compliant ​

abap
SELECT SINGLE carrid FROM scarr WHERE carrid LIKE '%LH%' INTO @lv_text.
IF lv_text CP 'prefix*'.
  RETURN.
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
CHECK_LIKEBooleantrueEnable checking for invalid wildcard usage in LIKE comparisons (defaults to true)
CHECK_CPBooleantrueEnable checking for invalid wildcard usage in CP and NP comparisons (defaults to true)

Suppression ​

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

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

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

Technical Details ​

Released under the MIT License.