Storage allocation is the process of associating an area of storage with a variable so that the data item(s) represented by the variable can be recorded internally. When storage is associated with a variable, the variable is allocated.
Allocation for a given variable can take place statically, (before the execution of the program) or dynamically (during execution). A variable that is allocated statically remains allocated for the duration of the application program. A variable that is allocated dynamically relinquishes its storage either upon the termination of the block containing that variable, or at an explicit request from the application.
The storage class assigned to a variable determines the degree of storage control applied to it and the manner in which the variable’s storage is allocated and freed. There are four storage classes: automatic, static, controlled, and based. You assign the storage class using its corresponding attribute in an explicit, implicit, or contextual declaration:
Based variables outside of areas can be allocated and freed using the ALLOCATE built-in function and PLIFREE built-in subroutine respectively. They can also be allocated using the AUTOMATIC built-in function; such allocated variables are freed automatically when the block in which they are allocated terminates.
Storage class attributes can be declared explicitly for element, array, and major structure and union variables. For array and major structure and union variables, the storage class declared for the variable applies to all of the elements in the array or structure or union.
Storage class attributes cannot be specified for:
Allocation of storage for variables is managed by PL/I. You do not specify where in storage the allocation is to be made. You can, however, specify that a variable be allocated in an existing AREA. For more information, refer to Area data and attribute.