69 lines
1.7 KiB
Plaintext
69 lines
1.7 KiB
Plaintext
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
|
|
|
|
{code} 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
|
|
|
|
----
|
|
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
|
|
----
|
|
|