# use group in array

**URL:** <https://techcommunity.softwareag.com/t/use-group-in-array/186338>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [January 20, 2016, 4:44pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338 "2016-01-20T16:44:21Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thierry\_Couairon](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/thierry_couairon/32/300_2.png) [@Thierry\_Couairon](https://techcommunity.softwareag.com/u/Thierry_Couairon)\
**Post date:** [January 20, 2016, 4:44pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/1 "2016-01-20T16:44:21Z")

</div>

hello

I have this code

```auto

1 level1
2 level2 (/ 1: 10)
3 leve21 (a3)
3 level22 (a3)
****
1 h-level1
2 level2 (/1:*)
3 level21 (a3)
3 level22 (a3)

resize array h-level1.level2 to (1:10)
move to by name level1 level1-h ==> compilation error NAT0631

```

i try this

```auto

1 h-level1
2 level2 (/1:*)
3 h-level21 (a3)
3 h-level22 (a3)

resize ...
move by name ...
```

Compilation and run ok but the table h-level1.level2 is empty

if i try move level1.level2 (1) to h-level1.level2 (1) =\> Error Nat0285

An idea to move level1.level2 to h-level1.level2 ?

Brgds

---

<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:** [January 20, 2016, 8:32pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/2 "2016-01-20T20:32:13Z")

</div>

This works perfectly fine

```auto
DEFINE DATA LOCAL                                  
1 LEVEL1                                           
  2 LEVEL2 (/ 1: 10)                               
    3 LEVE21 (A3)                                  
    3 LEVEL22 (A3)                                 
****                                               
1 H-LEVEL1                                         
  2 LEVEL2 (/1:*)                                  
    3 LEVEL21 (A3)                                 
    3 LEVEL22 (A3)                                 
END-DEFINE                                         
RESIZE ARRAY H-LEVEL1.LEVEL2 TO (1:10)             
*                                                  
LEVEL1.LEVEL21(1) := 'AAA'                        
LEVEL1.LEVEL22(1) := 'BBB'                        
*                                                  
MOVE BY NAME LEVEL1.LEVEL2(1) TO H-LEVEL1.LEVEL2(1)
*                                                  
WRITE LEVEL1.LEVEL21(1)                            
      LEVEL1.LEVEL22(1)                            
*                                                  
END                                                
```

---

<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:** [January 21, 2016, 1:31am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/3 "2016-01-21T01:31:10Z")

</div>

Actually, there is a typo in the original code which you have propagated.  
The corrected code is below …  
.  
DEFINE DATA  
LOCAL  
1 LEVEL1  
2 LEVEL2 (/1:10)  
3 LEVEL21 (A3) /\* I corrected typo “LEVE21” to “LEVEL21”  
3 LEVEL22 (A3)  
\*  
1 H-LEVEL1  
2 LEVEL2 (/1:\*)  
3 LEVEL21 (A3)  
3 LEVEL22 (A3)  
END-DEFINE  
\*  
RESIZE ARRAY H-LEVEL1.LEVEL2 TO (1:10)  
\*  
LEVEL1.LEVEL21(1) := ‘21A’  
LEVEL1.LEVEL21(2) := ‘21B’  
LEVEL1.LEVEL21(3) := ‘21C’  
\*  
LEVEL1.LEVEL22(1) := ‘22X’  
LEVEL1.LEVEL22(2) := ‘22Y’  
LEVEL1.LEVEL22(3) := ‘22Z’  
\*

- MOVE BY NAME LEVEL1 TO H-LEVEL1 /\* Error NAT0631
- MOVE BY NAME LEVEL1.LEVEL2(_) TO H-LEVEL1.LEVEL2(_) /\* Error NAT0631  
MOVE BY NAME LEVEL1.LEVEL2(1:10) TO H-LEVEL1.LEVEL2(1:10)
- 

DISPLAY (AD=I) LEVEL1 5X H-LEVEL1  
\*  
END

---

<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:** [January 21, 2016, 2:45am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/4 "2016-01-21T02:45:01Z")

</div>

For an X-array you likely would want the upper bound to be set dynamically, so use a variable in the RESIZE and the MOVE BY NAME.

```auto
1 #U (I4)

ASSIGN #U = 10
RESIZE ARRAY H-LEVEL1.LEVEL2 TO (1:#U)

MOVE BY NAME LEVEL1.LEVEL2 (1:#U) TO H-LEVEL1.LEVEL2 (1:#U)
```

