How to Set Position for File Using COBOL START Statement

The START statement is the best option in COBOL to deal with indexed files. In this post you will learn also best interview questions asked;

  • What is KEY IS
  • How record will START in this file position
  • Exception handling

The format of the START statement is given below:

START file-name [KEY IS {EQUAL TO

GREATER THAN >
NOT LESS THAN
NOT < THAN} data-name]
[; INVALID KEY imperative statement]

The START statement enables the programmer to position the relative file at some specified point so that subsequent sequential operations on the file can start from this point instead of the beginning. The KEY IS phrase indicates how the file is to be positioned.

The data name in this phrase must be the data name in the RELATIVE KEY phrase of the SELECT clause.

When the EQUAL TO OF NOT LESS THAN condition is specified, the file is GREATER THAN condition is specified, the file is positioned at the next relative position indicated by the relative key data item. Thus

START MY-FILE KEY IS GREATER THAN REL-KEY
INVALID KEY
GO TO INVALID PARA.

It will position the file at the fifty-first record position if the relative key data item REL-KEY contains 50.

  • The INVALID KEY condition arises if the specified record position if the specified record position is empty. In that case the imperative statement after the INVALID KEY phrase is executed.
  • The START statement requires that the file must be opened in the INPUT or I-O mode.
  • The access mode can only be SEQUENTIAL or DYNAMIC.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.