Unnecessary copy
unnecessary_copy
Description
Finds DATA(a) = b. where a is read exactly once, and b can be read instead
Extended Information
Reports DATA(a) = b. when all of the following hold:
* a is a local variable of a METHOD, FORM or FUNCTION, and has exactly one more reference: a read,
which does not take its address, bind a field symbol to it, or pass it to USING, CHANGING or EXPORTING
* b is a plain data object: variable, constant, attribute, or a chain of components and attributes,
without calls, offsets, table expressions, field symbols or ->*
* the declaration is executed before the read on every path: the read is in the block of the declaration
or a nested block, and both are in the same loop
* b keeps its value from the declaration until the read: for a local b, no write to it and its address is
never taken; for other b, in addition no method, function or form call and no write except to local
variables, by value parameters and RETURNING in between
a has the type of b, so reading b instead does not change any conversion.
A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
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 declaration and replaces the read of a with b. No release requirement,
inline declarations need 7.40 SP02 already.
See also alias_never_reassigned for copies that are read several times.