COBOL File Processing Cycle

COBOL Files COBOL File Declaration

FILE cycle process involves file declaration, open, file operations and closing file.

File processing in COBOL mainly divided into four parts. Those are named as below.

  • Declaration
  • Open
  • Process
  • Close


FILE Declaration specifies the FILE specifications to the program.

FILE Declaration includes allocating & defining of FILE.

FILE Declaration divided into two categories.

The FILE Declaration topic explained in detail here


Open operation is to open a file before performing any kind of process on files like read, write or re-write etc.

Without opening a file, Programmer can’t able to perform any processing operations.

The FILE Open topic explained in detail here

Processing a File:

Processing of a file is nothing but performing any operations like READ/WRITE/REWRITE etc other than OPEN and CLOSE.

The FILE processing topic explained in detail here

Closing of File:

CLOSE statement used to close the files once the processing of the file completed.

An Opened file should be closed and that can be done by using CLOSE statement.

The FILE CLSOE topic explained in detail here

Practical Example:


  IDENTIFICATION DIVISION.                                        
  PROGRAM-ID. SEQFILE.                                            
  ENVIRONMENT DIVISION.                                            
  INPUT-OUTPUT SECTION.                                            
      SELECT FILE1 ASSIGN TO DISK1.                               
      ORGANIZATION IS SEQUENTIAL                                   
      ACCESS MODE IS SEQUENTIAL                                    
      FILE STATUS IS WS-FS1.                                       
  DATA DIVISION.                                                   
  FILE SECTION.                                                    
  FD  FILE1.                                                       
      RECORD CONTAINS 80 CHARACTERS.                               
      BLOCK CONTAINS 800 CHARACTERS.                               
      RECORDING MODE IS F.                                         
      DATA RECORD IS STD-REC.                                      
  01 STD-REC.                                                      
      02 STD-NO          PIC 9(03).                                
      02 STD-NAME        PIC X(20).                                
      02 STD-GENDER      PIC X(07).                                
      02 FILLER          PIC X(50).                                
  WORKING-STORAGE SECTION.                                        
  77 WS-STD-NO           PIC 9(03).                                
  77 WS-STD-NAME         PIC X(20).                                
  77 WS-STD-GENDER       PIC X(07).                                
  77 WS-FS1              PIC 9(02).                               
  77 WS-FS2              PIC 9(02).                                
     88 EOF-SW           VALUE 'Y'.                                
     88 NOT-EOF-SW       VALUE 'N'.                               
  PROCEDURE DIVISION.                                             
      ACCEPT WS-STD-NO.                                           
      ACCEPT WS-STD-NAME.                                         
      ACCEPT WS-STD-GENDER.                                        
      DISPLAY 'SEQUENTIAL FILE EXTENDED MODE..'                    
      OPEN EXTEND FILE1.                                           
      PERFORM UNTIL EOF-SW                                         
         READ FILE1                                               
         AT END MOVE 'Y' TO WS-EOF-SW                              
         IF STD-NO = WS-STD-NO                                     
            MOVE 'Y' TO WS-EOF-SW                                  
            DISPLAY 'DUPLICATE RECORD EXISTS...'                  
      IF STD-NO NOT EQUAL WS-STD-NO                                
         WRITE STD-REC                                             
      CLOSE FILE1.                                                
      STOP RUN.                                                    

COBOL Files COBOL File Declaration