title: COBOL Program to read a flat file sequentially and write it to an output file, not able to read at all loop is going infinite
body: <p>I'm trying to write COBOL Program to read a flat file sequentially and write it to an output file, I'm able to read only one record at a time, not able to read next record what should I do?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>PROCEDURE DIVISION.                                           
      OPEN INPUT FILEX.                                         
      PERFORM READ-PARA THRU END-PARA UNTIL END-OF-FILE = 'Y'.  
      CLOSE FILEX.                                              
      STOP RUN.                                                 
  READ-PARA.                                                    
      READ FILEX                                                
        AT END                                                  
      MOVE 'Y' TO END-OF-FILE                                   
      DISPLAY OFFCODE1                                          
      DISPLAY AGCODE1                                           
      DISPLAY POLNO1                                            
      DISPLAY EFFDATE1                                          
      DISPLAY EXPDATE                                           
      DISPLAY REPCODE                                           
      DISPLAY POLHOLDER1                                        
      DISPLAY LOCATION1                                         
      GO TO END-PARA.                                           
  END-PARA.   
  </code></pre>
  
  <p>i, ve tried using the scope terminator, still not able to loop 'm getting S001 ABEND here is my code :</p>
  
  <pre><code>IDENTIFICATION DIVISION.             
  PROGRAM-ID. SIMPLE.                  
  ENVIRONMENT DIVISION.                
  INPUT-OUTPUT SECTION.                
  FILE-CONTROL.                        
   SELECT FILEX ASSIGN TO SYSUT1   
   FILE STATUS IS FS.              
  DATA DIVISION.                       
  FILE SECTION.                        
  FD  FILEX.                           
  01  FILEXREC.                        
  02 OFFCODE1 PIC X(3).            
  02 FILLER PIC X.                 
  02 AGCODE1 PIC X(3).             
  02 FILLER PIC X.                 
  02 POLNO1 PIC X(6).              
  02 FILLER PIC X.                 
  02 EFFDATE1 PIC X(8).            
  02 FILLER PIC X.                                        
  02 EXPDATE PIC X(8).                                    
  02 FILLER PIC X.                                        
  02 REPCODE PIC X(1)                                     
  02 FILLER PIC X.                                        
  02 POLHOLDER1 PIC X(8).                                 
  02 FILLER PIC X.                                        
  02 LOCATION1 PIC X(9).                                  
  02 FILLER PIC X(87).                                    
  WORKING-STORAGE SECTION.                                    
  77  FS PIC 9(2).                                            
  01  WS-INDICATORS.                                          
   10  WS-EOF-IND                    PIC X(01) VALUE 'N'.  
       88  WS-END-OF-FILE                      VALUE 'Y'.  
  PROCEDURE DIVISION.                                         
   OPEN INPUT FILEX.                                       
   PERFORM READ-PARA THRU END-PARA UNTIL WS-END-OF-FILE.   
   CLOSE FILEX. 
   STOP RUN.                         
  READ-PARA.                            
   READ FILEX                        
     AT END                          
        MOVE 'Y' TO WS-EOF-IND.      
     DISPLAY OFFCODE1                
     DISPLAY AGCODE1                 
     DISPLAY POLNO1                  
     DISPLAY EFFDATE1                
     DISPLAY EXPDATE                 
     DISPLAY REPCODE                 
     DISPLAY POLHOLDER1              
     DISPLAY LOCATION1               
     IF WS-END-OF-FILE               
        GO TO END-PARA.            
    END-PARA.                             
   EXIT.                       
  </code></pre>
  
  <p>one more method i tried even in this works for only one record, again getting S001 ABEND while running the code. Here is the code:</p>
  
  <pre><code>   IDENTIFICATION DIVISION.                  
     PROGRAM-ID. ASSIGNMENT.                   
     ENVIRONMENT DIVISION.                     
     INPUT-OUTPUT SECTION.                     
     FILE-CONTROL.                             
     SELECT FILEX ASSIGN TO SYSUT1         
     DATA DIVISION.                            
     FILE SECTION.                             
     FD  FILEX.                                
     LABEL RECORDS ARE STANDARD            
     RECORD CONTAINS  140  CHARACTERS      
     BLOCK CONTAINS  00  RECORDS.          
       01  FILEXREC.                             
        02 OFFCODE1 PIC 9(3).                 
        02 FILLER PIC X.                      
        02 AGCODE1 PIC X(3).                  
        02 FILLER PIC X.                      
        02 POLNO1 PIC X(6).                   
        02 FILLER PIC X.                                      
        02 EFFDATE1 PIC X(8).                                 
        02 FILLER PIC X.                                      
        02 EXPDATE1 PIC X(8).                                 
        02 FILLER PIC X.                                      
        02 REPCODE1 PIC X(1).                                 
        02 FILLER PIC X.                                      
        02 POLHOLDER1 PIC X(8).                               
        02 FILLER PIC X.                                      
        02 LOCATION1 PIC X(9).                                
        02 FILLER PIC X(26).                                  
    WORKING-STORAGE SECTION.                                  
     01  WS-INDICATORS.                                        
     10  WS-EOF-IND                    PIC X(01) VALUE 'N'.
      88  WS-END-OF-FILE                      VALUE 'Y'.
  
     01  TEMP1.                                                
      02 OFFCODE2 PIC 9(3).                                 
      02 FILLER PIC X.                                      
      02 AGCODE2 PIC X(3).                                  
      02 FILLER PIC X.                                      
      02 POLNO2 PIC X(6).                                   
      02 FILLER PIC X.                                      
      02 EFFDATE2 PIC X(8).                                 
      02 FILLER PIC X.                                      
      02 EXPDATE2 PIC X(8).                                 
      02 FILLER PIC X.                                      
      02 REPCODE2 PIC X(1).                                 
      02 FILLER PIC X.                                      
      02 POLHOLDER2 PIC X(8).                               
      02 FILLER PIC X.                                      
      02 LOCATION2 PIC X(9).                                
      02 FILLER PIC X(26).                                  
   PROCEDURE DIVISION.                                       
   OPEN INPUT FILEX.                                     
   PERFORM READ-PARA THRU END-PARA UNTIL WS-END-OF-FILE. 
  CLOSE FILEX.                                          
  STOP RUN.                        
  READ-PARA.                           
  READ FILEX                       
       INTO TEMP1                  
    AT END                         
       MOVE 'Y' TO WS-EOF-IND.     
    DISPLAY OFFCODE1               
    DISPLAY AGCODE1                
    DISPLAY POLNO1                 
    DISPLAY EFFDATE1               
    DISPLAY EXPDATE1               
    DISPLAY REPCODE1               
    DISPLAY POLHOLDER1             
    DISPLAY LOCATION1              
          IF WS-END-OF-FILE        
             GO TO END-PARA.       
    END-PARA.                      
        EXIT. 
  </code></pre>