|
SELCOPY
Examples Menu
Where logic is required to bypass or repeat operations, the GOTO statement
can be used.
The following example processes a tape file with a logical record length of
38, and block size of 3160. The file consists of two different types of
records:
- A header record, is always numeric in position 1 and 2.
- A transaction record, always has 'Z' in position 1.
The file is in ascending sequence of header records, but many header
records may have the same number in positions 1 and 2.
It is required to select only the header records containing '81' in
position 1 and 2, together with their associated 'Z' records, writing them
to tape with an output blksize of 380.
At the same time we require a print of all the '81' Header records that
were selected.
READ TAPE10 LRECL=38 * LRECL reqd for VSE only.
IF POS 1 NE '81'
THEN GOTO GET * Implicit label for 1st logical stmt.
==LOOP== ** Only '81' records drop through to here **
WRITE TAPE11 BLKSIZE=380
IF POS 1 NE 'Z'
THEN PRINT STOPAFT=222 * Limit printing
READ TAPE10 * No need to repeat LRECL.
IF POS 1 GT '81' * 'Z' is < '8'
THEN GOTO EOJ
GOTO LOOP * Prevent automatic GOTO GET.
=LOOPE= * Unref'd label. '=' for readability only
The THEN GOTO GET statement will cause looping around the first READ
statement until we find a record with 81 in position 1. On finding it,
control will drop through to LOOP, our main loop.
Because (for EBCDIC) "Z" is lower than numerics, checking position 1 for greater than
"81" will never be satisfied by a transaction record.
So we keep looping around until either we get End-of-file, or we find a
record with 82 or more in position 1 and 2.
|