Or you can compute the upper limit prior to the MOVE.

```auto
ASSIGN #U = *UBOUND (H-LEVEL1.LEVEL21) /* or *OCC (H-LEVEL1.LEVEL21)
MOVE BY NAME LEVEL1.LEVEL2 (1:#U) TO H-LEVEL1.LEVEL2 (1:#U)
```

---

<div class="post-metadata">

**Author:** ![Thierry\_Couairon](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/thierry_couairon/32/300_2.png) [@Thierry\_Couairon](https://techcommunity.softwareag.com/u/Thierry_Couairon)\
**Post date:** [January 21, 2016, 9:20am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/5 "2016-01-21T09:20:18Z")

</div>

Hello

Thank’s you very much at all members for your response  
Sorry but i make a mistake when i showed the example  
I have more and more fields in the structure, not just level1 and i have need to move all structure  
-1- Move by name all structure except the periodic group and multiple field  
-2- Move multiple fields (no pb for this because move a to b compil correctly)  
-3- Move periodic group

If i want compil the first move by name, i must change the group’s name and it’s no possible to make  
'move by name ’ for periodic group after

Brgds

---

<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:** [January 21, 2016, 11:22am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/6 "2016-01-21T11:22:56Z")

</div>

> [@Peter Holmick](#):
>
> Actually, there is a typo in the original code which you have propagated.

Yes, sorry, seems the C&P from the terminal emulation did not pick up the  
latest version, I had caught & corrected that, of course …

---

<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:** [January 21, 2016, 1:51pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/7 "2016-01-21T13:51:19Z")

</div>

At first, I did not understand the problem you were trying to address. Your second post clarified the problem (I think).

Suppose you have a FROM group and a TO group which are identical, and have many named fields and arrays.

What you could do (perhaps) is something like the following:

Suppose I want to move the FROM group to the TO group, except for an array #ARRAY (1:10).

You could have a small third group, say the SAVE group, which has just #ARRAY (1:10)

Do a MOVE BY NAME (or just a MOVE) of FROM.#ARRAY(1:10) to #SAVE.#ARRAY(1:10)

Now do the big MOVE BY NAME of FROM to TO.

Next, do a move of #SAVE.#ARRAY(1:10) to TO.#ARRAY (1:10)

This will clearly not be as efficient as individual moves, and, you would need separate SAVE arrays for different exclusions, but it will work, and will avoid the “messiness” of working with the large groups (possibly using separate MOVEs for each field/array).

---

<div class="post-metadata">

**Author:** ![Thierry\_Couairon](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/thierry_couairon/32/300_2.png) [@Thierry\_Couairon](https://techcommunity.softwareag.com/u/Thierry_Couairon)\
**Post date:** [January 21, 2016, 2:32pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/8 "2016-01-21T14:32:12Z")

</div>

Hello

thank’s for your response  
i try your method and report result as soon as possible

brgds

---

<div class="post-metadata">

**Author:** ![Thierry\_Couairon](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/thierry_couairon/32/300_2.png) [@Thierry\_Couairon](https://techcommunity.softwareag.com/u/Thierry_Couairon)\
**Post date:** [January 21, 2016, 2:55pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/9 "2016-01-21T14:55:43Z")

</div>

Hello

Ok but it’s no work because th perodifc group can’t move (Compil error)

To clarify the problem, i write the entire code below

```auto

DEFINE DATA                
LOCAL                      
1 £IN                      
2 £TAB01 (/1:191)          
3 £TAB02 (A4)              
3 £TAB03 (A3)              
2 £TAB11 (A5/1:191)        
2 £CH01 (A6)               
1 £OUT                     
2 £HTAB01 (/1:*)          
3 £HTAB02 (A4)             
3 £HTAB03 (A3)             
2 £HTAB11 (A5/1:*)         
2 £CH01 (A6)               
1 £SAVE                    
2 £TAB01 (/1:191)          
3 £TAB02 (A4)              
3 £TAB03(A4)               
1 £I (N3)           
END-DEFINE                 
£IN.£TAB02(1) := 'A'                                
£IN.£TAB03(1) := '1'                                
£IN.£TAB02(2) := 'B'                                
£IN.£TAB03(2) := '2'                                
£IN.£TAB02(3) := 'C'                                
£IN.£TAB03(3) := '3'                                
RESIZE ARRAY £OUT.£HTAB01 TO (1:3)                  
MOVE BY NAME £IN TO £OUT                            
MOVE BY NAME £IN.£TAB01(1:3) TO £SAVE.£TAB01(1:3)   
MOVE £SAVE.£TAB01(1:3) TO £OUT.£HTAB01(1:3)         
FOR £I := 1 TO 8                                    
  WRITE £OUT.£HTAB01(£I)                            
END-FOR                                             
* WRITE WORK FILE 1 VARIABLE £OUT                   
END                                                 
```

In fact, the X-ARRAY is the problem but i have no other solution because the real program must write a file like a “decompress” method  
field field nb occurence oc1 oc2 … ocn f3 f4 …  
with nb occurence variable

Brgds

---

<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:** [January 21, 2016, 8:33pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/10 "2016-01-21T20:33:18Z")

</div>

Here is a program adapted from the one you sent (but, I made a couple of changes)

```
DEFINE DATA                  
LOCAL                        
1 #IN                        
2 #TAB01 (1:3)            
3 #TAB02 (A4)                
3 #TAB03 (A3)                
2 #TAB11 (A5/1:3)          
2 #CH01 (A6)                 
1 #OUT                       
2 #TAB01 (1:3)            
3 #TAB02 (A4)               
3 #TAB03 (A3)               
2 #TAB11 (A5/1:3)           
2 #CH01 (A6)                 
1 #SAVE                      
2 #TAB01 (/1:191)            
3 #TAB02 (A4)                
3 #TAB03(A4)                 
1 #I (N3)    
1 #string (a60)         
END-DEFINE   

```

- #IN.#TAB02(1) := ‘A’  
#IN.#TAB03(1) := ‘1’  
#IN.#TAB02(2) := ‘B’  
#IN.#TAB03(2) := ‘2’  
#IN.#TAB02(3) := ‘C’  
#IN.#TAB03(3) := ‘3’
- MOVE BY NAME #IN TO #OUT  
COMPRESS #IN.#TAB01(1:3) inTO #STRING with delimiter ‘,’  
\*\*  
SEPARATE #STRING into #OUT.#TAB01 (1:3) with delimiter ‘,’  
FOR #I := 1 TO 3  
WRITE #OUT.#TAB01(#I)  
END-FOR  
write // ‘=’ #string  
END

Page 1 16-01-21 14:32:57

A 1  
B 2  
C 3

#STRING: A,B,C,1,2,3

The use of COMPRESS and SEPARATE may do what you require.

If the above does not solve your problem, please post a specific example and the output you require

steve

---

<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:** [January 22, 2016, 12:51am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/11 "2016-01-22T00:51:37Z")

</div>

Thierry, the solution to your re-stated problem is the MOVE BY POSITION statement (but use with care).  
.  
DEFINE DATA  
LOCAL  
1 #I (N3)  
1 #IN  
2 #TAB01 (/1:191)  
3 #TAB02 (A4)  
3 #TAB03 (A3)  
2 #TAB11 (A5/1:191)  
2 #CH01 (A6)  
1 #OUT  
2 #HTAB01 (/1:_)  
3 #HTAB02 (A4)  
3 #HTAB03 (A3)  
2 #HTAB11 (A5/1:_)  
2 #CH01 (A6)  
1 #SAVE  
2 #TAB01 (/1:191)  
3 #TAB02 (A4)  
3 #TAB03 (A3) /\* changed from (A4) to (A3)  
1 #U (N3) /\* Ralph Zbrog’s suggestion …  
END-DEFINE  
\*  
#IN.#TAB02(1) := ‘A’ ; #IN.#TAB03(1) := ‘1’  
#IN.#TAB02(2) := ‘B’ ; #IN.#TAB03(2) := ‘2’  
#IN.#TAB02(3) := ‘C’ ; #IN.#TAB03(3) := ‘3’  
#IN.#TAB11(1) := ‘QQQQQ’  
#IN.#TAB11(2) := ‘RRRRR’  
#IN.#TAB11(3) := ‘SSSSS’  
#IN.#TAB11(4) := ‘TTTTT’  
#IN.#TAB11(5) := ‘UUUUU’  
#IN.#CH01 := ‘ALPHA6’  
\*  
#U := 3 /\* Ralph Zbrog’s suggestion …  
RESIZE ARRAY #OUT.#HTAB01 TO (1:#U)  
RESIZE ARRAY #OUT.#HTAB11 TO (1:3) /\* must materialize this x-array too  
\*  
MOVE BY NAME #IN TO #OUT  
MOVE BY NAME #IN.#TAB01(1:#U) TO #SAVE.#TAB01(1:#U)

- MOVE #SAVE.#TAB01(1:#U) TO #OUT.#HTAB01(1:#U) /\* Error NAT0285 !
- #OUT.#HTAB01(1:#U) := #SAVE.#TAB01(1:#U) /\* Error NAT0623 ?  
MOVE BY POSITION #SAVE.#TAB01(1:#U) TO #OUT.#HTAB01(1:#U) /\* \<== 🙂
- 

DISPLAY (ES=ON) #IN (CD=RE) 4X #SAVE (CD=YE) 4X #OUT (CD=GR)  
\*  
/\* FOR #I = 1 TO 3 /\* changed from 8 to 3  
/\* WRITE ‘=’ #I ‘=’ #OUT.#HTAB01(#I)  
/\* END-FOR  
\*\*\* WRITE WORK FILE 1 VARIABLE #OUT  
END

---

<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:** [January 22, 2016, 12:56am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/12 "2016-01-22T00:56:21Z")

</div>

In fact, with MOVE BY POSITION you can eliminate the intermediate group called #SAVE and just do:  
MOVE BY NAME #IN TO #OUT  
MOVE BY POSITION #IN.#TAB01(1:#U) TO #OUT.#HTAB01(1:#U) /\* \<== :-()

---

<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:** [January 22, 2016, 6:42am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/13 "2016-01-22T06:42:16Z")

</div>

Writing a variable number of occurrences of an MU or PE is simple. You don’t need the CPU overhead of X-arrays nor the complexity of multiple structures (#IN & #OUT) and MOVE BY NAME/POSITION. All you need is a verbose WRITE WORK statement.

Borrowing from Peter’s example:

```auto
DEFINE DATA LOCAL
1 #IN
  2 #TAB01 (A7/1:191) 2 REDEFINE #TAB01
    3 #TAB02-A (191)
      4 #TAB02 (A4)
      4 #TAB03 (A3)
  2 #TAB11 (A5/191)
  2 #CH01 (A6)
*
1 #01 (N3)
1 #11 (N3)
1 #W (A1000)
END-DEFINE
*
#IN.#TAB02(1) := 'A' ; #IN.#TAB03(1) := '1'
#IN.#TAB02(2) := 'B' ; #IN.#TAB03(2) := '2'
#IN.#TAB02(3) := 'C' ; #IN.#TAB03(3) := '3'
#IN.#TAB11(1) := 'QQQQQ'
#IN.#TAB11(2) := 'RRRRR'
#IN.#TAB11(3) := 'SSSSS'
#IN.#TAB11(4) := 'TTTTT'
#IN.#TAB11(5) := 'UUUUU'
#IN.#CH01 := 'ALPHA6'
*
#01 := 3
#11 := 5
*
WRITE WORK 1 VARIABLE #IN.#TAB01 (1:#01)
                      #IN.#TAB11 (1:#11)
                      #IN.#CH01
WRITE WORK 1 VARIABLE #IN.#TAB02 (1:#01)
                      #IN.#TAB03 (1:#01)
                      #IN.#TAB11 (1:#11)
                      #IN.#CH01
READ WORK 1 #W
  PRINT #W
END-WORK
END
```

```auto
Page 1 01/21/16 21:20:36
 
A 1 B 2 C 3 QQQQQRRRRRSSSSSTTTTTUUUUUALPHA6
A B C 1 2 3 QQQQQRRRRRSSSSSTTTTTUUUUUALPHA6
```

The two WRITE WORK statements demonstrate the alternatives for the PE structure output.

---

<div class="post-metadata">

**Author:** ![Thierry\_Couairon](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/thierry_couairon/32/300_2.png) [@Thierry\_Couairon](https://techcommunity.softwareag.com/u/Thierry_Couairon)\
**Post date:** [January 22, 2016, 9:54am UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/14 "2016-01-22T09:54:26Z")

</div>

Hello

Thank’s you very much at all members for your response  
With them, i can finish my job 😃

Brgds

---

<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:35pm UTC](https://techcommunity.softwareag.com/t/use-group-in-array/186338/15 "2021-04-02T15:35:10Z")

</div>


