Scope of Declarations

Declarations can occur either at the job level or within subroutines. Declarations occurring at the job level can define:

  • Global variables

  • Subroutines

  • Global data specifications

Items declared at the job level can be referenced anywhere in the job, including in any of the subroutines.

Variables and subroutines declared within a subroutine are local to that subroutine. They can only be used in the subroutine they are declared in, and in subroutines nested within that subroutine. Local variables are reinitialized each time the subroutine is invoked.

Note: A variable or subroutine cannot be referenced before its declaration. For example, a subroutine cannot make use of a globally declared variable unless the declaration of that variable occurs before the declaration of the subroutine.

Special care should be taken when assigning values to a global variable in an asynchronous subroutine. Refer to PROCESS Statement for further information.