ILE COBOL Programmer's Guide

Passing Pointers between Programs and Procedures

To obtain the address of the first SALARY-REC record area, the CHAINLST program calls the program CHAINANC:

           CALL "CHAINANC" USING PTR-FIRST

PTR-FIRST is defined in WORKING-STORAGE in the calling program (CHAINLST) as a pointer data item:

       WORKING-STORAGE SECTION.
       77  PTR-FIRST         POINTER  VALUE IS NULL.

Upon return from the call to CHAINANC, PTR-FIRST contains the address of the first record in the chained list.

PTR-FIRST is initially defined as having a null value as a logic check. If an error occurs with the call, and PTR-FIRST never receives the value of the address of the first record in the chain, a null value remains in PTR-FIRST and, according to the logic of the program, the records will not be processed.

NULL is a figurative constant used to assign the value of a non-valid address to pointer items. It can be used in the VALUE IS NULL clause, in the SET statement, and as an operand in a relation condition with a pointer.

The Linkage Section of the calling program contains the description of the records in the chained list. It also contains the description of the department code that is passed through the USING phrase of the CALL statement.

       LINKAGE SECTION.
       01  SALARY-REC.
         05  PTR-NEXT-REC    POINTER.
         05  NAME            PIC X(20).
         05  DEPT            PIC 9(4).
         05  SALARY          PIC 9(6).
       01  DEPT-X            PIC 9(4).

To base the record description SALARY-REC on the address contained in PTR-FIRST, use a SET statement:

           CALL "CHAINANC" USING PTR-FIRST
           SET ADDRESS OF SALARY-REC TO PTR-FIRST


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