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 editting the file by inserting zeros ... pramodrsingh DFSORT/ICETOOL 9 Mon Aug 21, 2017 5:58 pm
No new posts Match two files using multiple keys a... santoshks1987 SYNCSORT 11 Fri Aug 18, 2017 10:50 am
No new posts Multiple VSAM files single output fil... Mohan Kothakota DFSORT/ICETOOL 11 Wed Aug 09, 2017 7:57 pm
This topic is locked: you cannot edit posts or make replies. rexx code to create a ps file Bharath Vikraman CLIST & REXX 4 Mon Aug 07, 2017 10:30 am
No new posts Split file based on comparsion to 2 f... Div Grad DFSORT/ICETOOL 3 Thu Jul 27, 2017 9:16 pm


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