Joined: 14 Jan 2008 Posts: 2504 Location: Atlanta, Georgia, USA
Your reply indicates that you're issuing a STARTBR, then a READ and then a READNEXT?
If you issue a READ (as opposed to a READNEXT or READPREV) while you're in BROWSE mode, the CRP (current record pointer) will no longer be valid and the well-known IBM condition "unpredictable results may occur" will most likely be raised.
In order to perform a READ while you're in BROWSE mode, you must issue a ENDBR first.
You must also save the current KEY value in WS, so you can begin the BROWSE again (STARTBR) after you're finished with the randomly read record.
To begin browsing again, move the last byte of the key to the last byte of redefined binary-fullword, add 1 to the fullword and move the binary-fullword last byte back to your WS key's last byte.
03 WS-RECORD-KEY PIC X(12).
03 WS-FWORD PIC 9(08) BINARY.
03 WS-FWORD-X REDEFINES WS-FWORD
MOVE ZERO TO WS-FWORD.
MOVE WS-RECORD-KEY (12:) TO WS-FWORD-X (4:).
ADD 1 TO WS-FWORD.
MOVE WS-FWORD-X (4:) TO WS-RECORD-KEY (12:).
In the above example, if the last byte was equal to '9' (X'F9'), it becomes a SOFA' after the addition, which then allows VSAM to point to the next logical record.
However, if the last byte was equal to X'FF' (an oddity, most likely), you would then move bytes 11-12 of WS-RECORD-KEY to bytes 3-4 of WS-FWORD-X, add 1 to WS-FWORD and store it back in WS-RECORD-KEY, bytes 11-12.