Hi,
This was asked in an interview and I was not very sure of the answer. The question was:
What happens when we reopen a ps file and start reading
I mean it will read from Beginning or it will read from where it left?
I thought compiler will give error if we re-open in the same program, right?
What happens when we reopen a ps file and start reading.
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What happens when we reopen a ps file and start reading.
As long as the file is closed before being reopened, this will not generate any kind of compiler error and is quite acceptable. The reopen causes the file to be read from the first record again.
Re: What happens when we reopen a ps file and start reading.
why 'open' is so important in COBOL? Is this applicable to Windows and or Linux too, I've not heard about it?
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What happens when we reopen a ps file and start reading.
Windows and Linux machines open files as well -- but implicitly for the most part. COBOL being well over 50 years old needs the open explicitly stated.
Re: What happens when we reopen a ps file and start reading.
Thanks.
But is it recommended to have multiple opens for a file in the COBOL program?
But is it recommended to have multiple opens for a file in the COBOL program?
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: What happens when we reopen a ps file and start reading.
It is rare to open one file more than once in a COBOL program. I've done it a few times in my last 48 years of writing COBOL code but the total can be counted on my fingers.
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