**************************************
      * Program name: dynfile.cbl
      * Demonstrates dynamic file processing
      * (without using EXECUTE statement).
      *
      * Copyright 2000 Deskware, Inc.
      **************************************
      * file name gldi variable definition
         1  file_name_gldi.
          5 FILLER      PIC X(n) VALUE `file`.
          5 counter pic 99.
          5 FILLER      PIC X(n) VALUE `.dat`.

      * file record definition
         1 file_record.
          5 field_1 PIC 99.
          5 field_2 pIC XX VALUE `AB`.

         PERFORM VARYING counter FROM 1 BY 1 UNTIL counter > 8
            FD file_name_gldi RECORD IS 4 BYTES
            OPEN file_name_gldi FOR WRITING
            PERFORM VARYING field_1 FROM 1 BY 1 UNTIL field_1 > 10
               IF field_1 > 5
                  MOVE `CD` TO field_2
               END-IF
               WRITE file_record TO file_name_gldi
            END-PERFORM
            CLOSE file_name_gldi
         END-PERFORM.
         GOBACK.