The TYPE command controls variable scope. The default behavior is to set the scope (i.e., NEW for M programs) at the current stack level. When the program decrements the stack (i.e., QUIT), all variables and objects referenced by those variables are deleted (i.e., KILL).
The following variable scopes are available in PSL:
Scope |
Description |
Compiler |
Identifies compiler variables. |
Literal |
Can be assigned and referenced within the PSL source code at compile time. The compiler inserts the values into the generated code as literal values. For more information on Literal scope, refer to the Literal Scope Variables section. |
Public |
Suppresses scope control in the TYPE command. Any variable or object initialized during the process is passed back to the prior controlling scope. PSL methods cannot modify public scope variables. |
|
The NEW command is supported. However, it is redundant with the TYPE command and should be avoided. |
Arrays
You can initialize arrays with the TYPE command with different classes assigned to each array level. However, the scope of the array is always the scope of its root variable. If the root variable is not defined, it defaults to the most restrictive scope of any of the array levels.
System Variables
%SystemVariables must always be in scope and contain a value within
PSL procedures. Otherwise, a run-time UNDEFINED variable occurs. %SystemVariables
should only be initialized at the batch driver or service class level
of the application, or within specific functions that protect the scope
and return the original value. For a list of system variables, click here
.