View previous topic :: View next topic
|
Author |
Message |
Deepakgoyal2005
New User
Joined: 22 Mar 2007 Posts: 57 Location: India
|
|
|
|
I have a requirement wherein I have to update and add records to a sequential file.
Input:
File 1 has 1 record: F1D1 F1D2
File2 has 1 record: F2D1 F2D2
Cobol code process:
If F2D1 = 0, MOVE F1D2 TO F2D2 and update record
If F2D1 NOT = 0, add new record to File2 with field values in File1.
Problem:
I had opened File2 in IO mode. The Cobol code is able to update File2 but fails while writing a new record with FILE-STATUS = 48 for file2.
Let me know if anybody could help on this? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
it is very UNWISE to access a sequential file in INPUT/OUTPUT mode
the proper approach is to read file1, file2 producing file3 with the updated added records
after that a couple of renames would put things back in place with the <proper> names
or better review the whole setup by using GDGs |
|
Back to top |
|
|
Deepakgoyal2005
New User
Joined: 22 Mar 2007 Posts: 57 Location: India
|
|
|
|
Thanks Enrico for your response.
Just 1 more question. With sequential files we can use update and write in IO and OUTPUT mode respectively. Is there anything we can play around with ORGANIZATION or MODE or FILE-type to update and write a file in same cobol code? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
enrico is correct, that would be a horrible way to approach the requirement.
Despite that, the "4" in your status-code is "logic error". The "8", when it is "logic error", is
Quote: |
"The execution of a WRITE statement was attempted on a file not open in the I-O, output, or extend mode. " |
So, the run-time is telling you that you do not have the file open in the way that you think you do. Never let slip an opportunity to follow-up on messages and errors. Understand this exactly, then (so that when you come across it "for real" you already are a good way along getting the answer) and then throw away the code and start again, in the manner that enrico has outlined. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
FWIW, None of my clients will permit code to update a sequential file. There needs to be a new output file with the adds/changes created.
Many make this a gdg. . . |
|
Back to top |
|
|
Jose Mateo
Active User
Joined: 29 Oct 2010 Posts: 121 Location: Puerto Rico
|
|
|
|
Good day to all!
I totally agree with Enrico and everybody else on not using I-O mode to update sequential file. But you could use the I-O mode to update a sequential file but you can't write a new record to the file because then you will be appending a record to the file and the extend mode is use for this purpose. With I-O mode you could read and rewrite record but not write. In order to write (add) a record to the file you must close the file and reopen it with the extend mode but is not practical to open, close and reopen a file when needed. |
|
Back to top |
|
|
|