The WHEN command is a useful tool for scanning a field and is discussed on page 3-177 of the VISION:Report Reference Guide 16.1.
Scanning fixed length fields and records is straightforward, but what do you do if the record you are scanning is of a variable length?
To scan the entire record, first define a single field that spans the maximum length of the record:
EQU INDATA INF5-8202
However, if you scan INDATA like this you will always scan 8202 bytes, which will be beyond the end of the record in many cases.
WHEN has an optional parameter that allows you to specify the length as a variable.
Note the flddef3 parameter:
WHEN flddef1 INCLUDES C'xxx' flddef3
Flddef3 must be a binary field, 2 or 4 bytes long, that contains the value indicating the length of data to be scanned.
For a standard, variable length file, the record length should be in the first 2 bytes of the record:
EQU INLENG INF1-2-B
If it is a VSAM file, it is in VAL 243-246, so the field definition would be
EQU INLENG VAL243-246-B
In either case, to scan this entire variable record, but not past the end, your logic would be resemble this:
WHEN INDATA INCLUDES C'XYZ' INLENG