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 Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_LIKE | Boolean | true | Enable checking for invalid wildcard usage in LIKE comparisons (defaults to true) |
CHECK_CP | Boolean | true | Enable 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_WILDCARDRelated Rules
- Prefer BETWEEN for Inclusive Range Checks —
#EC PREF_BETWEEN - Avoid Repeating the Same String Literal —
#EC NO_DUP_LITERALS
Technical Details
- Native ATC Class:
ZCL_SKYLINT_NO_WRONG_WILDCARD - Implementation File: zcl_skylint_no_wrong_wildcard.clas.abap