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
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8697
Location: Back in jolly old England

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: 647
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
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8697
Location: Back in jolly old England

PostPosted: Thu Jun 28, 2018 6:26 pm    Post subject:
Reply with quote

So obviously you HAVE NOT picked up on the difference between a FILE and a DATASET.

So let me see if your thought pattern is correct ......
You have a PS DATASET on DASD and you want to add a record into said DATASET. So where exactly will this data be written, over the top of the next sequential record perhaps ... oh no, that wouldn't work would it, because you will blat the next record in the DATASET

As Steve-myers has said previously , using the same DATASET as both input and output is not a good idea.

It would work with a VSAM KSDS but certainly not with a PS DATASET. If however you had an input DATASET and a different output DATASET it might work.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8363
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: 429
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
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1942
Location: NY,USA

PostPosted: Thu Jun 28, 2018 10:23 pm    Post subject:
Reply with quote

Why do you need COBOL Program to do this task? Learn DFSORT and use JOINKEYS to get your desired results.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 715
Location: Pennsylvania

PostPosted: Thu Jun 28, 2018 11:34 pm    Post subject:
Reply with quote

Give the poor guy a break.

The COBOL reference has the word FILE listed 1,820 times.

The term DATASET (one word is found ZERO times).

The term DATA SET (two words is found 35 times).

Here is a snippet.
Quote:
file-control-paragraph
Names the files and associates them with the external data sets.
Must begin in Area B with a SELECT clause. It must end with a separator
period. See “FILE-CONTROL paragraph” on page 132.
file-control-paragraph can be omitted if there are no files defined in the
program, even if the FILE-CONTROL keyword is specified.


You make such a huge deal about the difference, but from the COBOL perspective, they are referring to much the same thing.
This is the COBOL forum correct?

It may be a dataset in the JCL, but inside the COBOL program it is a FILE.
One thousand eight hundred references in the manual tells me that.

So give it a rest already, and consider the possibility that you may be mistaken.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2035
Location: UK

PostPosted: Fri Jun 29, 2018 6:57 pm    Post subject: Reply to: Can we use a file both as input and output in COBOl prog ??
Reply with quote

File in the program connects to the DDNAME in the JCL which connects to the data set name. Files do not have an organisation - they are a sequential stream of bytes. If one is referring to 'file' as per the program then, Fine. If referring to the data set, as in this case, then 'data set' should be used although 'file' would be understood.
Back to top
View user's profile Send private message
jerryte

Active User


Joined: 29 Oct 2010
Posts: 194
Location: Toronto, ON, Canada

PostPosted: Fri Jun 29, 2018 10:39 pm    Post subject: Re: Reply to: Can we use a file both as input and output in COBOl prog ??
Reply with quote

Chiku kumar wrote:
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).

First open the file using
OPEN INPUT file
You can then read and process the records. When finished do:
CLOSE file
then
OPEN EXTEND file
Then you can WRITE to append records to end of the file

Note: the SEARCH cobol statement is for searching a table that is in memory. It doesn't work on files.
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1942
Location: NY,USA

PostPosted: Sat Jun 30, 2018 4:12 am    Post subject:
Reply with quote

jerryte, how is it different than RahulG31?
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 How to manage VSAM file update confli... ocjohnh JCL & VSAM 2 Sat Jul 21, 2018 6:04 am
No new posts Need Help to Create 4 Output Records ... satish.ms10 DFSORT/ICETOOL 4 Thu Jul 19, 2018 1:55 am
No new posts finding anydata between positions of ... ram_vizag SYNCSORT 13 Tue Jul 17, 2018 9:14 pm
No new posts KSDS file fields update by passing va... Anil Kumar Prajapati TSO/ISPF 5 Wed Jul 11, 2018 5:59 am
No new posts Comparing inside same file vickey_dw DFSORT/ICETOOL 2 Tue Jul 10, 2018 9:51 pm

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