|
6.2 MOVE
The format is:
|
MOVE [literal-1 or identifier-1] TO [identifier-2] ...
|
The MOVE statement has already been extensively used in the examples in the Defining Data section. A couple of features have not
been described yet: CORRESPONDING (abreviation CORR) and the qualification OF or IN.
The elipsis (...) means more of the same, i.e. above [identifier-2] [identifier-3] [identifier-4]...and so on.
To move a group of items from one field description to another:
03 DATE-IN.
05 W-DAY PIC 99.
05 W-MONTH PIC 99.
05 W-YEAR PIC 99.
:
03 DATE-OUT.
05 W-DAY PIC 99.
05 PIC X VALUE '/'.
05 W-MONTH PIC 99.
05 PIC X VALUE '/'.
05 W-YEAR PIC 99.
If you were to code: MOVE DATE-IN TO DATE-OUT you would end up with the 6 characters of
DATE-IN appearing in the first 6 positions of DATE-OUT, including over-written fillers. To get the contents of
W-DAY of DATE-IN into W-DAY of DATE-OUT (and the same for the other two items) you could either move them individually,
or you could simply code: MOVE CORRESPONDING DATE-IN TO DATE-OUT. To do this the items must have the same name spelling
and must be of the same level (here they are both level 03). They don't have to be in the same level 01 group.
Of course, this does present the programmer with a potential problem, this being that if elsewhere in the program you were to code, say,
ADD 12 to W-MONTH, the compiler would report a syntax error since it W-MONTH appears twice in the data division and doesn't know
which one you mean. To remedy this, you have to qualify the item, i.e. state which group W-MONTH you mean, i.e. :
MOVE 12 TO W-MONTH IN DATE-OUT.
You could use the word OF instead of IN here to the same effect.
Reference modification
To access specific characters within a string you can use a reference modifier.
STRING-ITEM (startPosition:Length)
The start position is the nth character of the STRING-ITEM.
For MicroFocus compilers at least, the length can be omitted if you want all characters to the end of the string.
e.g.
WORKING-STORAGE SECTION.
01 STRING-1 PIC X(10) VALUE 'ABCDEFGHIJ'.
01 STRING-2 PIC X(10) VALUE SPACES.
01 STRING-3 PIC X(10) VALUE SPACES.
01 STRING-4 PIC X(10) VALUE SPACES.
01 STRING-5 PIC X(10) VALUE SPACES.
01 STRING-6 PIC X(10) VALUE SPACES.
:
:
in procedure division:
MOVE STRING-1(2:6) TO STRING-2
MOVE STRING-1(1:9) TO STRING-3
MOVE STRING-1(6) TO STRING-4
MOVE STRING-1(5:1) TO STRING-5
MOVE STRING-1(3:3) TO STRING-6
Then:
STRING-2 will contain characters 2 to 6, i.e. : "BCDEFG "
STRING-3 will contain characters 1 to 9, i.e. : "ABCDEFGHI "
STRING-4 will contain characters 6 to the end of STRING-1, i.e. : "FGHIJ "
STRING-5 will contain character 5 only, i.e. : "E "
STRING-6 will contain characters 3 to 5, i.e. : "CDE "
|