Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

File status for empty file when open

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: File status for empty file when open
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    Post subject:
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    Post subject:
Reply with quote

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

Senior Member


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

PostPosted: Tue May 11, 2010 3:10 pm    Post subject:
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

Site Director


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

PostPosted: Tue May 11, 2010 7:55 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
This topic is locked: you cannot edit posts or make replies. session stuck in TPX with status ACL amitc23 CA Products 1 Tue Dec 13, 2016 12:53 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us