Boolean flag via IF

 home quick fix  example  edit

boolean_flag_via_if

Description

Finds a flag that is initialized to false and set to true in a single IF, use xsdbool

Extended Information

Reports DATA(f) = VALUE abap_bool( )., DATA(f) = abap_false. or DATA f TYPE abap_bool.,
later followed by IF cond. f = abap_true. ENDIF., when all of the following hold:

* f is a local variable of a METHOD, FORM or FUNCTION, of type c LENGTH 1, its address is never taken
* the IF has no ELSEIF and no ELSE, its only statement is f = abap_true. and it contains no comments
* f has no other write, and is not read before the IF
* the IF is in the same block and the same loop as the declaration; DATA f TYPE abap_bool. is not
executed per loop iteration, so neither it nor the IF may be in a loop

Requires xsdbool, ie. 7.40 SP08 or above, ABAP Cloud or open-abap.
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
INCLUDE, test seams, enhancements or native SQL.

The quick fix deletes an inline declaration and replaces the IF with DATA(f) = xsdbool( cond ).,
or keeps DATA f TYPE abap_bool. and replaces the IF with f = xsdbool( cond ).

use_bool_expression covers IF with an ELSE branch, without looking at the declaration and the other uses.

Default Configuration

Hover to see descriptions, Ctrl+Space for suggestions

Examples