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
 
Can we use a file both as input and output in COBOl prog ??

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Can we use a file both as input and output in COBOl prog ??
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: 8734
Location: Welsh Wales

PostPosted: Thu Jun 28, 2018 3:56 pm    Post subject:
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: 672
Location: The Universe

PostPosted: Thu Jun 28, 2018 4:07 pm    Post subject:
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    Post subject: Reply to: Can we use a file both as input and output in COBOl prog ??
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: 8405
Location: Dubuque, Iowa, USA

PostPosted: Thu Jun 28, 2018 7:51 pm    Post subject:
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: 444
Location: USA

PostPosted: Thu Jun 28, 2018 9:17 pm    Post subject: Reply to: Can we use a file both as input and output in COBOl prog ??
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: 184
Location: USA

PostPosted: Mon Aug 06, 2018 6:10 pm    Post subject: Experience teaches not to do this except with VSAM files!
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    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 Accessing control blocks to retrieve ... menonkiran COBOL Programming 4 Wed Nov 14, 2018 9:08 pm
This topic is locked: you cannot edit posts or make replies. DFSORT output in CSV for data spans i... hiravibk DFSORT/ICETOOL 3 Tue Nov 13, 2018 7:55 pm
No new posts Will this code extract 1 byte from fi... pkmurali CLIST & REXX 8 Sat Nov 10, 2018 11:13 pm
No new posts REFORMATTING WITH JFY CLOBBERING OUTP... speermb DFSORT/ICETOOL 12 Thu Nov 08, 2018 7:20 pm
No new posts Error reading file in REXX module ashek15 CLIST & REXX 3 Wed Oct 24, 2018 4:50 am

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