Unsafe COND or SWITCH Inferred Type Truncates Values
Overview
Unsafe COND or SWITCH inferred type truncates values.
ATC Finding Message:
COND/SWITCH #( ) infers short C type and truncates longer branches
Rationale
When using COND #( ... ) or SWITCH #( ... ) with string literals, ABAP derives the result type from the first THEN branch operand. If the first operand is a short text literal (e.g. 'OK' with type C LENGTH 2), subsequent longer branch values (such as 'PENDING') are silently truncated to match the first length. Specify the target type explicitly, e.g. COND string( ... ), or ensure the type accommodates all branches.
Non-Compliant
abap
DATA(lv_status) = COND #( WHEN lv_ok = abap_true THEN 'OK' ELSE 'PROCESSING' ).Compliant
abap
DATA(lv_status) = COND string( WHEN lv_ok = abap_true THEN 'OK' ELSE 'PROCESSING' ).Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
abap
" Standard pseudo-comment:
... "#EC NO_COND_TRUNC
" SAP CI_ prefix format:
... "#EC CI_NO_COND_TRUNCRelated Rules
- Collapse Value-Mapping IF Chains into COND —
#EC PREF_COND - Convert Pure CASE Mappings into SWITCH Expressions —
#EC PREF_SWITCH
Technical Details
- Native ATC Class:
/SKYL/CL_NO_COND_TRUNC - ABAP Implementation: /skyl/cl_no_cond_trunc.clas.abap
- Rule Metadata: rules-data.mjs (Line 6064)