Controlled storage and attribute
Variables declared as CONTROLLED are allocated only when you specify them in an ALLOCATE statement. A controlled variable remains allocated until a FREE statement that names the variable is encountered or until the end of the program.
Controlled variables are partially independent of the program block structure, but not completely. The scope of a controlled variable can be internal or external. When it is declared as internal, the scope of the variable is the block in which the variable is declared and any contained blocks. Any reference to a controlled variable that is not allocated is in error.
You cannot pass variables that are not declared as CONTROLLED to a procedure that declares them as CONTROLLED. However, you can pass a variable that is declared as CONTROLLED to a procedure that does not declare it as CONTROLLED.
Abbreviation: CTL
X can be
validly referred to within procedure B and that part
of procedure A that follows execution of the CALL
statement. A: proc;
dcl X controlled;
call B;
.
.
.
B: proc;
allocate X;
.
.
end B;
end A; dcl A(M,N) ctl;
get list(M,N);
allocate A;
get list(A);
.
.
.
free A;This method is more efficient than the alternative of setting up a begin-block, because block activation and termination are not required.
