
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
68 lines
1.9 KiB
Plaintext
68 lines
1.9 KiB
Plaintext
== 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.
|
|
|
|
|
|
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
|
|
|
|
[source,rpg]
|
|
----
|
|
D TESTINZ PR extpgm('TESTINZ')
|
|
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
|
|
|
|
[source,rpg]
|
|
----
|
|
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[]
|