Highlighted
Super Contributor.
Super Contributor.
80 views

How to check if file is empty in microFocus cobol without reading the file??

Hi,

when I am reading  empty file, it gives error status as 10...

But, i just wanted to know , How to check if file is empty in microFocus cobol without reading the file??

I need to display the message to user  as "No record in  CM file" in case   file is empty without reading.

See my logic

open  input CM-FILE

Read CM-FILE-REC

 

 

 

 

 

 

 

 

0 Likes
2 Replies
Highlighted
Super Contributor.
Super Contributor.

Re: How to check if file is empty in microFocus cobol without reading the file??

Also, when i  Read CM-FILE-REC , immediately given error status as 10 and abended with error and my complete application is getting closed.

after read , just i thought to  keep condition to check status and send message to user ,then no use...

 

 

0 Likes
Highlighted
Super Contributor.
Super Contributor.

Re: How to check if file is empty in microFocus cobol without reading the file??

I'll answer your problem/error first, then try and answer the question you actually asked.

1. To avoid the read generating an error message and existing the program, add a DECLARATIVE SECTION.  Add this file to that section.  This traps all file errors, and you can decide what (if anything) to do with the error.  After the declarative section finishes processing, if it simply exits, control returns to the program right after the IO command that triggered the error.  I recommend this method.

2. If the file is sequential or relative, then an empty file would be zero bytes.  You can use C$FILEINFO utility in this case to see what the size is before opening the file. 

3. If the file is indexed, you can use the I$IO utility to "open" the file, then use the INFO-FUNCTION to find out how many records are in the file

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.