Skip to main content

Problem:

You may want to do the following Visual Basic function in COBOL:

ReDim Preserve FileArray(1 To ArraySize)

It basically allows you to increase the size of your array as you need it at runtime.

Resolution:

You could move the large array to linkage then allocate memory for it at runtime when you know how many elements are needed and fix its address using "set address of lnk-array to the-pointer". It won't allow for a redim but gives some flexibility on the array size.

Here is a technique that is used by some of our developers when they want to increase the array! They allocate a new block of memory with the new size, copy the contents across, and then free the old memory. There is a whole selection of CBL_ routines for allocating memory dynamically.

Old KB# 1447