Modifying Records: The MATCH and NEXT Statements in VSAM

MATCH statements in MODIFY procedures select the first record with field values matching those that it provides. NEXT statements select the next record after the current position and make that the new current position.

MATCH or NEXT operations can select specific segments in a record, or specific segment instances in a multi-segment file structures. In this discussion, the logic that applies to record selection also applies to segment selection.

Current position depends upon the execution of MATCH and NEXT statements:

When the full key is used in a MATCH statement, subsequent NEXT statements retrieve subsequent records, continuing to the end of the file.

When a partial key is used, the starting point is the partial key value. This type of operation results in selection of the subset of a file's records that contain the specified key value. The search continues until the partial-key value changes, resulting in a NONEXT condition.

Issuing a MATCH on a partial key selects only the first instance of the matched value. You then use NEXT to select subsequent matches.

While NEXT statements can update segments similarly to MATCH statements and follow the same rules, they are usually employed in read-only operations for displaying field values.

You can use NEXT statements in requests without Case Logic to modify or display the data in:

To modify or display data in all descendent segments, use Case Logic as described in your FOCUS documentation. Use the NEXT statement to update and display data in the root segment. This request displays all the PUBKEYs of the LIBRARY6 file we described in Describing VSAM Data Sources to FOCUS:

MODIFY FILE LIBRARY6
.
.
.
NEXT PUBNO
ON NEXT TYPE "PUBLISHER NUMBER: <D.PUBNO"
ON NONEXT GOTO EXIT
.
.
.
DATA

Without resorting to Case Logic, a NEXT statement can only modify or display data in the first instance of a descendent segment.

This request uses Case Logic to display data from the LIBRARY6 file. When the descendent segments for a parent segment are exhausted, a NONEXT condition occurs.

MODIFY FILE LIBRARY6
PROMPT PUBNO
REPOSITION PUBNO
MATCH PUBNO
ON NOMATCH REJECT
ON MATCH TYPE "YOU ENTERED PUBLISHER #: <PUBNO"
ON MATCH GOTO CASENEXT
CASE CASENEXT
NEXT BOINKEY
ON NEXT TYPE
"THE PUBLISHER AND BINDING TYPE"
"IS <D.BOINKEY"
ON NEXT GOTO CASENEXT
ON NONEXT GOTO EXIT
ENDCASE
DATA

The MATCH statement selects a segment with a particular publisher number. The NEXT statement selects the segment with the group key information, that is, the publisher number along with the binding type indicator. The BOOK INFO segment is a descendent of the ROOT segment.


Information Builders