MOVE

Syntax

         ┌◄────────────────────────────────────────────┐
── MOVE ─┴─┬─/1*\─<sequence range list>──────────────┬─┴───────────────┤
           └─/1*\─ TO ─┬─<base>─┬─┬──────────────────┤
                       ├─ NEXT ─┤ └─ + ──<increment>─┘
                       └─ END ──┘

Explanation

The MOVE command moves lines from one place to another within the work file. The lines are moved as a contiguous block and are assigned new sequence numbers.

Lines are moved, not copied; therefore, lines in the sequence range list no longer retain their old sequence numbers. However, the existing contents of the MARKID field of the moved lines remain. Refer to the MARKID command in this section for more information about the MARKID field.

To copy lines in the work file, use the INSERT command.

The UPDATE command, which applies all changes, additions, and deletions to the work file, is implicitly invoked after the MOVE command has been executed.

Sequence Range List

The sequence range list construct specifies the sequence range or ranges of the lines to be moved within the work file.

Assigning an Initial Value for the Sequence Range List

The new sequence numbers of moved lines are determined by assigning an initial value to the first line and incrementing that value for each succeeding line. The initial value is specified in one of three ways:

  • The base option specifies the value explicitly. The base value must be an integer.

  • The NEXT option sets the initial value to the next sequence number that would have resulted from the most recent MOVE, INSERT, RESEQ, or SEQ command. A default value of 100 is used if no such command has appeared since the last MAKE, GET, or DELETE ALL command.

  • The END option sets the initial value to the largest sequence number currently in the file, plus the currently specified (or default) increment.

Increment Option

The increment construct defines the increment value to use for successive sequence numbers in the block. The increment value must be an integer. If no increment value is specified, the increment value from the most recent MOVE, INSERT, RESEQ, or SEQ command is used. 100 is used if none of these commands have been used since the last MAKE, GET, or DELETE ALL command.

When the MOVE Command is Not Performed

The range of new sequence numbers cannot overlap any lines already in the file, nor can the numbers exceed the largest sequence number that can be expressed in the sequence number field. If either of these conditions occurs, an error message will be displayed and the move will not be done.

Examples

The following example demonstrates how to move four records in the TESTONLY file. The records with sequence number 1000 through 1300 are reassigned sequence numbers with the first moved record assigned the base sequence number 10 and subsequent records incremented by 1.

GET TESTONLY;LIST
#WORKFILE TESTONLY: SEQ, 15 RECORDS, SAVED
100 LINE 1
200 LINE 2
300 LINE 3
400 LINE 4
500 LINE 5
600 LINE 6
700 LINE 7
800 LINE 8
900 LINE 9
1000 LINE 10
1100 LINE 11
1200 LINE 12
1300 LINE 13
1400 LINE 14
1500 LINE 15
#
MOVE 1000-1300 TO 10+1
#UPDATING
#
L
10 LINE 10
11 LINE 11
12 LINE 12
13 LINE 13
100 LINE 1
200 LINE 2
300 LINE 3
400 LINE 4
500 LINE 5
600 LINE 6
700 LINE 7
800 LINE 8
900 LINE 9
1400 LINE 14
1500 LINE 15
# 

The following example shows the result of the MOVE command's NEXT option performed after the previous example. Records 1400 and 1500 are assigned sequence numbers from where the most recent MOVE operation left off.

MOVE 1400,1500 TO NEXT
#UPDATING
#
L
10 LINE 10
11 LINE 11
12 LINE 12
13 LINE 13
14 LINE 14
15 LINE 15
100 LINE 1
200 LINE 2
300 LINE 3
400 LINE 4
500 LINE 5
600 LINE 6
700 LINE 7
800 LINE 8
900 LINE 9
#

The following example shows the result of the MOVE command's END option performed after the previous two examples. Records 100 through 400 are moved to the end of the file and assigned sequence numbers with the sequence number of the last record as a base and incrementing by 1 from where the most recent MOVE operation left off.

MOVE 1400,1500 TO NEXT
#UPDATING
#

L
10 LINE 10
11 LINE 11
12 LINE 12
13 LINE 13
14 LINE 14
15 LINE 15
500 LINE 5
600 LINE 6
700 LINE 7
800 LINE 8
900 LINE 9
901 LINE 1
902 LINE 2
903 LINE 3
904 LINE 4
#