Coding input and output statements for VSAM files
Use the COBOL statements shown below to process VSAM files.
About this task
OPEN
- To connect the VSAM data set to your COBOL program for processing.
WRITE
- To add records to a file or load a file.
START
- To
establish the current location in the cluster for a
READ NEXT
statement.START
does not retrieve a record; it only sets the current record pointer. READ
andREAD NEXT
- To retrieve records from a file.
REWRITE
- To update records.
DELETE
- To logically remove records from indexed and relative files only.
CLOSE
- To disconnect the VSAM data set from your program.
All of the following factors determine which input and output statements you can use for a given VSAM data set:
- Access mode (sequential, random, or dynamic)
- File organization (ESDS, KSDS, or RRDS)
- Mode of
OPEN
statement (INPUT
,OUTPUT
,I-O
, orEXTEND
)
The following table shows the possible combinations of statements and open modes for sequential files (ESDS). The X indicates that you can use a statement with the open mode shown at the top of the column.
Access mode | COBOL statement | OPEN INPUT |
OPEN OUTPUT |
OPEN I-O |
OPEN EXTEND |
---|---|---|---|---|---|
Sequential | OPEN |
X | X | X | X |
WRITE |
X | X | |||
START |
|||||
READ |
X | X | |||
REWRITE |
X | ||||
DELETE |
|||||
CLOSE |
X | X | X | X |
The following table shows the possible combinations of statements and open modes that you can use with indexed (KSDS) files and relative (RRDS) files. The X indicates that you can use the statement with the open mode shown at the top of the column.
Access mode | COBOL statement | OPEN INPUT |
OPEN OUTPUT |
OPEN I-O |
OPEN EXTEND |
---|---|---|---|---|---|
Sequential | OPEN |
X | X | X | X |
WRITE |
X | X | |||
START |
X | X | |||
READ |
X | X | |||
REWRITE |
X | ||||
DELETE |
X | ||||
CLOSE |
X | X | X | X | |
Random | OPEN |
X | X | X | |
WRITE |
X | X | |||
START |
|||||
READ |
X | X | |||
REWRITE |
X | ||||
DELETE |
X | ||||
CLOSE |
X | X | X | ||
Dynamic | OPEN |
X | X | X | |
WRITE |
X | X | |||
START |
X | X | |||
READ |
X | X | |||
REWRITE |
X | ||||
DELETE |
X | ||||
CLOSE |
X | X | X |
The fields that you code in the FILE STATUS
clause
are updated by VSAM after each input-output statement to indicate
the success or failure of the operation.