CLEAR before overwrite

 home quick fix  example  edit

clear_before_overwrite

Description

Finds CLEAR of a local variable whose next use overwrites it completely

Extended Information

Reports CLEAR v. when all of the following hold:

* v is a local variable of a METHOD, FORM or FUNCTION, its address is never taken: no field symbol,
REF #( ), GET REFERENCE, and it is not passed to a parameter by reference
* the CLEAR is not chained and has no WITH addition
* the next reference to v is a full overwrite in the same block: v = ., including v = NEW ...,
or CREATE OBJECT v. with optional TYPE and EXPORTING, where nothing else in the statement references v.
Not ?=, READ TABLE INTO, offset/length or component writes, CREATE OBJECT with EXCEPTIONS, or other
statements that can leave v unchanged
* every statement between the CLEAR and the overwrite is a direct statement of the block, not a nested structure,
and does not reference v
* v is not a table with header line
* if a TRY or CATCH SYSTEM-EXCEPTIONS encloses the CLEAR, nothing from the CLEAR to the overwrite can raise
an exception, a CATCH could see the old value: the overwrite directly follows the CLEAR and assigns a variable
or a literal of identical type, or a reference variable

Unlike clear_after_declaration, the CLEAR can be in a loop.
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 the CLEAR. No release requirement.

Default Configuration

Hover to see descriptions, Ctrl+Space for suggestions

Examples