Moving first few variables from structure 1 to structure 2

Hi,

I have structures as below

01 STRUCTURE-01
02 ST1-VAR1 (N5)
02 ST1-VAR2 (A5)
02 ST1-VAR3 (P5)
02 ST1-VAR4 (N3.2)
02 ST1-VAR5 (P5.3)

01 STRUCTURE-02
02 ST2-VAR1 (N5)
02 ST2-VAR2 (A5)
02 ST2-VAR3 (P5)
02 ST2-VAR4 (N3.2)
02 ST2-VAR5 (P5.3)

Here, if I use MOVE BY POSITION, it will move the whole structure 1 to structure 2.
I do not want to keep the identical varialbles in both the structure and use MOVE BY NAME.

How can I make a move of only first 3 variables from structure 1 to first 3 variables in structure 2?

Regards,
Mishra

Change the names of VAR4 and VAR5 in one of the structures and use MOVE BY NAME

Just add some structure, as below:

DEFINE DATA LOCAL
01 STRUCTURE-01
02 ST1-FIRST-THREE
03 ST1-VAR1 (N5) INIT <12345>
03 ST1-VAR2 (A5) INIT <‘ABCDE’>
03 ST1-VAR3 (P5) INIT <67890>
02 ST1-VAR4 (N3.2) INIT <123.45>
02 ST1-VAR5 (P5.3) INIT <12345.678>
*
01 STRUCTURE-02
02 ST2-FIRST-THREE
03 ST2-VAR1 (N5)
03 ST2-VAR2 (A5)
03 ST2-VAR3 (P5)
02 ST2-VAR4 (N3.2)
02 ST2-VAR5 (P5.3)
END-DEFINE
*
MOVE BY POSITION ST1-FIRST-THREE
TO ST2-FIRST-THREE
WRITE STRUCTURE-01 // STRUCTURE-02
END

Page 1 02/18/12 06:12:09

12345 ABCDE 67890 123.45 12345.678

12345 ABCDE 67890 0.00 0.000

Steve, just curious, did you ever compare the performance of MOVE BY NAME vs MOVE BY POSITION ?

This inquiring mind, etc. :wink:

Thanks - Wolfgang

Thank you Wolfgang and Steve for your kind response.

Hi Wolfgang;

"Steve, just curious, did you ever compare the performance of MOVE BY NAME vs MOVE BY POSITION ?

I will have to dig it out. Probably re-run the code too, since it would be at least one (and possibly two) Natural versions ago.

HOWEVER, one point I should have made in my earlier response.

I really am annoyed when I see a MOVE BY NAME being used improperly (from a performance viewpoint).

I often see two Groups with identical fields (over twenty in one case I saw). There were two MOVE BY NAME’s for the Groups.

Instead, I had the programmer REDEFINE the Group as a single alpha field, then do a simple MOVE of the single field from within one Group to the other Group. The performance difference was quite astounding; okay, not really astounding since Natural was doing one move operation rather than twenty plus moves. I will post such a comparison later today.

To be fair, you would have to synchronize any changes to the two Groups. A miniscule price to pay (a tiny edit chore versus lots of extra MOVE’s every time the code was executed).

In Mishra’s case, instead of ST1-FIRST-THREE and ST2-FIRST-THREE being Groups, they could each be fields formatted as A13.

steve

Here is a comparison (on a PC, will report on mainframe later) between MOVE BY NAME and a MOVE between Fields that comprise entire Groups.

  • THIS PROGRAM COMPARES THE TIME TO DO TEN INDIVIDUAL
  • MOVES VIA THE MOVE BY NAME AND A SINGLE MOVE.
  • TIMINGS MAY DIFFER ON DIFFERENT PLATFORMS.
  • ON MY MACHINE, MOVE BY NAME TAKES ABOUT TEN TIMES AS LONG.
  • PLEASE REMEMBER, FOR A MEANINGFUL COMPARISON, YOU
  • MUST SUBTRACT OUT THE “FOR LOOP ONLY” TIME
  • FROM THE OTHER TWO TIMES.

