Skip to content

Unsafe COND or SWITCH Inferred Type Truncates Values ​

WarningAnti-Patterns & Bad Practices#EC NO_COND_TRUNCRemote Enabled✏️ Edit Rule on GitHub

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_TRUNC

Technical Details ​

Community & Feedback ​

Released under the MIT License.