# Dynamic array handling

**URL:** <https://techcommunity.softwareag.com/t/dynamic-array-handling/189308>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [June 28, 2016, 2:49pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308 "2016-06-28T14:49:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Puru\_Kaushik](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@Puru\_Kaushik](https://techcommunity.softwareag.com/u/Puru_Kaushik)\
**Post date:** [June 28, 2016, 2:49pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308/1 "2016-06-28T14:49:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [June 28, 2016, 4:59pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308/2 "2016-06-28T16:59:45Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![Puru\_Kaushik](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@Puru\_Kaushik](https://techcommunity.softwareag.com/u/Puru_Kaushik)\
**Post date:** [June 30, 2016, 3:12pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308/3 "2016-06-30T15:12:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [July 1, 2016, 7:16pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308/4 "2016-07-01T19:16:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [July 1, 2016, 11:30pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308/5 "2016-07-01T23:30:48Z")

</div>

> [@Puru Kaushik](#):
>
> 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)

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:36pm UTC](https://techcommunity.softwareag.com/t/dynamic-array-handling/189308/6 "2021-04-02T15:36:22Z")

</div>


