VSAM- File Reading in COBOL Program


The below example shows how we can write code in COBOL program to read VSAM file. I am giving here the best method how we can give.

Simple Read just like sequential files:

OPEN INPUT sample-file.

READ sample-file INTO identifier.

AT END statement.


WRITE record-name FROM identifier

INVALID KEY statement.

Establishing a Key

Move ‘xxxxxx’ TO key-value

START sample-file KEY IS EQUAL TO key-value

Now position is established with start command. To read a record from a file into your working storage area, we need to give either READ or READ NEXT.

Rules for using READ or READ NEXT:

READ – we need to give if we have given access mode is sequential.

RED NEXT – we need to give , if we have given access mode is random.

Unless you give READ or READ NEXT, record from file will not be fetched.

Author: Srini

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

Comments are closed.