The chained list in this example is set up so that the last record contains an address that is not valid. To do this, the pointer data item in the last record would be assigned the value NULL.
A pointer data item can be assigned the value NULL in three ways:
In the case of a chained list in which the pointer in the last record contains a null value, the code to check for the end of the list would be:
IF PTR-NEXT-REC = NULL
·
·
·
(logic for end of chain)
If you have not reached the end of the list, process the record and move on to the next record.
In the program CHAINLST, this test for the end of the chained list is accomplished with a "do while" structure:
PERFORM WITH TEST BEFORE UNTIL ADDRESS OF SALARY-REC = NULL IF DEPT = DEPT-X THEN ADD SALARY TO DEPT-TOTAL ELSE CONTINUE END-IF SET ADDRESS OF SALARY-REC TO PTR-NEXT-REC END-PERFORM
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.