Microsoft KB Archive/47755

MOVE CORRESPONDING with Variables of the Same Name

PSS ID Number: Q47755 Article last modified on 08-11-1989

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: In COBOL, it is possible to have data names duplicated in the WORKING-STORAGE SECTION. The purpose of using duplicate data names is for defining records for files that contain some or all of the same data in one program. You can transfer data from one record to another using the MOVE CORRESPONDING statement. The MOVE CORRESPONDING statement moves only the data items whose names and PICTURE clauses are identical (in both identifier-1 and identifier-2) from identifier-1 to identifier-2. The MOVE CORRESPONDING statement aligns in identifier-2 only the data items from identifier-1 that have the same names and picture clauses. All data names that are unique to identifier-1 or identifier-2 are left untouched. This information applies to Microsoft COBOL Compiler Versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: The MOVE CORRESPONDING syntax is as follows: MOVE CORRESPONDING unique-var1 TO unique-var2. To reference the duplicated names in the PROCEDURE DIVISION, the names must be qualified. For example: DISPLAY redundant-1 OF unique-var1. There are some restrictions on duplicated data names: 1. Duplicated data names must not appear as level 01, 77, or 88 items. For example, the following DATA-DIVISION entries are correct: 01 unique-var1. 05 redundant-1 pic xxx. 05 redundant-2 pic 99. 01 unique-var2. 05 filler pic x(2). 05 redundant-1 pic xxx. 05 filler pic x(5). 05 redundant-2 pic 99. 2. Two identical data names cannot appear as subordinate items to a group item unless they can be made to appear unique though qualification, such as having a unique subdivided group item. For example, the following DATA DIVISION entry is correct: 01 unique-var3. 05 filler pic x(5). 05 unique-var4. 10 redundant-1 pic xxx. 05 unique-var5. 10 redundant-1 pic xxx. 10 redundant-2 pic 99.

Code Example
The following is a full code example for the above situations: WORKING-STORAGE SECTION. 01 unique-var3. 05 filler pic x(5). 05 unique-var4. 10 redundant-1 pic xxx. 05 unique-var5. 10 redundant-1 pic xxx. 10 redundant-2 pic 99. 01 unique-var1. 05 redundant-1 pic xxx. 05 redundant-2 pic 99. 01 unique-var2. 05 filler pic x(2). 05 redundant-1 pic xxx. 05 filler pic x(5). 05 redundant-2 pic 99. PROCEDURE DIVISION. MOVE CORRESPONDING unique-var1 TO unique-var5. MOVE CORRESPONDING unique-var1 TO unique-var4. MOVE CORRESPONDING unique-var2 TO unique-var1. MOVE CORRESPONDING unique-var2 TO unique-var5. DISPLAY redundant-1 OF unique-var5. MOVE “ABC” TO redundant-1 OF unique-var4. STOP RUN.

Copyright Microsoft Corporation 1989.