MOVE Format 2 – MOVE CORRESPONDING

6.28.2. MOVE Format 2 – MOVE CORRESPONDING

Figure 6-70 - MOVE CORRESPONDING Syntax This statement moves similarly-named elementary

MOVE CORRESPONDING identifier-1 TO identifier-2 ...

items from one group item to another.

1. The word CORRESPONDING may be abbreviated as CORR.

2. Both identifier-1 and identifier-2 must be group items.

3. Two data items subordinate to identifier-1 and identifier-2 are said to correspond if they meet the following conditions:

a. They both have the same name, but that name is not FILLER

b. If they are not immediately subordinate to identifier-1 and identifier-2, then the items they ARE subordinate to have the same name, but that name is not FILLER; if those items, in turn, are not identifier-1 and identifier-

2, then this rule continues to apply recursively upward through the structure of identifier-1 and identifier-2

c. They are both elementary items (ADD CORR,SUBTRACT CORR) or at least one of them is an elementary item (MOVE CORR)

d. Neither potential corresponding candidate is a REDEFINES or RENAMES of another data item

e. Neither potential corresponding candidate has an OCCURS clause (they MAY, however, contain subordinate data items that contain an OCCURS clause)

4. When corresponding matches are established, the effect of a MOVE CORRESPONDING on those matches will be

as if a series of individual MOVEs were done – one for each match.

The previous rules may be best understood with an example. Observe the following code: IDENTIFICATION DIVISION.

PROGRAM-ID. corrdemo. DATA DIVISION. WORKING-STORAGE SECTION.

01 X. 05 A VALUE 'A' PIC X(1). 05 G1.

10 G2.

15 B VALUE 'B' PIC X(1).

05 C. 10 FILLER VALUE 'C' PIC X(1). 05 G3. 10 G4.

15 D VALUE 'D' PIC X(1). 05 V1 VALUE 'E' PIC X(1). 05 E REDEFINES V1 PIC X(1). 05 F VALUE 'F' PIC X(1). 05 G VALUE ALL 'G'.

10 G2 OCCURS 4 TIMES PIC X(1). 05 H VALUE ALL 'H' PIC X(4). 01 Y. 02 A PIC X(1). 02 G1.

03 G2.

04 B PIC X(1). 02 C PIC X(1). 02 G3.

03 G5.

04 D PIC X(1). 02 E PIC X(1). 02 V2 PIC X(1). 02 G PIC X(4). 02 H OCCURS 4 TIMES PIC X(1). 66 F RENAMES V2.

PROCEDURE DIVISION. 100-Main.

MOVE ALL '-' TO Y. DISPLAY ' Names: ' 'ABCDEFGGGGHHHH'. DISPLAY 'Before: ' Y. MOVE CORR X TO Y. DISPLAY ' After: ' Y. STOP RUN.

The DISPLAY statements produce the output: Names: ABCDEFGGGGHHHH Before: -------------- After: ABC---GGGG---- OpenCOBOL had no problem establishing a “corresponding” relationship between the “A”, “B” and “C” data

items within the “X” and “Y” group items. Note that even though “X” uses a level numbering scheme of 01- 05-10- 15 while “Y” uses 01-02-03-04, that fact makes no difference to the establishment of corresponding matches.

The “G” items were found to match even though G OF X was the parent of a data item that contains an

OCCURS clause No match could be made with the “D” items because they violate rule #3b (look carefully at the four group

item names). No match could be made with the “E” items because E OF X violates rule #3d (REDEFINES).

No match could be made with the “F” items because E OF X violates rule #3d (RENAMES). No match could be made with the “H” items because H OF Y contains an OCCURS clause, therefore violating

rule #3e.