In this topic, we described about the below sections -
START is used to set the file pointer to read the next record. START won't retrieve any record and only sets the pointer to read the next record. The START statement used for positioning within an indexed or relative file for subsequent sequential retrieval.
The associated indexed or relative file must be open in either INPUT or I-O mode before performing START statement. When the START statement is executed, a comparison is made between the key data-name value and the corresponding key field in the file.
If the FILE STATUS clause is specified in the file-control entry, the associated file status key is updated when the START statement is executed.
Must name a file with sequential or dynamic access. file-name-1 should be defined with FD entry in the data division. file-name-1 must not name a sort file.
KEY phrase -
KEY phrase is used to position the file position indicator at the record that satisfies the specified KEY value in the file. When the KEY phrase is not specified, KEY IS EQUAL is applied.
If the KEY is specified with 'less than' or 'less than or equal to', the file position indicator is positioned to the last logical record that satisfies the comparison.
For an indexed file, if the key has duplicate entries that satisfies the comparison, the file position indicator is positioned at the last record of the entries.
- Can be qualified.
- Can't be subscripted.
INVALID KEY phrase -
If the comparison is not satisfied by any record in the file, an invalid key condition exists; the position of the file position indicator is undefined and (if specified) the INVALID KEY imperative-statement is executed.
Both the INVALID KEY phrase and an applicable EXCEPTION/ERROR procedure can be omitted.
END-START phrase -
The END-START used to end the scope of the START statement. END-START is not required when START statement ended with period.
END-START can also be used with an imperative START statement. END-START permits conditional START to be nested in another conditional statement.
Practical Example - FILE START
Below example is used to display all the records after the specified student number from student records.
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.