The ALLOCATE statement allocates storage for based variables and sets a locator variable that can be used to identify the location, independent of procedure block boundaries.
Abbreviation: ALLOC
Both based and controlled variables can be allocated in the same statement. For the syntax of controlled variables, see ALLOCATE statement for controlled variables.
Storage is allocated in an area when the IN option is specified or the SET option specifies an offset variable. These options can appear in any order. For allocations in areas:
When an area is not used, the locator variable must be a pointer variable. If storage for the based variable is not available, the STORAGE condition is raised.
Note that if a based variable uses REFER, it size will be calculated at run-time. If this calculation yields a value that is too large to fit in a FIXED BIN(31) variable, then your program is in error and should be corrected. In this situation, the STORAGE condition will not be raised; instead the ERROR condition with ONCODE=3809 will be raised if:
If neither of these conditions apply, unpredictable results will occur.
The amount of storage allocated for a based variable depends on its attributes, and on its dimensions, length, or size specifications if these are applicable at the time of allocation. These attributes are determined from the declaration of the based variable.
A based structure or union can contain adjustable array bounds or string lengths or area sizes (see REFER option (self-defining data)). The asterisk notation for extents is not allowed for based variables.