I have a requirement , where i need to keep reading a VSAM (KSDS) sequentially and check for a condition , if the read record satisfies the condition i need to remove the record from the VSAM and continue with the Next record , If i reach the End of FIle , i will issue a delay restart and repeat the whole process again.
My Doubts :
I do a STARTBR and use read next to do the sequential read.
Now can i delete the record simply by using the key and continue with readnext , or
should i issue a ENDBR and store the Key and DELETE and then again STARTBR using the key and continue
Joined: 06 Jun 2008 Posts: 8231 Location: Dubuque, Iowa, USA
From the CICS Programming Guide manual (link at the top of the page), section 18.104.22.168:
To end the browse, use the ENDBR command. There is no RIDFLD for this command. Trying to browse past the last record in a file raises the ENDFILE condition. You must issue the ENDBR command before performing an update operation on the same file (a READ UPDATE, DELETE with RIDFLD, or WRITE command). If you do not, you get unpredictable results, possibly including deadlock within your own transaction.
Joined: 14 Jan 2008 Posts: 2504 Location: Atlanta, Georgia, USA
If the file is defined to LSR and you issue a STARTBR, READNEXT and then a DELETE before issuing an ENDBR, you're going to have big trouble, as the CRP (Current Record Pointer) will lose its mind and/or (as Robert has posted from the IBM manual), cause a deadlock.
Besides, IBM highly discourages this sequence.
I first encountered a program in the mid 1980's which was doing this (we were running CICS/OS 1.6.1 at the time) and it was a royal PITA to debug.