Here’s sample COBOL program that shows how to use READ, WRITE and READ NEXT statements. The READ statement is to get record randomly. The READ NEXT to read VSAM file till end of the file.
Establish a Key
START statement positions the cursor. Once position establishes, you can use READ or READ NEXT statements. Below are the examples for that.
MOVE 'xxxxxx' TO key-value
START sample-file
KEY IS EQUAL TO key-value
END-START.
READ Statement
The purpose of READ statement is to fetch a record randomly after establishing a key. Here is more on How to Use READ in VSAM Complete Syntax .
READ sample_file RECORD INTO identifier
KEY IS EQUAL TO key_value
INVALID KEY do_this
NOT INVALID KEY do_this
END-READ.
READ NEXT Statement
READ Next fetches records sequentially till end of the input VSAM file. Here’s more on VSAM-Basics-Usage.
READ sample_file
NEXT RECORD INTO identifier KEY IS sample-key
AT END do_this
NOT AT END do_this
END-READ.
Note: When you work with VSAM files, the logic READ and READ NEXT helpful to read records.
Write a Record
WRITE record-name FROM identifier INVALID KEY statement.
Related Posts







One response
[…] name VSAM states that it is all about storage and Access method. Read my previous post on […]
LikeLike