Copy chain
copy_chain
Description
Finds a local variable that only passes a value on from one variable to another
Extended Information
Reports a local variable that only passes a value on, in two cases.
1. DATA v TYPE ... [CLEAR v.] v = src. ... y = v. when all of the following hold:
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE, or with
DATA(v) = VALUE t( ). with an explicit type and nothing in the parentheses
* v has exactly one write besides CLEAR: v = src., and all CLEARs are before it
* v has exactly one read, the complete source of y = v.
* src is a local variable, or a pass-by-value or RETURNING parameter of a method or form, its address is never
taken, and it is not written from v = src. until y = v.
* v = src. is executed before y = v. on every path: y = v. is in the same block or a nested block,
and both are in the same loop
* v and src are both reference types, or have identical types; for other types the copy into v can convert,
e.g. truncate a string into a c field. For DATA(y) = v. the types must be identical, else y changes its type
* the declaration, the CLEARs and v = src. are not chained
The quick fix deletes the declaration, the CLEARs and v = src., and changes the read to y = src.
2. DATA a TYPE REF TO c. CREATE OBJECT a. b = a. when all of the following hold:
* a is a local variable, declared with DATA without VALUE and not chained, its address is never taken
* the only other references to a are CREATE OBJECT a. and the complete source of b = a., which is the next
statement in the same block, apart from declarations like DATA in between
* CREATE OBJECT has at most TYPE and EXPORTING, it is not chained. With EXCEPTIONS, a classic exception in the
constructor would leave b unchanged instead of initial
* b is a local variable, or a pass-by-value or RETURNING parameter, whose address is never taken, it is
declared before the CREATE OBJECT and not used in its parameters, so the constructor cannot see b
* b = a. passes the syntax check, so the static type of b accepts the class of a
The quick fix deletes the declaration of a and b = a., and creates the object in b, keeping TYPE and EXPORTING.
If the static types of a and b differ, it adds TYPE with the class of a.
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.