ILE COBOL Programmer's Guide


Using Pointers in a MOVE Statement

Elementary pointers cannot be moved using the MOVE statement; a SET statement must be used; however, pointers are implicitly moved when they are part of a group item.

When compiling a MOVE statement, the ILE COBOL compiler generates code to maintain (a pointer MOVE) or not maintain (a non-pointer MOVE) pointers within a group item.

A pointer MOVE is done when all of the following conditions are met:

  1. The source or receiver of a MOVE statement contains a pointer
  2. Both of the items are at least 16 bytes long
  3. The data items are properly aligned
  4. The data items are alphanumeric or group items.

Of the conditions listed above, determining if two data items are properly aligned can be the most difficult.

Note:
A pointer MOVE is slower than using the SET statement to move a pointer.

Items must be on the same offset relative to a 16-byte boundary for a pointer MOVE to occur. (A warning is issued if this is not true.)

The following example shows three data structures, and the results when a MOVE statement is issued:

Figure 81. Using Pointers in a MOVE Statement


WORKING-STORAGE SECTION.
  01  A.
      05  B      PIC X(10).
      05  C.
          10  D      PIC X(6).
          10  E      POINTER.
  01  A2.
      05  B2     PIC X(6).
      05  C2.
          10  D2     PIC X(10).
          10  E2     POINTER.
 01  A3.
     05  B3     PIC X(22).
     05  C3.
         10  D3     PIC X(10).
         10  E3     POINTER.
PROCEDURE DIVISION.
MOVE  A  to A2. (1)
MOVE  A  to A3. (1)
MOVE  C  to C2. (2)
MOVE  C2 to C3. (3)

(1)
This results in a pointer MOVE because the offset of each group item to be moved is zero. Pointer integrity is maintained.

(2)
This results in a non-pointer MOVE, because the offsets do not match. The offset of group item C is 10, and the offset of group item C2 is 6. Pointer integrity is not maintained.

(3)
This results in a pointer MOVE, because the offset of group item C2 is 6, and the offset of C3 relative to a 16-byte boundary is also 6. (When the offset is greater than 16, the offset relative to a 16-byte boundary is calculated by dividing the offset by 16. The remainder is the relative offset. In this case, the offset was 22, which, when divided by 16, leaves a remainder, or relative offset, of 6.) Pointer integrity is maintained.

If a group item contains a pointer, and the ILE COBOL compiler cannot determine the offset relative to a 16-byte boundary, the ILE COBOL compiler issues a warning message, and the pointer move is attempted. However, pointer integrity may not be maintained. The ILE COBOL compiler cannot determine the offset if the item is defined in the Linkage Section, or if the item is reference-modified with an unknown starting position. You must ensure that pointer alignment is maintained, or a machine check error may result.

The ILE COBOL compiler places all 01-level and 77-level items on a 16-byte boundary whether or not they contain pointers.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]