title: Sequentially read a specific record in a file then display it
body: <pre><code>INPUT-OUTPUT SECTION.
     FILE-CONTROL.
         SELECT MASTER-FILE ASSIGN TO "MASTER-PRODUCT-FILE.DAT"
         ORGANIZATION IS SEQUENTIAL
         ACCESS MODE IS SEQUENTIAL.
  
         SELECT TRANSACTION-FILE ASSIGN TO "INVENTORY-FILE.DAT"
         ORGANIZATION IS LINE SEQUENTIAL.
  
  DATA DIVISION.
    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
     FILE SECTION.
     FD MASTER-FILE.
     01 MASTER-RECORDS.
         05 PR-CODE                  PIC 9(7).
         05 PR-NAME                  PIC X(30).
         05 PR-PRICE                 PIC 9(5)V99.
         05 PR-QUANTITY              PIC S9(6).
  
     FD TRANSACTION-FILE.
     01 TRANSACTION-RECORDS.
         05 TR-CODE                  PIC 9(6).
         05 TR-DATE.
             10 DATE-YEAR            PIC 9(4).
             10 DATE-MONTH           PIC 99.
             10 DATE-DAY             PIC 99.
         05 TR-PRODCODE              PIC 9(7).
         05 TR-PRODNAME              PIC X(30).
         05 TR-PRODPRICE             PIC 9(5).
         05 TR-PRODQUANTITY          PIC S9(6).
         05 TR-PRODSALES             PIC 9(6)V99.
  
   WORKING-STORAGE SECTION.
    *Current Date
     01 CDate.
         05 CYear                    PIC 9(4).
         05 CMonth                   PIC 99.
         05 CDay                     PIC 99.
    *Current Time
     01 CTime.
         05 CHour                    PIC 99.
         05 CMinute                  PIC 99.
  *End of File
     01 EOF                          PIC A(1).
    *Input Product Code
     01 WS-PR-CODE                   PIC 9(7).
  
  PROCEDURE DIVISION.
    *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
     0000-MAIN.
         PERFORM 1000-INCREMENT.
         PERFORM 2000-INTRO.
         PERFORM 3000-DATA-ENTRY-PR-CODE.
         PERFORM 4000-OPEN-FILE.
         PERFORM 5000-READ-MASTER-FILE.
         PERFORM 6000-CLOSE-FILE.
    *-----------------------------------------------------------------
     1000-INCREMENT.
    *Increment the transaction code to 1
         MOVE 000000 TO TR-CODE
         ADD 1 TO TR-CODE.
    *-----------------------------------------------------------------
     2000-INTRO.
    *Current date and time validation
         ACCEPT  CDate FROM DATE YYYYMMDD.
         ACCEPT  CTime FROM TIME.
    *System's header
         DISPLAY SPACES.
         DISPLAY "--------------------------------------------------".
         DISPLAY "|                  INVENTORY SYSTEM              |".
         DISPLAY "--------------------------------------------------".
         DISPLAY SPACES.
         DISPLAY "         TRANSACTION NUMBER : "TR-CODE
         DISPLAY "         TRANSACTION DATE   : "CMonth"/"CDay"/"CYear
         DISPLAY "         TRANSACTION TIME   : "CHour":"CMinute
         DISPLAY SPACES.
         DISPLAY "      **** PLEASE ENTER PRODUCT DETAILS ****      ".
    *-----------------------------------------------------------------
     3000-DATA-ENTRY-PR-CODE.
         DISPLAY "PRODUCT CODE    : " WITH NO ADVANCING.
         ACCEPT WS-PR-CODE.
  
         PERFORM 5000-READ-MASTER-FILE.
    *-----------------------------------------------------------------
     4000-OPEN-FILE.
         OPEN I-O MASTER-FILE
         OPEN OUTPUT TRANSACTION-FILE.
    *-----------------------------------------------------------------
     5000-READ-MASTER-FILE.
         PERFORM UNTIL EOF = "Y"
             READ MASTER-FILE INTO WS-PR-CODE
                 AT END MOVE "Y" TO EOF
                 NOT AT END DISPLAY MASTER-RECORDS
             END-READ
         END-PERFORM.
    *-----------------------------------------------------------------     
     6000-CLOSE-FILE.
         CLOSE MASTER-FILE.
         CLOSE TRANSACTION-FILE.
         STOP RUN.
  </code></pre>
  
  <p>How can I fix this? My problem is that when I enter the product code, it doesn't display the product details. The error is READ/START not allowed. Can you teach me how to find a specific record in a file? At first I manually created the .DAT file, inserted few records according to the data types and format. Please see the .DAT file <a href="https://drive.google.com/file/d/0B-JYlsx2A-2qSDNmSHZvLVA4dTA/view?usp=sharing" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Here is the sample output:</p>
  
  <p><img src="https://i.stack.imgur.com/2zRUi.png" alt="enter image description here"></p>