Browsing a VSAM Key Sequenced Data Set (KSDS) means positioning at a key (or at the beginning or end of the file) and then reading records sequentially in key order—without necessarily reading the whole file or changing any data. You "browse" a range: for example, all records with keys from 100 to 200, or all records from the start up to a limit. In batch COBOL you use START to set the position and READ NEXT in a loop. In CICS you use STARTBR to begin a browse and READNEXT (or READPREV) to read the next or previous record. Browse is often read-only: you scan and display or process records. This page explains how browse works, START vs READ, range scanning, and how CICS STARTBR and READNEXT relate to batch START and READ NEXT.
A browse is a sequential scan from a chosen starting point. You do not read the file randomly by key one at a time; you establish a position and then read the next record, then the next, then the next, until you have processed the range you care about or hit end of file. So browse = position + sequential read loop. The position is set by key: e.g. "start at the first record with key greater than or equal to X." Then each READ NEXT returns the next record in ascending key order. You can stop when the key goes past a certain value (e.g. end of range) or when you get an at-end condition. Browse is useful for listing records in key order, for range queries (e.g. "all orders in January"), and for read-only reporting.
| Step | How |
|---|---|
| Position | START with key condition (e.g. GTEQ) or at start; no record returned |
| Read | READ NEXT (or READ PREV) in a loop; each read returns next/previous record in key order |
| End | At end of range or ENDBR (CICS); close file or end browse |
In COBOL you use ACCESS IS DYNAMIC (or SEQUENTIAL) so you can use START and READ NEXT. START sets the current position. You move a key value to the RECORD KEY field (or alternate key field), then issue START with a key condition. Common conditions: KEY IS EQUAL TO (position at that key; next READ NEXT returns that record if it exists), KEY IS GREATER THAN OR EQUAL TO (position at the first record with key >= value; next READ NEXT returns that record). After a successful START, you loop with READ NEXT until you want to stop (e.g. key out of range) or AT END.
1234567891011121314151617MOVE LOW-KEY TO CUST-ID. START CUSTFILE KEY IS GREATER THAN OR EQUAL TO CUST-ID INVALID KEY DISPLAY 'No records in range' NOT INVALID KEY PERFORM UNTIL exit-flag READ CUSTFILE NEXT AT END SET exit-flag TO TRUE NOT AT END IF CUST-ID > HIGH-KEY SET exit-flag TO TRUE ELSE PERFORM PROCESS-RECORD END-IF END-READ END-PERFORM END-START.
This browses from LOW-KEY through HIGH-KEY. START positions at the first record with key >= LOW-KEY; the loop reads each record until the key exceeds HIGH-KEY or end of file.
In CICS, STARTBR (Start Browse) establishes the browse position. You pass the file name, the RIDFLD (record identifier field—for KSDS this is the key), and optionally KEYLENGTH and a search condition (EQUAL or GTEQ). GTEQ means "greater than or equal": position at the first record with key >= the value in RIDFLD. After STARTBR, you call READNEXT in a loop. Each READNEXT returns the next record in ascending key order and updates RIDFLD so the next READNEXT continues from there. You must not change RIDFLD between READNEXT calls (or the browse will jump to a different position). When done, issue ENDBR to release the browse. Multiple browses can be active if you use different REQID values. Browse in CICS is read-only: you cannot REWRITE or DELETE during the browse.
READPREV is the reverse: it reads the previous record in key order (descending). So you can browse backward from a high key. Use ENDBR when you finish so that the VSAM string (and buffers) are released.
To browse from the first record, position at the lowest key. In COBOL you can set the key to a value lower than any key in the file and use START KEY IS GREATER THAN OR EQUAL TO; the first READ NEXT then returns the first record. In CICS, KEYLENGTH(0) with STARTBR can position at the beginning. To browse from the end (e.g. for READPREV), position at a key higher than any in the file or use the appropriate START/STARTBR option so the first READ PREV returns the last record.
A common pattern is "give me all records where key is between A and B." You START (or STARTBR) with key condition GTEQ and key value A. Then you READ NEXT in a loop and process each record until the key is greater than B (or you hit end of file). That is a range browse. It is efficient because VSAM uses the index to find the first CI that contains key A, then reads CIs sequentially. You do not read the whole file if the range is small.
Random read: you supply one key, get one record. Browse: you set a starting position and then read many records in sequence. Use random read when you need a single record by key (e.g. lookup). Use browse when you need a range or a list in key order (e.g. "all customers in region X," "next 20 orders"). Both use the index; browse keeps the position and reads the next record each time.
Browsing is like starting at a certain page in a book and then reading the next page, then the next. You don't jump to random pages—you pick a starting place (START) and then read in order (READ NEXT). When you've read enough or reached the end, you stop. That's how you "browse" a range of records in key order.
1. What does START do in a VSAM browse?
2. In CICS, which command starts a browse?
3. Is browse typically read-only?