Storage Classes

A variable's storage class determines when and for how long storage is to be allocated for the variable. Since this storage holds the variable's value, the storage class of a variable determines how long the variable retains its value.

The Open PL/I language permits the following six storage classes, which are fully explained in the section Storage Classes.

Unless declared otherwise, a variable's storage class is AUTOMATIC, meaning that it is allocated storage each time its immediately enclosing scope becomes active (as happens during a procedure call or the execution of a BEGIN statement. Exiting the scope frees this allocated storage (as happens at procedure or BEGIN block termination). Consequently, AUTOMATIC variables do not retain their values after deactivation of the block in which they are contained.

If a variable must retain its value between calls of its containing procedure, it should be declared to have the STATIC storage class. For example:

DECLARE K FIXED BINARY STATIC;
DECLARE TABLE(4) CHARACTER(5)
      STATIC INITIAL('A','B','C','D');

In this example, each element of the array TABLE is given an initial value.

Storage for STATIC variables is allocated prior to program execution by the Compiler and linker. Consequently, the length (precision) of each STATIC variable must be constant at compile time.