Looping Through Files With REPEAT in VSAM

MODIFY requests using FIDEL usually prompt for a key field value and then use that to retrieve a segment instance. After modifying that instance, you enter a new key field value to retrieve the next instance. In this way, you can modify one segment instance at a time.

How to:

Loop With the REPEAT statement in VSAM

The REPEAT statement enables you to process records with segments that have multiple-occurrences. With REPEAT, you can add, update, or delete several segment instances on one screen.

Multi-record processing causes the request to retrieve multiple segment instances before FIDEL displays instance values. Each time the request retrieves a segment instance, it stores its values in a work area in memory called the Scratch Pad Area. The request continues retrieving instances until the specified number is reached.

After retrieving the instances, FIDEL reads the instance values from the Scratch Pad Area and displays them all on one screen. You can then update them and transmit the updated values back to the VSAM data source.

You can also design requests to add several segments at a time or to both update existing segments and add new ones on the same screen.

This topic describes multiple-occurrence record processing using REPEAT. One REPEAT statement collects record instances and loads them into the Scratch Pad Area (SPA); another REPEAT statement retrieves records from the SPA and uses them to modify the database. This method does not require knowledge of how the records are stored in the SPA. You must process them sequentially, however, and you can process only one at a time.

Refer to your FOCUS documentation for additional information about the REPEAT statement.


Top of page

Syntax: Looping With the REPEAT statement in VSAM

REPEAT  {*/count} [TIMES] [MAX limit] [NOHOLD]
phrases
.
.
ENDREPEAT

where:

count
Is an integer or temporary integer field that specifies the number of times the request executes REPEAT. The value (from 0 to 32,767) should not be smaller than the number of segment instances to be displayed on the FIDEL screen.

If count is 0, the REPEAT does not execute (this allows you to skip a REPEAT if you use a temporary field for this parameter).

If count is an asterisk, the REPEAT executes indefinitely. To end it, code a GOTO ENDREPEAT.

Once REPEAT begins execution, the count value cannot be changed.

TIMES
Is an optional word used to improve readability.

limit
Is an integer specifying the maximum number of times to execute the REPEAT. Specify this only when using a temporary field for the count parameter.

NOHOLD
Is an option that allows you to use REPEAT as a simple loop that executes a group of MODIFY statements repeatedly.

phrases
Are MODIFY statements to be executed within the REPEAT statement. Each must begin on a new line.

ENDREPEAT
Ends the REPEAT statement and must appear on a line by itself.

REPEAT statements can stand by themselves or can be part of ON MATCH, ON NOMATCH, ON NEXT, or ON NONEXT phrases in MATCH or NEXT statements. The following example loads multiply occurring segments of the VSAM1 data source.

CASE ADDCASE
REPEAT 4 TIMES
COMPUTE QTR_NUM=REPEATCOUNT;
MATCH QTR_NUM
ON MATCH UPDATE GRADE QTR_AVE
ON MATCH GO TO ENDREPEAT
ENDREPEAT
ENDCASE

REPEAT statements cannot be nested - one must end before the next begins.

Also, note use of the phrase GOTO ENDREPEAT for branching to the end of the REPEAT statement. REPEATCOUNT is a FOCUS variable that is incremented each time the REPEAT is executed.


Information Builders