****************************************
      * Program name: read.cbl
      * This program provides examples
      * of how to use the READ command.
      *
      * Copyright 2000 Deskware, Inc.
      ****************************************                                                             
      * Syntax: READ  INTO .
      *                                                               
      * Syntax: READ  INTO 
      *             AT END .
      *
       FD `WRITE1.DAT` RECORD IS 12 BYTES.
       FD `WRITE2.DAT` RECORD IS 14 BYTES.  
       1 eof              PIC X        VALUE `N`.
       1 yes              PIC X        VALUE `Y`.
       1 no               PIC X        VALUE `N`.
       1 write1_record.
           5 write1_field_1      PIC X(05).
           5 write1_field_2      PIC X(05).
       1 write2_record.
           5 write2_field_1      PIC X(05).
           5 write2_field_2      PIC X(05).

       MAIN.
            DISPLAY `NOTE: Running "cobolscript.exe write.cbl" `.
            DISPLAY `will create the data files used by this sample program.`.
            DISPLAYLF.
            PERFORM OPEN_FILES.
            MOVE `Y` TO yes.
            MOVE `N` TO eof.
            PERFORM PROCESSING_1 UNTIL eof = `Y`.
            MOVE `Y` TO yes.
            MOVE `N` TO eof.
            PERFORM PROCESSING_2 UNTIL eof = `Y`.
            PERFORM CLOSE_FILES.
            STOP RUN.
       OPEN_FILES.
      * Open a fixed width and a comma delimited text file.
            OPEN `WRITE1.DAT` FOR READING. 
            OPEN `WRITE2.DAT` FOR READING DELIMITED WITH `,`. 
            DISPLAY `FILES OPENED`.
       PROCESSING_1.
      * Read the fixed width text file.
            READ `WRITE1.DAT` INTO write1_record AT END MOVE yes TO eof.
            DISPLAY `eof: ` & eof  &
            ` write1_record: <`  & write1_record  & `>`.
       PROCESSING_2.
      * Read the comma delimited text file.
            READ `WRITE2.DAT` INTO write2_record AT END MOVE yes TO eof.
            DISPLAY `eof: `  & eof  & ` write2_record: <`  &
            write2_record  & `>`.
       CLOSE_FILES.
           CLOSE `WRITE1.DAT`.
           CLOSE `WRITE2.DAT`.
           DISPLAY `FILES CLOSED`.