Joined: 06 Jun 2008 Posts: 8417 Location: Dubuque, Iowa, USA
Yes. Open statement 1 time and close statement 1 time. Also, these statements are executed only once.
The count of open / close statements is irrelevant. And how do you KNOW they are executed only one time? Unless you do something like put DISPLAY statements in the code to prove the number of times they open / close the file, you are merely guessing about the number of executions. The behavior you described sounds precisely and exactly like the file was opened more than one time, and there have been plenty of examples on this forum of code "falling through" and executing statements the TS did not realize were executing.
put that in your jcl before your cobol program. do that to delete and uncatalog your file. strangely it seems as though the new z/OS is more forgiving and will do that for you like in UNIX however it is safer to do it explicitly so you don't have to keep doing it manually.
Next if you indeed have only run those open/close instructions just once in your program and have written to that file in the mean time then you're okay. in fact you might wish to take advantage of the cobol compiler that has been out there for decades now and not even write the close instruction!!!!!
that's right. the compile will do your work for you. take out
000523 CLOSE I122A-FILE.
still make sure you have your open instruction done ONCE and then of course the write instruction done multiple times until your program has "run out of gas".
also I didn't see an FD. do you have one in your code? also take out the DCB parameters in your JCL as they're already there from your program!!
make sure of course that you have BLOCK 0 in the FD as that really is all you need. remember with cobol - less is better.