Unable to write in the file



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Unable to write in the file

Postby nm992 » Mon Oct 31, 2011 10:32 pm

Hi..

I have a file in which i need to read 4 fields..and after meeting some condition..need to update the status for each record in the same file in field say 5.

I declared the file as i-o and access mode is sequential..

The way I am doing is

Read the file
check the condition
move "fail' to status
Write file.

But I am getting file status 48.and the status is not being written.

Can anyone please suggest where am i wrong?
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Unable to write in the file

 

Re: Unable to write in the file

Postby dick scherrer » Mon Oct 31, 2011 10:35 pm

Hello,

Do not try to re-write this sequential file - there is no good reason to do so. Well managed organizations will not even permit this.

Read the "input", make the changes, and write the output.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Unable to write in the file

Postby nm992 » Mon Oct 31, 2011 11:01 pm

hi Dick..

I did not get what you tried to say.

my quest is my File has 5 fields..
Field 1 ,Filed 2 ,Field 3,Field 4,Field 5

Field 5 is empty.I need to do some processing for field 1 to 4 and need to update Field 5.

Should I write in a seperate file and then merge Field 1 to Field 4 and output file..
nm992
 
Posts: 43
Joined: Sun Jul 11, 2010 11:31 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Unable to write in the file

Postby Robert Sample » Tue Nov 01, 2011 12:45 am

Should I write in a seperate file and then merge Field 1 to Field 4 and output file..
Yes, absolutely -- you never want to attempt to do input AND output processing on a sequential file. Period. Use one file for input and one file for output. What you do with the fields (whatever THAT means -- files have records and each record has columns)is totally up to you and your program.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Unable to write in the file

Postby dick scherrer » Tue Nov 01, 2011 12:51 am

Hello,

Read the "input" data (4 fields with data and one empty field) and write the 5-field data into a new file.

There need be no "merging" - this should be a simple read A and write B process.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Unable to write in the file

Postby BillyBoyo » Tue Nov 01, 2011 1:01 am

It would be worth checking on the error code you got. There is a table in the Cobol manuals. There is a discrepency between the type of file you are using, the type of open you are using, and the type of write that you are doing.

If you have a sequential file (DSORG=PS) then read input file, write seperate output file as has been suggested to you already. If you have a VSAM file, your requirement may be to update it in place. Check exactly how you are achieving the rewriting against what is in the manual - and remember to back-up the file before your job runs, and to restore the file before your job re-runs in the event of failure/error.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Unable to write in the file

Postby Ed Goodman » Tue Nov 01, 2011 7:34 pm

I have a hunch that you are trying to change the record length. To use REWRITE, the record length has to stay the same. Remember, you are trying to replace the record in the SAME SPOT on the media.

Oh, and don't use REWRITE. It's the cause of great sorrow and misery around the world.
Ed Goodman
 
Posts: 342
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: Unable to write in the file

Postby Ed Goodman » Tue Nov 01, 2011 7:36 pm

Ahh, wait...
manual says a "48" means
The execution of a WRITE statement was
attempted on a file not open in the I-O,
output, or extend mode.

So...are you using the "WRITE" verb, or the "REWRITE" verb?
Ed Goodman
 
Posts: 342
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: Unable to write in the file

Postby dick scherrer » Tue Nov 01, 2011 9:43 pm

Hello,

As most places will not allow a process to overwrite an input qsam dataset, i suggest this not be pursued any further. If this was a vsam file, sure have at the re-write.

The most widely accepted way to do this that i've seen is to read the input and write a new output with the required changed/new data.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post