ILE COBOL Programmer's Guide


Pointer Alignment

Pointers can be defined at any level (except 88) in the File, Working-Storage, or Linkage sections of a program.

When a pointer is referenced on the iSeries server, it must be on a 16-byte storage boundary. Pointer alignment refers to the ILE COBOL compiler's process of positioning pointer items within a group item to offsets that are multiples of 16 bytes from the beginning of the record. If a pointer item is not on a 16-byte boundary, a pointer alignment exception is sent to the ILE COBOL program. In general, pointer alignment exceptions occur in the Linkage Section, where it is up to the user to align these items.

In the File and Working-Storage sections, the compiler ensures that this exception does not occur by adding implicit FILLER items. Every time an implicit FILLER item is added by the compiler, a warning is issued. In the Linkage Section, no implicit FILLER items are added by the compiler; however, warnings are issued indicating how many bytes of FILLER would have been added had the group item appeared in the File or Working-Storage sections.

You can define a data item as a pointer by specifying the USAGE IS POINTER clause or the USAGE IS PROCEDURE-POINTER clause as shown in the following example:

 ID DIVISION.
 PROGRAM-ID. PROGA.
 WORKING-STORAGE SECTION.
  77  APTR USAGE POINTER.
  77  APROC-PTR USAGE PROCEDURE-POINTER.
  01  AB.
      05 BPTR  USAGE POINTER.
      05 BVAR  PIC S9(3) PACKED-DECIMAL.
 LINKAGE SECTION.
 01  AVAR.
     05 CVAR  PIC X(30).
 PROCEDURE DIVISION.
      SET APTR TO ADDRESS OF AVAR.
      SET APROC-PTR TO ENTRY "PROGA".

In the above example, AVAR is an 01-level data item, so the ADDRESS OF AVAR is the ADDRESS OF special register. Because a special register is an actual storage area, the SET statement moves the contents of ADDRESS OF AVAR into pointer data item APTR.

In the above example, if the SET statement used ADDRESS OF CVAR, no special register exists. Instead, the pointer data item APTR is assigned the calculated address of CVAR.

In the above example, the second SET statement is setting procedure-pointer data item APROC-PTR to the outermost ILE COBOL program "PROGA".


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