Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts Updating data from one file to other!!! Vignesh Sid SYNCSORT 1 Mon Nov 06, 2017 2:42 pm
This topic is locked: you cannot edit posts or make replies. Need help how to pass the ESP variabl... Venkichaitu JCL & VSAM 12 Thu Nov 02, 2017 3:53 am
This topic is locked: you cannot edit posts or make replies. Comparing current time with the time ... arunsoods SYNCSORT 1 Mon Oct 30, 2017 4:07 pm
No new posts -502 Error - Cursor already open anand jeyapaul DB2 7 Sun Oct 29, 2017 4:22 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us