rspec/rules/S1896/rpg/rule.adoc

68 lines
1.9 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
Non-static variables initialized with ``++INZ()++`` are only reliably initialized on the first run through the code in a "terminate and stay resident" (TSR) program. Subsequent calls to the program within the same job do not re-initialize the variable with the value from ``++INZ()++`` unless the last record indicator is set at the end of the program.
2021-04-28 16:49:39 +02:00
Without setting the last record indicator, the assumptions the code makes about the variable's initial value will be wrong every time but one, potentially leading to bad program behavior.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,rpg]
----
D TESTINZ PR extpgm('TESTINZ')
2021-04-28 16:49:39 +02:00
D Parm1 15A
D Parm2 15A CONST
DMUTVAR S 15A INZ('ABC') // Noncompliant; *inlr not set
D TESTINZ PI
D Parm1 15A
D Parm2 15A CONST
/Free
IF %PARMS > 1 and Parm2 <> '';
MUTVAR=Parm2;
ENDIF;
DSPLY(E) ('MUTVAR:' + MUTVAR);
Parm1=MUTVAR;
return;
/End-free
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,rpg]
2021-04-28 16:49:39 +02:00
----
D TESTINZ PR extpgm('TESTINZ')
D Parm1 15A
D Parm2 15A CONST
DMUTVAR S 15A INZ('ABC')
D TESTINZ PI
D Parm1 15A
D Parm2 15A CONST
/Free
IF %PARMS > 1 and Parm2 <> '';
MUTVAR=Parm2;
ENDIF;
DSPLY(E) ('MUTVAR:' + MUTVAR);
Parm1=MUTVAR;
*inlr = *on;
return;
/End-free
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this use of "Inz()", and set "xxx"'s default value at the beginning of the program.
endif::env-github,rspecator-view[]