The “scope” of a variable determines how long and in which context a variable definition remains valid. It thus determines the lifetime and the visibility of the variable.
The “lifetime” of variables can be linked to the execution of either the procedure or the current task. In the first case, the variable definition becomes invalid at the end of the related procedure; it is also no longer available if the same procedure is called again later.
Specifying the scope CURRENT restricts the lifetime of the variable to the current procedure in which the variable was declared; the scope PROCEDURE links the lifetime of the variable to the last procedure called with CALL-PROCEDURE in the current call nesting hierarchy.
Variables with the scope TASK remain available until the end of the task and are thus independent of the procedure calls in this task.
The “visibility” of a variable determines whether this variable can be accessed from within a procedure. All variables declared in the current procedure are visible, regardless of their specified scope. Any other variable is visible only if
the current procedure was called with the INCLUDE-PROCEDURE command,
the variable was visible in the calling procedure and
no other variable with the same name has been declared in the current procedure.
This means that variables are visible in the called procedure through (several nested) INCLUDE-PROCEDURE calls and can thus be used in the called procedure. A procedure called with CALL-PROCEDURE, in contrast, cannot “see” any variables which are not declared within this procedure. (An exception to this rule is the SYSSWITCH variable, see page 154 (Reserved variable names )).