Hi everyone,
I have a situation which requires me to open the same file in two different mode in a single COBOL program. Can we do that?
OPEN the file in two different modes in COBOL.
-
- Registered Member
- Posts: 18
- Joined: Sat Sep 27, 2014 9:13 pm
-
- Registered Member
- Posts: 18
- Joined: Sat Sep 27, 2014 9:13 pm
Re: OPEN the file in two different modes in COBOL.
I should have elaborated it. The situation goes like this:
Open a file in the program and if the file is empty write header data and the details to file. However in case the file is not empty we need to write the details only and not the header.
Is there any way to toggle between the modes within the program, let's say: Open the file in input mode, then followed by reading and close it . Later open the file in output mode and do the write? Is it allowed?
Thanks,
Open a file in the program and if the file is empty write header data and the details to file. However in case the file is not empty we need to write the details only and not the header.
Is there any way to toggle between the modes within the program, let's say: Open the file in input mode, then followed by reading and close it . Later open the file in output mode and do the write? Is it allowed?
Thanks,
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: OPEN the file in two different modes in COBOL.
You need to be careful here. IBM distinguishes between a data set which has never had any data written to it versus a data set that has been written to but has no records now. In the first case, you cannot read the data set so your application design fails. In the second case, there is no problem with reading.if the file is empty
Furthermore, if you are not specifying DISP=MOD for the data set, then your output statements will replace every record in the data set so you will lose your header data.
Yes, it is allowed.Open the file in input mode, then followed by reading and close it . Later open the file in output mode and do the write? Is it allowed?
-
- Registered Member
- Posts: 18
- Joined: Sat Sep 27, 2014 9:13 pm
Re: OPEN the file in two different modes in COBOL.
This is very compelling. If a data set was never written to, as you said, how can the data set even exist? Is not it like that it never existed?Robert Sample wrote: ↑Tue Jan 31, 2023 7:42 pmYou need to be careful here. IBM distinguishes between a data set which has never had any data written to it versus a data set that has been written to but has no records now. In the first case, you cannot read the data set so your application design fails. In the second case, there is no problem with reading.
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: OPEN the file in two different modes in COBOL.
Use JCL utility IEFBR14. This utility allows you to create data sets in JCL, but it does not access that data set. So the data set exists, can be cataloged, but has never been written to. Any JCL can allocate data sets but unless the program being executed opens that DD statement for output, it will not be written to.This is very compelling. If a data set was never written to, as you said, how can the data set even exist? Is not it like that it never existed?
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute