IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

File status for empty file when open


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
kudamala

New User


Joined: 12 Sep 2008
Posts: 51
Location: Bangalore

PostPosted: Tue May 11, 2010 2:38 pm
Reply with quote

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
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Tue May 11, 2010 2:49 pm
Reply with quote

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
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue May 11, 2010 2:50 pm
Reply with quote

Try reading a record and check for FILE STATUS
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue May 11, 2010 3:10 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 11, 2010 7:55 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 4
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top