View previous topic :: View next topic
|
Author |
Message |
kudamala
New User
Joined: 12 Sep 2008 Posts: 51 Location: Bangalore
|
|
|
|
Hello Friends
I expect that, when we try to open an empty file that shoud give a return code other than '0', but when I try to open an empty file in Cobol, I am getting file status as '0'. Is the correct behaviour or something wrong?
If is is correct, can anybody suggest how can I check an empty file while opening time?
My requirement is to check the file is empty or not.
I just placed a display statment as follows:
OPEN INPUT FA-FILE
DISPLAY 'FA-STATUS:' FA-FSTAT1
I am getting status code as '0' even the file is empty
My file is a flat file with VB lenght 597 |
|
Back to top |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
Hi Ravi,
If I am not mistaken, OPEN statement will only detect whether the file is present or not and link to the current module. If u want to know whether the file is empty you will need to do a single READ statement, which if fails, will denote it is empty... |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Try reading a record and check for FILE STATUS |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Be carefull with "empty files" on the mainframe. If a dataset is catalogued but never opened for output then you should not try to open this dataset for input. You might get an abend. It is more safe to ensure that you have a "real" empty dataset. Having said that, you might use something like this in your COBOL progam:
Code: |
EVALUATE File_Status
WHEN '00'
Perform process_para
read_count = read_count + 1
WHEN '10'
If read_count = 0
then
Display "the File is Empty"
Else
Normal process.
WHEN OTHER
Abend the Program , Read Error |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
I expect that, when we try to open an empty file that shoud give a return code other than '0' |
Change your expectation. . . The people who designed the language had a different expectation - their implementatoin says that an empty file is completely valid. Indeed, it is sometimes quite important.
The status needs to be checked after every READ in addition to checking after the OPEN. |
|
Back to top |
|
|
|