# Appending values to an array

**URL:** <https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes, NaturalONE\
**Created:** [August 24, 2021, 2:54pm UTC](https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807 "2021-08-24T14:54:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tomas\_Moraes](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/tomas_moraes/32/6982_2.png) [@Tomas\_Moraes](https://techcommunity.softwareag.com/u/Tomas_Moraes)\
**Post date:** [August 24, 2021, 2:54pm UTC](https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807/1 "2021-08-24T14:54:19Z")

</div>

I made an array and I want to populate its fields under certain conditions along my program.  
So I´d like to do an “append” operation in my array. In other languages I can find statements to handle this.  
Is there a “method” or a straight command to do this in Natural? Thank you!

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [August 24, 2021, 4:47pm UTC](https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807/2 "2021-08-24T16:47:28Z")

</div>

Take a look at the commands EXPAND ARRAY, RESIZE ARRAY and REDUCE ARRAY and the accompanying discussion of X-Arrays.

If this isn’t what you are looking for, please provide some details about your use case and perhaps some simple code examples to illustrate your question.

---

<div class="post-metadata">

**Author:** ![Tomas\_Moraes](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/tomas_moraes/32/6982_2.png) [@Tomas\_Moraes](https://techcommunity.softwareag.com/u/Tomas_Moraes)\
**Post date:** [September 2, 2021, 6:36pm UTC](https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807/3 "2021-09-02T18:36:30Z")

</div>

@Douglas_Kelly I appreciate your interest, thank you!  
I´ve been thinking better and in fact my need is to increment the values in the array, and not its number of fields. I’m using this array to control the amount of records that I´ll write in a work file. Here’s my idea for now ( this “FOR” loop is a “READ” in my real version ). Do you think this works?

DEFINE DATA LOCAL  
1 #EXP (N2/1:3)  
1 #I (N07)  
1 #Q (N07)  
1 #TIMN (N07) 1 REDEFINE #TIMN  
2 #HHIISS (N06)  
2 #T (N01)  
1 #R2 (N02)  
1 #R3 (N02)  
1 #R7 (N02)  
END-DEFINE  
/\*  
/\* JUST TAKING SOME NUMBERS TO POPULATE THE ARRAY “IN A NON-ORDERED WAY”  
FOR #I FROM 11 TO 9999999 STEP 1  
DIVIDE 2 INTO #I GIVING #Q REMAINDER #R2  
DIVIDE 3 INTO #I GIVING #Q REMAINDER #R3  
DIVIDE 7 INTO #I GIVING #Q REMAINDER #R7  
DECIDE FOR FIRST CONDITION  
WHEN ( #R2 EQ 0 AND #EXP(1) LE 9 ) ADD 1 TO #EXP(1)  
WHEN ( #R3 EQ 0 AND #EXP(2) LE 9 ) ADD 1 TO #EXP(2)  
WHEN ( #R7 EQ 0 AND #EXP(3) LE 9 ) ADD 1 TO #EXP(3)  
WHEN NONE  
MOVE _TIMN TO #TIMN ADD #T TO #I /_ ATTEMPT TO GET SOME “RANDOM VALUES”  
END-DECIDE  
RESET #Q  
END-FOR  
WRITE ‘AMOUNT OF MULTIPLES OF 2 =’ #EXP(1)  
/ ‘AMOUNT OF MULTIPLES OF 3 =’ #EXP(2)  
/ ‘AMOUNT OF MULTIPLES OF 7 =’ #EXP(3)  
ON ERROR  
EJECT  
TERMINATE 50  
END-ERROR  
END

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [September 7, 2021, 8:39pm UTC](https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807/4 "2021-09-07T20:39:11Z")

</div>

I have read your response to Doug; but still do not understand what you are trying to explain. I am guessing there is a language problem. If so, could you get someone to re-write the explanation.

---

<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:** [December 6, 2021, 8:39pm UTC](https://techcommunity.softwareag.com/t/appending-values-to-an-array/243807/5 "2021-12-06T20:39:54Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
