Natural reporting mode - Move indexed

While working on a very old Natural program, I came across a cryptic reporting mode statement : Move indexed.

I tried to het the Natural documentation for the same, but was not successful. Please can some one help me understand what Move indexed statement does and what are the syntax variations?

Redirection to any NATURAL documentation will also be ok.

The oldest documentation we got here is Nat 6.1 for Open Systems. It only says that MOVE INDEXED is deprecated - but doesn’t say anything how it works (so you could replace it) :frowning:

So it seems that you have to find a much older documentation of Natural…

Okay, here come the programs:

MOVEXD01

  • Prior to version 2, Natural did not have array capability.
  • The MOVE INDEXED command allowed the “simulation” of
  • arrays.In this program a simple one dimensional array
  • is simulated.
  • ** IMPORTANT ** MOVE INDEXED IS NOT VALID IN STRUCTURED MODE

DEFINE DATA LOCAL
1 #ARRAY (A10) INIT <1234567890>’ #ARRAY
END

MOVEXD02

  • NOW FOR A TWO DIMENSIONAL EXAMPLE. I WISH TO “SIMULATE”
  • AN ARRAY THAT IS 12 BY 5. (EG. FIVE YEARS WORTH OF MONTHLY DATA
  • WE SHALL START WITH AN ARRAY OF ALPHA 60, WHICH ONCE AGAIN HAS
  • THE FIRST CHARACTER RENAMED. WE SHALL THEN COMPUTE AN OFFSET
  • TO THE ARRAY BY ADDING THE MONTH TO TWELVE TIMES ONE LESS THAN
  • THE YEAR. (IN A SENSE, WE ARE TREATING THE 5 BY 12 ARRAY AS A
  • SINGLE DIMENSIONED ARRAY WITH SIXTY ENTRIES)
  • FOR OUR PURPOSES, I WILL CHANGE THE ENTRY FOR YEAR THREE, MONTH EIGHT

DEFINE DATA LOCAL
1 #ARRAY (A60)
1 REDEFINE #ARRAY
2 #FIRST (A1)
1 #OFFSET (P3)
END-DEFINE
*
INCLUDE AATITLER
*

  • FIRST, I SHALL INITIALIZE #ARRAY TO A RECOGNIZABLE STRING

MOVE ALL ‘1234567890AB’ TO #ARRAY
*

  • NOW WE COMPUTE OUR OFFSET
    #OFFSET = 8 + ( 3 - 1 ) * 12
  • MYNUMBER{ OF MONTHS
  • NOW FOR THE MOVE INDEXED ITSELF

MOVE INDEXED ‘*’ TO #FIRST
*
WRITE 5/10 ‘THE RESULT OF THE MOVE INDEXED IS SHOWN BELOW’ // #ARRAY
END

MOVEXD03

  • THIS PROGRAM SHOWS A MOVE INDEXED COMMAND WITH THE
  • OFFSET ON THE “SENDING” FIELD.

DEFINE DATA LOCAL
1 #STRING (A10) INIT <‘ABCDEFGHIJ’>
1 REDEFINE #STRING
2 #FIRST (A1)
1 #HOLD (A1)
END-DEFINE
*
INCLUDE AATITLER
*
MOVE INDEXED #FIRST <4> TO #HOLD
WRITE 3/10 ‘=’ #STRING
/ 10T ‘=’ #HOLD
// 10T ‘NOTE THE “D” IN #HOLD
/ 10T ‘“D” IS IN THE FOURTH POSITION OF #STRING
/ 10T ‘AND WE DID: MOVE INDEXED #FIRST <4> TO #HOLD
END

MOVEXD04

  • THIS PROGRAM SHOWS A MOVE INDEXED COMMAND WITH OFFSETS
  • ON BOTH THE “SENDING” AND “TARGET” FIELDS.
  • THIS TYPE OF LOGIC CAN OFTEN BE FOUND IN CODE THAT IS
  • MOVING OCCURRENCES IN A MULTIPLE VALUED FIELD
  • OR A PERIODIC GROUP.
  • SUCH CODE SHOULD NOW BE REPLACED WITH
  • VIEWS AND “ARRAY MOVES”.

DEFINE DATA LOCAL
1 #STRING1 (A10) INIT <‘ABCDEFGHIJ’>
1 REDEFINE #STRING1
2 #FIRST1 (A1)
1 #STRING2 (A10) INIT <‘**********’>
1 REDEFINE #STRING2
2 #FIRST2 (A1)
END-DEFINE
*
INCLUDE AATITLER
*
WRITE 3/10 ‘HERE IS #STRING1 BEFORE THE COMMAND:’ #STRING1
/ 10T ‘HERE IS #STRING2 BEFORE THE COMMAND:’ #STRING2


MOVE INDEXED #FIRST1 <4> TO #FIRST2 <6>


WRITE // 10T ‘AFTER THE COMMAND: MOVE INDEXED #FIRST1 <4> TO #FIRST2 <6>’
/ 10T ‘(NOTE #FIRST1 IS THE FIRST BYTE OF #STRING1)’
/ 10T ‘(AND #FIRST2 IS THE FIRST BYTE OF #STRING2)’
// 10T ‘=’ #STRING1
/ 10T ‘=’ #STRING2
// 10T ‘NOTE THE “D” IN THE ASTERISK STRING’
/ 10T ‘IN THE SIXTH POSITION’
END

MOVEXD05

  • THIS PROGRAM SHOWS A MOVE INDEXED COMMAND THAT CREATES
  • A “PSEUDO-ARRAY” OF FIVE BYTE ENTRIES.

DEFINE DATA LOCAL
1 #STRING (A50)
1 REDEFINE #STRING
2 #FIRST-FIVE (A5)
END-DEFINE
*
INCLUDE AATITLER
*

  • THE FOLLOWING COMMAND MERELY “INITIALIZES” #STRING

MOVE ALL ‘12345’ TO #STRING
WRITE 3/5 ‘BEFORE THE MOVE INDEXED, #STRING IS:’
/ 5T #STRING
*

  • THE FOLLOWING COMMAND MOVES ASTERISKS TO THE
  • FOURTH “BUCKET” OF FIVE BYTES.

MOVE INDEXED ‘*****’ TO #FIRST-FIVE <4>


WRITE // 5T ‘AFTER THE COMMAND: MOVE INDEXED “*****” TO #FIRST-FIVE <4>’
/ 5T ‘(WHERE #FIRST-FIVE IS THE FIRST FIVE BYTES OF #STRING
// 5T ‘#STRING IS NOW:’
/ 5T #STRING
// 5T ‘NOTE THE ASTERISKS IN THE 4TH “BUCKET” OF FIVE’
END

MOVEXD06

  • This program shows some common MOVE INDEXED code.
  • NOTE: with today’s arrays, the three commands consisting
  •   of two MOVE INDEXEDs and one ADD would be replaced
    
  •   by a single ADD such as ADD 12 to #ARRAY (3)
    

DEFINE DATA LOCAL
1 #NUMERIC (N20) INIT <12345678901234567890>
1 REDEFINE #NUMERIC
2 #FIRST-TWO (N2)
1 #HOLD (N2)
END-DEFINE
*
INCLUDE AATITLER
*
WRITE // 3T ‘BEFORE ADDITION TO THE THIRD “BUCKET”’
/ 3T ‘-------------------------------------’
// 3T ‘=’ #NUMERIC
*
MOVE INDEXED #FIRST-TWO <3> TO #HOLD
ADD 12 TO #HOLD
MOVE INDEXED #HOLD TO #FIRST-TWO <3>
*
WRITE // 3T ‘AFTER ADDITION TO THE THIRD “BUCKET”’
/ 3T ‘------------------------------------’
// 3T ‘=’ #NUMERIC
*
END

MOVEXD07

  • This program shows what is probably a “bug”.
  • I have REDEFINEd #STRING, but have done a MOVE INDEXED
  • into #NEXT-STRING.
  • This is not always a bug. This was a standard technique for
  • creating an array greater than 253 in total length.
  • (see MOVEXD08).

DEFINE DATA LOCAL
1 #STRING (A10) INIT <‘1234567890’>
1 REDEFINE #STRING
2 #FIRST (A1)
1 #NEXT-STRING (A5) INIT <‘12345’>
END-DEFINE
*
INCLUDE AATITLER
*
WRITE 3/10 ‘BEFORE MOVE INDEXED’
/ 10T ‘-------------------’
// 10T ‘=’ #STRING // 10T ‘=’ #NEXT-STRING
*
MOVE INDEXED ‘*’ TO #FIRST <13>
*
WRITE 3/10 ‘AFTER MOVE INDEXED’
/ 10T ‘------------------’
// 10T ‘=’ #STRING // 10T ‘=’ #NEXT-STRING
*
END

MOVEXD08

  • This program shows a common technique for creating large
  • pseudo-arrays in Natural.

DEFINE DATA LOCAL
1 #STRING-1 (A250)
1 REDEFINE #STRING-1
2 #FIRST-TEN (A10)
1 #STRING-2 (A250)
1 #HOLD (A10)
END-DEFINE
*
INCLUDE AATITLER
*
MOVE INDEXED ‘QWERTYUIOP’ TO #FIRST-TEN <30>
MOVE INDEXED #FIRST-TEN <30> TO #HOLD
*

  • Note that #FIRST-TEN <30> is actually within #STRING-2,
  • not #STRING-1. Basically I am simulating an array
  • of A10/1:50.

WRITE 3/10 ‘AFTER “INITIALIZING” MOVE INDEXED’
/ 10T ‘---------------------------------’
// 10T ‘=’ #HOLD
*
MOVE INDEXED ‘**********’ TO #FIRST-TEN <30>
MOVE INDEXED #FIRST-TEN <30> TO #HOLD
*
WRITE 3/10 ‘AFTER “SECOND” MOVE INDEXED’
/ 10T ‘---------------------------’
// 10T ‘=’ #HOLD
*
END

MOVEXD09

  • THIS PROGRAM SHOWS A COMMON USE OF MOVE INDEXED IN
  • CONJUNCTION WITH A MULTIPLE VALUED FIELD. IT ALSO
  • SHOWS THE USE OF AN IMPLICIT OFFSET.

RESET #LOOP (P3) #COUNT (P3) #FLAG (L) #HOLD (A3)
INCLUDE AATITLER
*
READ (30) EMPLOYEES
OBTAIN LANG (1:3)
RESET #FLAG
MOVE C*LANG TO #COUNT
IF #COUNT GT 3
#COUNT = 3


FOR #LOOP = 1 TO #COUNT


MOVE INDEXED LANG (1) <LOOP> TO #HOLD

IF #HOLD = 'ENG'
   DO
   #FLAG = TRUE
   ESCAPE BOTTOM
   DOEND

LOOP /* CLOSES FOR LOOP
IF #FLAG = TRUE
PRINT FIRST-NAME NAME ‘SPEAKS ENGLISH’ /
ELSE
PRINT FIRST-NAME NAME ‘DOES NOT SPEAK ENGLISH’ /
LOOP /* CLOSES READ LOOP
END

steve

It looks like the text did not post, just the programs.

Aha, the text was too long. I will post it as an attachment
move indexed.txt (9.91 KB)

Sorry, the first program did not post completely; here it is

MOVEXD01

  • Prior to version 2, Natural did not have array capability.
  • The MOVE INDEXED command allowed the “simulation” of
  • arrays.In this program a simple one dimensional array
  • is simulated.
  • ** IMPORTANT ** MOVE INDEXED IS NOT VALID IN STRUCTURED MODE

DEFINE DATA LOCAL
1 #ARRAY (A10) INIT <1234567890>’ #ARRAY
1 REDEFINE #ARRAY
2 #FIRST (A1)
END-DEFINE
*
INCLUDE AATITLER
*

  • AS YOU CAN SEE, #ARRAY IS NOT AN ARRAY, MERELY A TEN BYTE ALPHA
  • FIELD, WHOSE FIRST BYTE IS ALSO KNOWN AS #FIRST.
  • THE FOLLOWING COMMAND WILL MOVE AN ASTERISK INTO THE FIFTH
  • BYTE OF #ARRAY WITHOUT DISTURBING THE REST OF THE FIELD

MOVE INDEXED ‘*’ TO #FIRST <5>
*

  • NOTE THAT WE ARE MOVING TO #FIRST, NOT #ARRAY, WITH THE APPROPRIATE
  • OFFSET. UNLIKE ARRAYS, NATURAL DOES NOT DO EXTENSIVE ERROR CHECKING
  • WITH MOVE INDEXED. YOU MAY, INADVERTANTLY, DESTROY YOUR OWN DATA
  • OR YOUR OWN PROGRAM;…BE CAREFUL…

WRITE 5/10 ‘HERE IS THE RESULT OF THE MOVE INDEXED==>’ #ARRAY
END

Yes Steve,

I could remember that I read it in your one of the Inside Natural articles, version 10 or 16 probably. Helps a lot to understand.

Hi Steve,

This is probably the best explanantion of Move Indexed i have come across. Beautifully put.

Thanks :slight_smile: