Dynamic array handling

While using dynamic array I encounter sometimes Dynamic array is auto expanded with some value. it happens only some times and not all the times.

This issue occurs if special modules which consumes WSDL of some other application (non-mainframe), WSDL is converted to XMM which intern became Natural objects (Using Natural One). (please ask if this do not make any sense)

For example:

DEFINE DATA LOCAL
01 VAR1 (A12) DYNAMIC
END-DEFINE
*
EXPAND ARRAY VAR1 TO 5
PRINT ‘=’ OCC(VAR1) / Sometimes I get value other than 5 here :roll:
END

In order to avoid such occurrences, I have to use REDUCE to ZERO then Expand.

DEFINE DATA LOCAL
01 VAR1 (A12) DYNAMIC
END-DEFINE
*
REDUCE ARRAY VAR1 TO 0
EXPAND ARRAY VAR1 TO 5
PRINT ‘=’ *OCC(VAR1)
END

What could be wrong here. I use 8.2.4.6 Natural version.

This does not even pass syntax check on my mainframe (Nat 8.2.3).
Did you mean:

DEFINE DATA LOCAL
01 VAR1 (A12/*) 
END-DEFINE
*
EXPAND ARRAY VAR1 TO (1:5)
PRINT '=' *OCC(VAR1) /* Sometimes I get value other than 5 here
END

When you use EXPAND ARRAY on an array that is already larger than the specified size, Natural does nothing to the array. This is an efficiency decision because changing the size of an extensible array is one of the more costly things you can do in Natural. If you want to set the array to a specific size, use RESIZE ARRAY instead.

Yes, I made syntax error. :oops:

I agree to your point ‘When you use EXPAND ARRAY on an array that is already larger than the specified size, Natural does nothing to the array.’ and i had to use RESIZE instead.

But, My problem is how it is getting expanded before hitting ‘EXPAND ARRAY VAR1 TO (1:5)’ statement.

Also, where i could find the impact on performance if i use RESIZE instead of EXPAND all the time.

X-arrays don’t expand themselves. There must be an EXPAND or RESIZE somewhere prior to yours.

RESIZE, REDUCE, and EXPAND are expensive, so don’t EXPAND for each individual occurrence. EXPAND in blocks, for example 50 or 100. When done populating the array, REDUCE/RESIZE down to the actual number of occurrences.

Well, that part doesn’t make any sense to me, but then, I am not very well versed in XML and WSDL. The way your program is stated above, I don’t see any way that the extensible array could be expanded before you operate on it. If on the other hand, the module you are seeing the problem in is a subprogram and receiving the X-array as a parameter, then you will have to look to the calling module for your answer.