View previous topic :: View next topic
|
Author |
Message |
Pavankumar.m Warnings : 1 New User
Joined: 28 Nov 2010 Posts: 53 Location: Mumbai
|
|
|
|
Hi ,
I was trying write into sequential file but was getting return code '48'.
Here i have opened sequential file in sequential mode, and opened in I-O mode.
In this program and i read the sequetial file and if certain criteria met then i will add new record in same file.
Can any one pleas suggest how resolve this error.?
Thanks,
Pavan |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
A file status code 48 (which is what I assume you meant instead of return code '48' -- terminology is critical in IT where similar things may mean very different things, and "return code" only occurs when the program is ended, not on any type of I/O operation) means (from the COBOL Language Reference manual:
Quote: |
The execution of a WRITE statement was attempted on a file not open in
the I-O, output, or extend mode. |
So to answer your question as to how to resolve this error -- OPEN THE FILE, CHECK THE FILE STATUS CODE ON THE OPEN, AND DO NOT ATTEMPT TO WRITE TO THE FILE IF YOU DO NOT GET A 00 FILE STATUS CODE ON THE OPEN. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Also, why do you want to possibly corrupt your input file by writing to it? Create a new file or be prepared to pay for the extra overhead in recovering your input file. |
|
Back to top |
|
|
Pavankumar.m Warnings : 1 New User
Joined: 28 Nov 2010 Posts: 53 Location: Mumbai
|
|
|
|
hi Robert,
Thanks for your time.
While opening the file i am getting status code '00'.
Is there any special consideration i need to take ?..
Even i am able to read the records sucessfully, but only while writing getting isssue.
Thanks,
Pavan Kumar.M |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Are you saying that, for example, you have a 100 record dataset and if the conditions are right when you are record 10 you want to write a record at that point? Well, you cannot as your new record has to go at the end of the file. You can use REWRITE to replace your current record but that is all. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Did you read the COBOL Language Reference manual on the WRITE statement? It starts
Quote: |
6.2.40 WRITE statement
The WRITE statement releases a logical record to an output or input/output file.
When the WRITE statement is executed:
The associated sequential file must be open in OUTPUT or EXTEND mode.
The associated indexed or relative file must be open in OUTPUT, I-O, or EXTEND mode. |
Your file is sequential -- so you posted.
You cannot open it I-O and expect to WRITE to that file. |
|
Back to top |
|
|
Pavankumar.m Warnings : 1 New User
Joined: 28 Nov 2010 Posts: 53 Location: Mumbai
|
|
|
|
Hi Nic,
As per your example, i after reading 10th record, if 10th record matches
certail criterial, then i will adding new record in 11th row.
At this time 11th become 12....at total will be 101 records. No i dont want to write at end.
Thanks,
Pavan. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
What you want to do CANNOT be done the way you want to do it -- period.
Writing a new record occurs at the end of the file -- period.
You may open your file for input, open a DIFFERENT file for output, and copy records from input to output, adding records as appropriate, but you cannot write a new 11th record in the existing file without destroying all records after old record number 10. |
|
Back to top |
|
|
Pavankumar.m Warnings : 1 New User
Joined: 28 Nov 2010 Posts: 53 Location: Mumbai
|
|
|
|
Hi Nic\Robert
Thanks alot for your inputs, as suggested will create new file.
Thanks,
Pavan.M |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
By the way - you do not add a record at a 'row'. A row is a record in a DB2 table. |
|
Back to top |
|
|
|