Controlling the Current Record Position With REPOSITION in VSAM

With each successful MATCH in MODIFY process, the record containing the matched value becomes your current position within the file.

How to:

Establish Current Position Using REPOSITION Statements in VSAM

In NOMATCH situations, the current position will be the end of the file. Because FOCUS does not recognize VSAM record keys, the current position does not return to the beginning of the file after each pass. This creates a possibility that processing could terminate unexpectedly, or, that a NOMATCH condition might occur despite the existence of a matching key value in the file. The solution is to include the REPOSITION statement in all MODIFY procedures to change your current position and prevent abnormal terminations.

Syntax: Establishing Current Position Using REPOSITION Statements in VSAM

REPOSITION field

where:

field
Is any field of any segment.

REPOSITION enables you to change your current position in the data source, either returning to the beginning, or to the beginning of a record, or to the beginning of a segment chain within a record (that is, the parent segment, the parent's parent, and so on to the root segment). From there, you can search the segment chain from the beginning.

In the following example, REPOSITION is used to return the current position of the STUDENT field to the beginning of the file, enabling you to reenter data for STUDENT and LAST NAME.

MODIFY FILE VSAM2
REPOSITION STUDENT
MATCH STUDENT
ON NOMATCH INCLUDE
ON NOMATCH GO TO NEWREC
ON MATCH GO TO OLDREC
.
.
.

After executing REPOSITION, the current position depends on your MATCH or NEXT logic. When a NOMATCH or NONEXT condition exists, you tell FOCUS how to proceed by specifying a fieldname to tell it how to process the current data source.


Information Builders