Global variables that are only used by a single subprocedure should be declared in that subprocedure, thus limiting both their scope and other procedures' ability to modify the variable unexpectedly.


If the variable has been declared in the global scope to preserve its value between calls, add the ``++STATIC++`` keyword to the new local declaration. It will be added to the global heap and retained until the program ends, but only accessible by the subprocedure in which it was declared.


== Noncompliant Code Example

----
     D SUBPROC1        PR
     D  Parm1                         5  0 Const

     D X               S              5  0    // Noncompliant; only used in one subproc

      /Free
       SUBPROC1(1234);
       *inlr = *on;
       return;
       /End-free

     P SUBPROC1        B
     D SUBPROC1        PI
     D  Parm1                         5  0 Const
      /Free
       X = Parm1 + 1;                        // X is only used here
       DSPLY(E) X;
      /End-Free
     P                 E
----


== Compliant Solution

----
     D SUBPROC1        PR
     D  Parm1                         5  0 Const

      /Free
       SUBPROC1(1234);
       *inlr = *on;
       return;
       /End-free

     P SUBPROC1        B
     D SUBPROC1        PI
     D  Parm1                         5  0 Const
     D X               S              5  0
      /Free
       X = Parm1 + 1;
       DSPLY(E) X;
      /End-Free
     P                 E
----

