How to open the same file in two different programs in one execution ?
Here's the situation explained in more detail.
There are two programs, PGM1 and PGM2. PGM1 is in PLI version and PGM2 is in EPL/I version.
These two programs are executed in batch mode through a job.
PGM1 gets kicked off by the job and it opens the file FILE1 in OUTPUT mode and writes some records to the FILE1. After writing some records to the FILE1, without closing the file FILE1, the PGM1 calls PGM2 and PGM2 opens the FILE1 again in OUTPUT mode to write some recods. When the FILE1 is opened in PGM2, the records written to FILE1 by PGM1 are wiped off and FILE1 now has only records written by PGM2. There is no explicit CLOSE for the file FILE1 in PGM2. After PGM2 execution is over, the control goes back to PGM1. The job completes with S414-08 error code. It looks like the PGM1 is attempting to write some of the records to FILE1 stored in the BUFFER storage. It looks like the program is not able to locate the records stored in the buffer storage written by PGM1 and hence the job ends with completion code S414-08.
The description for S414-08 given as
S414 - 08 - FOR A QSAM DATA SET EITHER AN I/O ERROR OCCURRED WHILE
FLUSHING THE BUFFERS DURING CLOSE PROCESSING, OR A CLOSE WAS
ISSUED IN THE CALLER'S SYNAD ROUTINE.
I would like to know how to handle this situation where the same file is opened in both PGM1 and PGM2 and how to correctly get the records written into FILE1 by both program PGM1 and PGM2.
The file FILE1 is a sequential file and it's declared as
DCL FILE1 OUTPUT RECORD ENV(FB RECSIZE(133) CTLASA TOTAL);
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
Quote:
I would like to know how to handle this situation where the same file is opened in both PGM1 and PGM2 and how to correctly get the records written into FILE1 by both program PGM1 and PGM2.
You don't -- you've got a faulty design here. Opening the same sequential file in two programs running at the same time and attempting to write records to the file from both programs is a sure recipe for file corruption and abends. A process redesign is in order. Open the file, write the records, close the file then let the other program at the file to do the same. Or you could use VSAM with share options (but plan on writing enqueue and dequeue logic as well to ensure the file isn't corrupted by your writes).
Writing records to a file is a form of serialization on the file: that's why VSAM shareoption 2 allows as many as desired to READ the file, but only ONE to write the file. Two processes both writing to the file violates serialization and unpredictable results, at best, will occur -- and abends or file corruption are likely.