Function
The ALLOCATE statement allocates dynamic storage.
Format 1 | If storage is requested for a data description (data-name-1) for which the BASED |
Format 2 | If storage is requested as a number of characters, the address of the allocated |
Format 1
ALLOCATE data-name-1
[INITIALIZED] [RETURNING identifier-2]
Syntax rule
data-name-1 must be an elementary item which is specified with the BASED clause.
If identifier-2 is a type-specific data pointer, data-name-1 must also be type-based and the associated types must match.
If data-name-1 is strongly typed, identifier-2 must also be a type-specific pointer which is allocated the same type as data-name-1.
identifier-2 must reference an elementary item of the category "data pointer".
Format 2
ALLOCATE arithmetical-expression CHARACTERS
[INITIALIZED] RETURNING identifier-2
Syntax rule
identifier-2 may not be a type-specific data pointer.
identifier-2 must reference an elementary item of the category "data pointer".
General rules for formats 1 and 2
arithmetical-expression defines the number of bytes in storage which are requested. The result of the evaluation of arithmetical-expression is placed in an internal data item which is defined with
PIC S9(9) BINARY
.If the result of the evaluation is less than or equal to NULL, no storage is requested and identifier-2 contains the predefined value NULL.
With format 1 the size of the requested storage is determined by how much space is required for a data description data-name-1. If a data description which is subordinate to data-name-1 contains an OCCURS DEPENDING clause, the maximum length of the record is requested.
If the requested storage space is available, it is allocated. With format 1 the address of data-name-1 is set to the address of the allocated storage. The data pointer identifier-2 from the RETURNING phrase is set to the address of the allocated storage.
If the requested storage space is not available, the address of data-name-1 and/or the data pointer identifier-2 from the RETURNING phrase are set to NULL. The exception condition EC-STORAGE-NOT-AVAIL occurs. If the check for EC-STORAGE-NOT-AVAIL is activated, the associated exception condition is triggered and control is transferred to the corresponding USE procedure. After the return from the USE procedure, processing continues with the executable statement following the ALLOCATE statement.
The INITIALIZED phrase in format 1 causes an INITIALIZE statement INITIALIZE dataname-1 WITH FILLER ALL TO VALUE THEN TO DEFAULT to be executed for dataname-1.
If the INITIALIZED phrase is missing in format 1, an INITIALIZE statement INITIALIZE data-name-1 WITH FILLER REPLACING DATA-POINTER BY NULL, PROGRAM-POINTER BY NULL, OBJECT-REFERENCE BY NULL is executed.
The INITIALIZED phrase in format 2 causes the allocated storage to be initialized with binary NULLS.
If the INITIALIZED phrase is missing in format 2, the content of the allocated storage is undefined.
The storage remains allocated until it is explicitly released with a FREE statement or the program run is terminated.