use group in array

hello

I have this code


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


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

This works perfectly fine

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                                                
1 Like

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

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.

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.

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

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

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

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).

Hello

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

brgds

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


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

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

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) /* <== :slight_smile:

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

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) /* <== :-()

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:

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

Hello

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

Brgds