Skip to main content

so the following;

01 di-val string occurs any.

set size of di-val to 1.
move "123" to di-val(1)
set size of di-val to 2.
move "ac" to di-val(2)

When "set size of di-val to 2" is executed, di-val(1) is set to null (ie. all elements in the array are set to null)

Is there any way around this or an alternative approach. I basically want an array that can contain strings of varying lengths without taking up too much memory.


#managedcode
#VisualCOBOL

so the following;

01 di-val string occurs any.

set size of di-val to 1.
move "123" to di-val(1)
set size of di-val to 2.
move "ac" to di-val(2)

When "set size of di-val to 2" is executed, di-val(1) is set to null (ie. all elements in the array are set to null)

Is there any way around this or an alternative approach. I basically want an array that can contain strings of varying lengths without taking up too much memory.


#managedcode
#VisualCOBOL

To resize the array without clearing the existing contents, you can use the alternative syntax:

set size of ARRAY up by DELTA

set size of ARRAY down by DELTA

You may have to calculate the delta yourself if you only know the new size of the array. Here is the working version of your code:

       01 di-val string occurs any.

           set size of di-val to 1.
           move "123" to di-val(1)
           set size of di-val up by 1.
           move "ac" to di-val(2)
           display di-val(1)
           display di-val(2)


To resize the array without clearing the existing contents, you can use the alternative syntax:

set size of ARRAY up by DELTA

set size of ARRAY down by DELTA

You may have to calculate the delta yourself if you only know the new size of the array. Here is the working version of your code:

       01 di-val string occurs any.

           set size of di-val to 1.
           move "123" to di-val(1)
           set size of di-val up by 1.
           move "ac" to di-val(2)
           display di-val(1)
           display di-val(2)

Fantastic! Thank you very much. I appreciate it