Loading a variable-length table

You can use a do-until structure (a TEST AFTER loop) to control the loading of a variable-length table. For example, after the following code runs, LOCATION-TABLE-LENGTH contains the subscript of the last item in the table.

About this task


 DATA DIVISION.
 FILE SECTION.
 FD  LOCATION-FILE 
     RECORDING MODE F
     BLOCK 0 RECORDS
     RECORD 80 CHARACTERS
     LABEL RECORD STANDARD.
 01  LOCATION-RECORD.
     05  LOC-CODE               PIC XX.
     05  LOC-DESCRIPTION        PIC X(20).
     05  FILLER                 PIC X(58).
 . . .
 WORKING-STORAGE SECTION.
 01  FLAGS.
     05 LOCATION-EOF-FLAG       PIC X(5) VALUE SPACE.
        88 LOCATION-EOF                  VALUE "YES".
 01  MISC-VALUES.
     05 LOCATION-TABLE-LENGTH   PIC 9(3) VALUE ZERO.
     05 LOCATION-TABLE-MAX      PIC 9(3) VALUE 100.
*****************************************************************
***                L O C A T I O N   T A B L E                ***
***                FILE CONTAINS LOCATION CODES.              ***
*****************************************************************
 01  LOCATION-TABLE.
     05 LOCATION-CODE OCCURS 1 TO 100 TIMES
          DEPENDING ON LOCATION-TABLE-LENGTH   PIC X(80).
 . . .         
 PROCEDURE DIVISION.
     . . .
     Perform Test After
         Varying Location-Table-Length From 1 By 1
           Until Location-EOF
           Or Location-Table-Length = Location-Table-Max
       Move Location-Record To
           Location-Code (Location-Table-Length)
       Read Location-File
           At End Set Location-EOF To True
       End-Read
     End-Perform