IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Update and write sequential file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Deepakgoyal2005

New User


Joined: 22 Mar 2007
Posts: 57
Location: India

PostPosted: Wed Dec 19, 2012 1:36 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Dec 19, 2012 1:47 pm
Reply with quote

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
View user's profile Send private message
Deepakgoyal2005

New User


Joined: 22 Mar 2007
Posts: 57
Location: India

PostPosted: Wed Dec 19, 2012 1:54 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Dec 19, 2012 1:54 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Dec 19, 2012 10:55 pm
Reply with quote

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
View user's profile Send private message
Jose Mateo

Active User


Joined: 29 Oct 2010
Posts: 121
Location: Puerto Rico

PostPosted: Thu Dec 20, 2012 8:06 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Binary File format getting change whi... All Other Mainframe Topics 5
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
Search our Forums:

Back to Top