Page 1 of 1
What happens when we reopen a ps file and start reading.
Posted: Mon Feb 13, 2023 2:02 pm
by Rahul
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?
Re: What happens when we reopen a ps file and start reading.
Posted: Mon Feb 13, 2023 9:28 pm
by Robert Sample
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.
Posted: Mon Apr 24, 2023 10:18 pm
by Rahul
why 'open' is so important in COBOL? Is this applicable to Windows and or Linux too, I've not heard about it?
Re: What happens when we reopen a ps file and start reading.
Posted: Tue Apr 25, 2023 6:28 pm
by Robert Sample
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.
Posted: Mon Jun 12, 2023 11:07 am
by Rahul
Thanks.
But is it recommended to have multiple opens for a file in the COBOL program?
Re: What happens when we reopen a ps file and start reading.
Posted: Tue Jun 13, 2023 12:01 am
by Robert Sample
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.