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

Error 48 while writing into sequential file in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Pavankumar.m
Warnings : 1

New User


Joined: 28 Nov 2010
Posts: 53
Location: Mumbai

PostPosted: Tue Jul 23, 2013 7:02 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jul 23, 2013 7:06 pm
Reply with quote

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

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue Jul 23, 2013 7:11 pm
Reply with quote

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
View user's profile Send private message
Pavankumar.m
Warnings : 1

New User


Joined: 28 Nov 2010
Posts: 53
Location: Mumbai

PostPosted: Tue Jul 23, 2013 7:16 pm
Reply with quote

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

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue Jul 23, 2013 7:21 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jul 23, 2013 7:22 pm
Reply with quote

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
View user's profile Send private message
Pavankumar.m
Warnings : 1

New User


Joined: 28 Nov 2010
Posts: 53
Location: Mumbai

PostPosted: Tue Jul 23, 2013 7:28 pm
Reply with quote

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Jul 23, 2013 7:35 pm
Reply with quote

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
View user's profile Send private message
Pavankumar.m
Warnings : 1

New User


Joined: 28 Nov 2010
Posts: 53
Location: Mumbai

PostPosted: Tue Jul 23, 2013 7:39 pm
Reply with quote

Hi Nic\Robert

Thanks alot for your inputs, as suggested will create new file.

Thanks,
Pavan.M
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Tue Jul 23, 2013 7:40 pm
Reply with quote

By the way - you do not add a record at a 'row'. A row is a record in a DB2 table.
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 FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Error to read log with rexx CLIST & REXX 11
Search our Forums:

Back to Top