COBOL File Start

COBOL File Delete COBOL File Read Next

Advertisements


START is used in DYNAMIC access mode of indexed files.

START is used to set the pointer to the next read for reading the record.

START will be not retrieving any record and it only sets the pointer to the next read for reading the record.


Syntax:


START file-name-1 [KEY {relational operator} data-name-1]
      [INVALID KEY imperative-statement-1]
      [NOT INVALID KEY imperative-statement-1]
[END-EVALUATE].


Operating procedure:

  1. Move the key value to the key data name.
  2. Execute the start statement then the pointer will place at the starting of the matched record.

Practical Example - FILE START:


Below example is used to display all the records after the specified student number from student records.


Code:


 IDENTIFICATION DIVISION.                                         
 PROGRAM-ID. INDXFILD.                                            
 ENVIRONMENT DIVISION.                                            
 INPUT-OUTPUT SECTION.                                            
 FILE-CONTROL.                                                    
     SELECT FILE1 ASSIGN TO DISK1.                               
     ORGANIZATION IS INDEXED.                                    
     ACCESS MODE IS DYNAMIC.                                     
     RECORD KEY  IS STD-NO.                                       
     FILE STATUS IS WS-FS.                                        
 DATA DIVISION.                                                   
 FILE SECTION.                                                    
 FD  FILE1.                                                      
 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-FS               PIC 9(02).                              
 01 WS-EOF-SW           PIC X(01) VALUE 'N'.                     
    88 EOF-SW           VALUE 'Y'.                              
    88 NOT-EOF-SW       VALUE 'N'.                              
 PROCEDURE DIVISION.                                            
     ACCEPT STD-NO.                                             
     DISPLAY 'FILE BROWSING...'.                                 
     OPEN INPUT FILE1.                                           

     START FILE1 KEY EQUAL STD-NO.
        INVALID KEY DISPLAY 'NO STUDENT FOUND WITH GIVEN STD-NO'
        NOT INVALID KEY PERFORM READ-NEXT-RECS. 

     CLOSE FILE1.                                                
     DISPLAY STD-REC.  

     STOP RUN.                                                    

 READ-NEXT-RECS.

     PERFORM UNTIL EOF-SW                                         
        READ NEXT FILE1                                           
        AT END MOVE 'Y'  TO WS-EOF-SW                             
           DISPLAY 'RECORD READ : ' STD-REC                       
     END-PERFORM. 

 READ-NEXT-RECS-EXIT.
     EXIT.


COBOL File Delete COBOL File Read Next

Advertisements