Constant condition

 home quick fix  example  edit

constant_condition

Description

Finds IF and ELSEIF conditions on local variables whose value is known

Extended Information

Reports two cases, for local variables of a METHOD, FORM or FUNCTION.

1. DATA(c) = . where the constant is a character literal like 'X', or a character constant like
abap_true, abap_false or space, and the only other reference to c is the condition of an IF or ELSEIF:
c = , c <> , EQ, NE, c IS INITIAL, c IS NOT INITIAL, optionally with NOT.
The declaration must be executed before the condition on every path: the IF is in the block of the
declaration or a nested block. The quick fix deletes the declaration.

2. DATA v TYPE ... without VALUE, where v is never changed, except by CLEAR v., and its address is never taken,
in a condition v IS [NOT] INITIAL or v IS [NOT] BOUND. The declaration is kept.

The quick fix removes the IF branch that is never taken, or keeps the branch that is always taken and
removes the rest, also in ELSEIF chains: a first IF branch that is never taken turns the next ELSEIF into IF,
an ELSEIF branch that is always taken turns into ELSE. Nothing is reported if a removed branch declares
data that is used outside of it.

Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
INCLUDE, test seams, enhancements or native SQL. No release requirement.

Default Configuration

Hover to see descriptions, Ctrl+Space for suggestions

Examples