title: The system detected a protection exception
body: <p>I am trying to use the SORT feature of COBOL.</p>
  
  <pre><code>IDENTIFICATION DIVISION.                       
  PROGRAM-ID. ******.                          
  ENVIRONMENT DIVISION.                          
  INPUT-OUTPUT SECTION.                          
  FILE-CONTROL.                                  
       SELECT IN-FILE ASSIGN TO IFILE.           
       SELECT OUT-FILE ASSIGN TO OFILE.          
       SELECT SORT-FILE ASSIGN TO SORTWK.        
  DATA DIVISION.                                 
  FILE SECTION.                                  
  SD SORT-FILE.                                  
  01 SORT-REC.                                   
     05 S-NAME     PIC X(20).                    
     05 S-ADDRESS  PIC X(20).                    
     05 S-ID       PIC 9(9).                     
     05 S-CREDITS  PIC 99.                       
     05 FILLER     PIC X(29).                    
  FD IN-FILE.                                    
  01 IN-REC.                                     
     05 IN-NAME    PIC X(20).                    
     05 IN-ADDRESS PIC X(20).                    
     05 IN-ID      PIC 9(9).                     
     05 IN-CREDITS PIC 99.                       
     05 FILLER     PIC X(29).                    
  FD OUT-FILE.                                   
  01 OUT-REC       PIC X(80).                    
  WORKING-STORAGE SECTION.                       
  01 WS-WORK-AREA.                               
      05  EOF-SW    PIC X           VALUE SPACES.
  01 WS-DETAIL-LINES.                            
     05 RPT-LINE.                                
        10 OUT-NAME    PIC X(20).                
        10 OUT-ADDRESS PIC X(20).                
        10 OUT-ID      PIC 9(9).
        10 OUT-CREDITS PIC 99.                      
        10 FILLER      PIC X(29)       VALUE SPACES.
  PROCEDURE DIVISION.                               
  MAIN-RTN.                                         
      SORT SORT-FILE                                
              ON ASCENDING KEY S-ID                 
              INPUT PROCEDURE READ-RELEASE          
              OUTPUT PROCEDURE RETURN-WRITE.        
      STOP RUN.                                     
  OPEN-FILES-RTN.                                   
      OPEN INPUT IN-FILE.                           
      OPEN OUTPUT OUT-FILE.                         
  OPEN-FILES-RTN-EXIT. EXIT.                        
  
  READ-RELEASE.                                     
      PERFORM OPEN-FILES-RTN.                       
      PERFORM READ-INPUT                            
       UNTIL EOF-SW = 'F'.                          
  READ-RELEASE-RTN-EXIT. EXIT.                      
  
  READ-INPUT.                                       
      READ IN-FILE                                  
       AT END MOVE 'F' TO EOF-SW.                   
      RELEASE SORT-REC FROM IN-REC.                 
  
  RETURN-WRITE.                                     
      MOVE SPACES TO EOF-SW.                        
      PERFORM WRITE-FL                              
       UNTIL EOF-SW  = 'F'.                         
      PERFORM CLOSE-FILES-RTN.                      
  RETURN-WRITE-RTN-EXIT. EXIT.                      
  
  WRITE-FL.                                         
      RETURN SORT-FILE RECORD INTO OUT-REC          
       AT END MOVE 'F' TO EOF-SW.                   
      WRITE OUT-REC.
  WRITE-FL-RTN-EXIT. EXIT.   
  
  CLOSE-FILES-RTN.           
      CLOSE IN-FILE OUT-FILE.
  CLOSE-FILES-RTN-EXIT. EXIT. 
  </code></pre>
  
  <p>I am able to compile this program but when it comes to execute, it gives the following error:</p>
  
  <blockquote>
    <p>CEE3204S The system detected a protection exception (System Completion
    Code=0C4).        From compile unit SU98PGM6 at entry point SU98PGM6
    at compile unit offset +0005517A   at address 1F45517A.</p>
  </blockquote>
  
  <p>I have searched about this error but I couldn't figure out what is causing this problem in my program. </p>
  
  <p>I have made some changes after taking note of the comments, but am still getting the same problem with this changed code.</p>
  
  <pre><code>READ-RELEASE.                           
      PERFORM OPEN-FILES-RTN.             
      PERFORM READ-INPUT                  
       UNTIL EOF-SW = 'F'.                
  READ-RELEASE-RTN-EXIT. EXIT.            
  
  READ-INPUT.                             
      READ IN-FILE                        
       AT END MOVE 'F' TO EOF-SW          
       NOT AT END PERFORM PROCESS-INPUT.  
  
  PROCESS-INPUT.                          
      MOVE IN-NAME TO S-NAME.             
      MOVE IN-ADDRESS TO S-ADDRESS.       
      MOVE IN-ID TO S-ID.                 
      MOVE IN-CREDITS TO S-CREDITS.       
      RELEASE SORT-REC.                   
  PROCESS-INPUT-RTN-EXIT. EXIT.           
  
  RETURN-WRITE.                           
      MOVE SPACES TO EOF-SW.              
      PERFORM WRITE-FL                    
       UNTIL EOF-SW = 'F'.                
      PERFORM CLOSE-FILES-RTN.            
  RETURN-WRITE-RTN-EXIT. EXIT.            
  
  WRITE-FL.                               
      RETURN SORT-FILE RECORD INTO OUT-REC
       AT END MOVE 'F' TO EOF-SW          
       NOT AT END PERFORM PROCESS-OUTPUT. 
  WRITE-FL-RTN-EXIT. EXIT.                
  
  PROCESS-OUTPUT.                         
      MOVE S-NAME TO OUT-NAME.            
      MOVE S-ADDRESS TO OUT-ADDRESS.      
      MOVE S-ID TO OUT-ID.                
      MOVE S-CREDITS TO OUT-CREDITS.
      WRITE OUT-REC.            
  PROCESS-OUTPUT-RTN-EXIT. EXIT.   
  </code></pre>
  
  <p>Here is my JCL</p>
  
  <pre><code>//******** JOB 1,'*****',NOTIFY=*******                    
  //JOBLIB   DD  DSN=*******.*******.*******,DISP=SHR         
  //STEP0    EXEC PGM=SU98PGM6                               
  //IFILE    DD DSN=*******.*******.*******.*******(*******),DISP=SHR
  //SORTWK   DD DSN=*******.*******.*******.*******,DISP=SHR          
  //OFILE    DD DSN=*******.*******.*******.*******,              
  //            DISP=(NEW,CATLG,DELETE),                     
  //            DCB=(BLKSIZE=0,LRECL=80,RECFM=FB),           
  //            SPACE=(CYL,(1,1),RLSE),                      
  //            UNIT=SYSDA                                   
  /*         
  </code></pre>