DEFINE DATA LOCAL
1 FROM-GROUP
2 #BIG-FIELD (A10)
2 REDEFINE #BIG-FIELD
3 #1 (A1)
3 #2 (A1)
3 #3 (A1)
3 #4 (A1)
3 #5 (A1)
3 #6 (A1)
3 #7 (A1)
3 #8 (A1)
3 #9 (A1)
3 #0 (A1)
1 TO-GROUP
2 #BIG-FIELD (A10)
2 REDEFINE #BIG-FIELD
3 #1 (A1)
3 #2 (A1)
3 #3 (A1)
3 #4 (A1)
3 #5 (A1)
3 #6 (A1)
3 #7 (A1)
3 #8 (A1)
3 #9 (A1)
3 #0 (A1)
1 #LOOP (P9)
1 #START-CPU (I4)
1 #RUNNING-CPU (I4)
1 #ELAPSED-CPU (I4)
END-DEFINE
*
MOVE *CPU-TIME TO #START-CPU
SETA. SETTIME
FOR #LOOP = 1 TO 900000
MOVE BY NAME FROM-GROUP TO TO-GROUP
END-FOR
COMPUTE #ELAPSED-CPU = *CPU-TIME - #START-CPU
WRITE 5T 'MOVE BY NAME TIME: ’ *TIMD (SETA.) #ELAPSED-CPU
*
MOVE *CPU-TIME TO #START-CPU
SETB. SETTIME
FOR #LOOP = 1 TO 900000
MOVE FROM-GROUP.#BIG-FIELD TO TO-GROUP.#BIG-FIELD
END-FOR
COMPUTE #ELAPSED-CPU = *CPU-TIME - #START-CPU
WRITE // 5T 'MOVE TIME: ’ *TIMD (SETB.) #ELAPSED-CPU
*
MOVE *CPU-TIME TO #START-CPU
SETC. SETTIME
FOR #LOOP = 1 TO 900000
IGNORE
END-FOR
COMPUTE #ELAPSED-CPU = *CPU-TIME - #START-CPU
WRITE // 5T 'FOR LOOP ONLY: ’ *TIMD (SETC.) #ELAPSED-CPU
END

PAGE #   1                    DATE:    02/19/12
PROGRAM: MOVNM04X             LIBRARY: BOST-PER

MOVE BY NAME TIME:        30         301


MOVE TIME:        13         129


FOR LOOP ONLY:        12         116

I tend to use CPU time as a better indicator of performance than elapsed time (although on my PC, they are pretty much in lockstep).

After subtracting out the FOR loop CPU time, the single MOVE CPU time is 13, whereas the MOVE BY NAME CPU time is 185, which is a ratio of about fifteen to one. NOTE, this is only ten fields in the group. Performance should be somewhat linear with the number of fields.

Are there things I can do with MOVE BY NAME that I cannot do with a REDEFINE? Of course. However, when the two Groups are identical (same field names, same formats), I NEVER use the MOVE BY NAME.

steve

Thanks Steve :wink:

I didn’t suggest a REDEFINE just because it’s so easy to break things,
but looking at the numbers it’s hard NOT to consider it …

For completeness’ sake I’ve added MOVE BY POSITION (this is on a PC as well) and ran the whole suite

MOVE BY NAME TIME: 22 217

MOVE BY POSITION TIME: 14 138

MOVE TIME: 9 89

FOR LOOP ONLY: 8 77

To complete the picture here the results from mainframe Natural

with NOC=OFF

MOVE BY NAME TIME:        16         157    
                                            
MOVE BY POSITION TIME:        11         110
                                            
MOVE TIME:         8          73
                                            
FOR LOOP ONLY:         5          54        

With NOC=ON I had to change the FOR loop from 900.000 to 9.000.000 iterations,
otherwise it was just too quick and not really meaningful !

MOVE BY NAME TIME:        14          88    
                                            
MOVE BY POSITION TIME:         9          66
                                            
MOVE TIME:        10          64            
                                            
FOR LOOP ONLY:         9          64        

Interesting! Here are the numbers for Nat63@Solaris:


    MOVE BY NAME TIME:        46         462


    MOVE TIME:        21         206


    FOR LOOP ONLY:        19         188