Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Update and write sequential file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Update and write sequential file
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10375
Location: italy

PostPosted: Wed Dec 19, 2012 1:47 pm    Post subject: Reply to: Update and write sequential file
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7314

PostPosted: Wed Dec 19, 2012 1:54 pm    Post subject: Reply to: Update and write sequential file
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

Site Director


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

PostPosted: Wed Dec 19, 2012 10:55 pm    Post subject:
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: 112
Location: Puerto Rico

PostPosted: Thu Dec 20, 2012 8:06 pm    Post subject: Reply to: Update and write sequential file
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts File Tailoring -- Temporary dataset i... samzee71 CLIST & REXX 3 Fri Dec 01, 2017 3:12 am
No new posts Rexx - File tailoring samzee71 CLIST & REXX 10 Thu Nov 30, 2017 10:47 pm
No new posts Moving a PS file as body of a mail! Vignesh Sid JCL & VSAM 4 Tue Nov 21, 2017 9:23 pm
No new posts unable to set RC = 4 when empty file migusd SYNCSORT 1 Tue Nov 21, 2017 1:21 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us