Sequential access to an Entry Sequenced Data Set (ESDS) means reading records in the order they were written—entry order. There is no key in an ESDS, so the only "sequence" is the order in which records were appended to the file. Your program opens the file, then uses READ with NEXT (or the equivalent in your language) to read one record after another from the beginning to the end. Optionally, with dynamic access, you can position to a specific relative byte address (RBA) and then read sequentially from that point. This page explains how ESDS sequential access works, how it differs from KSDS sequential access, which COBOL verbs and access modes to use, and how to combine sequential read with RBA positioning when you need to resume from a saved position.
In an ESDS, sequential access means reading records in entry sequence: the first record written is the first you read, the second written is the second you read, and so on. The access method does not reorder records by a key (there is no key). It simply returns records in the order they exist on disk, which is the order in which they were written. So when you open an ESDS for input and repeatedly issue READ file-name NEXT, you get the records in the same order they were originally written. This is ideal for log files, audit trails, and any dataset where the chronological order of writes must be preserved and replayed in the same order.
Sequential read is efficient because VSAM reads control intervals in physical order. Once a control interval is in the buffer, all records in that CI can be returned with successive READ NEXT operations without extra I/O until the next CI is needed. So processing an entire ESDS from start to finish with READ NEXT tends to have good throughput.
In a Key Sequenced Data Set (KSDS), "sequential" means in key order: you read records in ascending (or descending) order by primary key. The physical order on disk is key order. In an ESDS, there is no key, so "sequential" means in entry order—write order. So the same word "sequential" means different things: key sequence for KSDS, entry sequence for ESDS. If you need to process records in the order they were created or received, ESDS sequential access gives you that. If you need to process in key order (e.g. customer ID), you use a KSDS and sequential access there gives you key order.
| Access mode | Description |
|---|---|
| ACCESS IS SEQUENTIAL | Read-only forward in entry order. READ NEXT from the beginning. START may not be supported. |
| ACCESS IS DYNAMIC | Can mix sequential (READ NEXT) and direct (START at RBA, then READ). Allows positioning by RBA then reading forward. |
In COBOL you define the ESDS with ORGANIZATION IS SEQUENTIAL (or the equivalent for your compiler; some use a different clause for VSAM ESDS). For sequential-only processing you specify ACCESS IS SEQUENTIAL. The RECORD KEY is not used for ESDS (there is no key). You still need a FILE STATUS clause to check after each READ. Example:
1234SELECT LOGFILE ASSIGN TO LOGFILE ORGANIZATION IS SEQUENTIAL ACCESS IS SEQUENTIAL FILE STATUS IS WS-STATUS.
With this definition you can OPEN INPUT LOGFILE, then in a loop PERFORM READ LOGFILE NEXT until the file status indicates end-of-file. Each READ returns the next record in entry order. To append records you would open with I-O (or a separate OPEN OUTPUT depending on how the file is used) and use WRITE to add records at the end.
With an ESDS opened for INPUT or I-O and ACCESS IS SEQUENTIAL, the typical valid operations are OPEN, READ (with NEXT for sequential read), REWRITE (to update the last record read in place, without changing length or only shortening), WRITE (to append a new record at the end when opened I-O), and CLOSE. With ACCESS IS DYNAMIC you can also use START to position at an RBA, then READ NEXT to read sequentially from that position. DELETE is not supported for ESDS (no physical delete).
| Operation | Description |
|---|---|
| OPEN | Open for INPUT (read-only) or I-O (read, update, append) |
| READ ... NEXT | Read next record in entry sequence |
| REWRITE | Update current record in place (same length or less) |
| WRITE | Append a new record at the end of the file |
| CLOSE | Close the file |
To read the entire ESDS from the start, open the file for INPUT, set up a loop, and issue READ file-name NEXT. The first READ returns the first record (lowest RBA), the next READ returns the second record, and so on. When there are no more records, the READ fails and the file status is set to indicate end-of-file (e.g. 10 in many COBOL implementations). You do not use a key; the access method maintains the current position and returns the next record in entry order each time.
Sometimes you need to start reading from the middle of the file—for example, to resume after a previous run. If you saved the RBA of the last record processed (or the RBA of the next record to process), you can open the file with ACCESS IS DYNAMIC, issue START to position at that RBA, then use READ NEXT to read forward in entry order from that point. Not all environments support START for ESDS; when they do, START with a key is not used (there is no key). Instead you specify the RBA so the access method positions to that byte offset. After that, READ NEXT returns the record at that RBA (if you positioned to a record start) or the next record, and continues in entry order. This gives you "resumable" sequential processing.
After each READ you should check the file status. A status of 00 (or 0) means the read was successful. A status indicating end-of-file (often 10) means there are no more records; you should exit the read loop. Other status values indicate errors (e.g. file not open, I/O error). Always check the status so your program can handle end-of-file and errors correctly.
If you open the ESDS for I-O, you can both read and update. After a successful READ, you can REWRITE the record to update it in place. The record length must not increase (you can shorten the record in some implementations). You cannot insert a record in the middle; the only way to add a record is WRITE, which appends at the end. So sequential processing with updates means: read in entry order, optionally REWRITE the current record, and optionally WRITE new records at the end. The sequential read order is unaffected; new records written at the end become the next records when you continue reading (if your design allows reading and writing in the same run) or in a subsequent run when you read from the beginning again.
Sequential read of an ESDS is efficient because it uses the natural physical order of the data. VSAM reads control intervals in sequence, so I/O is largely sequential on disk. For large ESDS files, reading from the beginning to the end with READ NEXT is one of the most efficient access patterns. If you need to resume from an RBA, positioning with START and then reading forward is still sequential from that point. Avoid repeatedly positioning to random RBAs and reading one record if you want maximum throughput; that pattern is more like random access and may cause more I/O.
Imagine a notebook where you only add new lines at the end. Reading the ESDS in order is like reading that notebook from the first line to the last. You don't jump by a "name" or "number"; you just read the next line each time. The order you read is exactly the order you (or someone) wrote the lines. If you put a bookmark at a line (that's like saving the RBA), next time you can open the notebook, go to the bookmark, and keep reading from there.
1. In what order are records read when you use READ NEXT on an ESDS?
2. Which access mode allows you to position by RBA and then read sequentially from that point?
3. What is the main difference between sequential read in ESDS vs KSDS?