Problem:
Can COBOL support Dynamic Arrays?
Resolution:
Micro Focus only support Dynamic arrays in COBOL.Net where an array can be defined as:-
01 myarray object reference cMyClass occurs any.
and then do:-
set size of myarray to 100
On Non .Net platforms (Server Express and Net Express) then there is a need to use one of the OO Collection classes. There is an Array class (for example bytearray) that should do what is required. Depending on the requirement there are also other collection classes that could work depending on what the exact needs are.
The only other solution would be to put the definition of the array in LINKAGE SECTION and allocate it dynamically. For example:-
LINKAGE SECTION.
01 my-array.
03 my-item pic x(100) occurs 1 to 1000000 depening on ws-length
At runtime the code could then work out the length required and do something similar to as follows:
compute ws-length = *> Code to work out the length
call "cbl_alloc_mem" using ws-length *> and other parameters
set address of my-array to ws-return-address-from-cbl-alloc-mem