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

Can we use a file both as input and output in COBOl prog ??


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

New User


Joined: 21 Jun 2018
Posts: 4
Location: India

PostPosted: Thu Jun 28, 2018 3:30 pm
Reply with quote

Can we use a file both as input and output in COBOL program
example: We need to search the file if record not present write to that same file


Thanks


Topic cleaned: By random admin, not me :-P
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Thu Jun 28, 2018 3:56 pm
Reply with quote

Your explanation of the requirement is too vague to answer the question.

What do you write to the same DATASET, which type of DATASET are you talking about, VSAM ESDS, VSAM KSDS, VSAM RRN sequential on DASD, sequential on tape, PDS, PDSE ....................

Are we using DB2 or IMS or ADABAS or what ???

Each and every option may possibly have a different solution.

Please explain with lots of deatil what you wish to achieve.
Back to top
View user's profile Send private message
steve-myers

Active Member


Joined: 30 Nov 2013
Posts: 917
Location: The Universe

PostPosted: Thu Jun 28, 2018 4:07 pm
Reply with quote

Yes, but it's not a good idea. Any mistake in your program will effectively destroy the data set. Notice I say "data set." The only "files" in OS/360 derived systems like MVS or z/OS is data on magnetic tape. A "file" as used in *nix or Windoze ia just a stream of bytes. A "data set" is also a stream of bytes organized into records and possibly higher level structures as in a partitioned data set or a VSAM data set.

In general it is not possible to insert data into a sequential data set (as you appear to propose) except by rewriting the data set from the beginning. It is possible, though somewhat difficult, to update data in a sequential data set.
Back to top
View user's profile Send private message
Chiku kumar

New User


Joined: 21 Jun 2018
Posts: 4
Location: India

PostPosted: Thu Jun 28, 2018 5:08 pm
Reply with quote

Its a sequential on DASD file which I want to search first using SEARCH option in COBOL and then I want to write a record into the same file IF the record doesn't already exist in the file (Unique records should be written to the file).
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: Thu Jun 28, 2018 7:51 pm
Reply with quote

Quote:
Its a sequential on DASD file which I want to search first using SEARCH option in COBOL
The SEARCH verb in COBOL applies ONLY to tables -- not data sets, not files, only tables. Hence your basic premise is flawed.
Quote:
then I want to write a record into the same file IF the record doesn't already exist in the file (Unique records should be written to the file).
What you want to do is not possible. From the Enterprise COBOL Language Reference manual version 6.2 page 489 with emphasis added by me:
Quote:
WRITE statement
The WRITE statement releases a logical record to an output or input/output file.
When the WRITE statement is executed:
v
The associated sequential file must be open in OUTPUT or EXTEND mode.
v
The associated indexed or relative file must be open in OUTPUT, I-O, or EXTEND mode.
And since you cannot read from a COBOL file opened for OUTPUT or EXTEND mode, it is therefore obvious that you ask for the impossible. It could be done with a VSAM KSDS but not for any form of sequential data set.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Thu Jun 28, 2018 9:17 pm
Reply with quote

Chiku Kumar,

You have to open in Input mode, then Close and again open in Extend mode

.
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Mon Aug 06, 2018 6:10 pm
Reply with quote

Just want to confirm this is a bad idea except with vsam files. Depending on various factors, there are cases where you CAN do this with COBOL and other programs, but it's really a bad idea for so many reasons.

Do yourself and your support staff a favor and avoid writing to the input file except for vsam. 'File' as in defined as input in the 'FILE SECTION'.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
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
No new posts How to split large record length file... DFSORT/ICETOOL 10
Search our Forums:

Back to Top