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
 

 

In cobol to know whether file is empty or not

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ranjeeth03

New User


Joined: 24 May 2007
Posts: 1
Location: hyderabad

PostPosted: Mon Jun 25, 2007 1:30 pm    Post subject: In cobol to know whether file is empty or not
Reply with quote

hw to code in cobol to knw whether file is empty or not?
Back to top
View user's profile Send private message

krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Jun 25, 2007 2:00 pm    Post subject:
Reply with quote

ranjeeth03
Try this:
1. read the i/p file once.
2. Check if you have reached end of file, if so then its empty.
Back to top
View user's profile Send private message
somnath

New User


Joined: 21 Mar 2005
Posts: 18
Location: India

PostPosted: Mon Jun 25, 2007 2:01 pm    Post subject: Re: in cobol to knw whether file is empty?
Reply with quote

If you are going to read the Empty file it will get into the AT END condition.
If you use a RECORD-READ counter to track the no. of records read you will find that the value of this counter will be zero.
The code will be something like below:

MOVE ZEROES TO RECORD-COUNTER.

READ Input-File
AT END
DISPLAY 'End of File.'
NOT AT END
ADD 1 to RECORD-COUNTER
END-READ.
Back to top
View user's profile Send private message
cvadlamudi

New User


Joined: 19 Apr 2007
Posts: 68
Location: India

PostPosted: Mon Jun 25, 2007 3:38 pm    Post subject:
Reply with quote

Hi,

When u try to read an empty input file then the file-status will be NON ZERO (i.e) 35.
so check the file status if it is '35' then u read an empty input file.
Then abort or do the exception wat ever u need.

Regards,
Mouli
Back to top
View user's profile Send private message
dr_te_z

New User


Joined: 08 Jun 2007
Posts: 71
Location: Zoetermeer, the Netherlands

PostPosted: Mon Jun 25, 2007 3:49 pm    Post subject:
Reply with quote

Be carefull with "empty files" on the mainframe. Whenever a dataset (=file) is catalogued (by means of an IEFBR14 step) 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.
This can be accomplised "on the drawing board" by means of JCL or coding standards.
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Mon Jun 25, 2007 5:18 pm    Post subject:
Reply with quote

Dear cvadlamudi,

File status 35 would not be for end-of-file. Typically it shd be 10

So after the first read st. check for FS=10 if so print the file is empty

This can also be done by using ICETOOL from JCL don't remember the xact control card st.

Thamilzan.
Back to top
View user's profile Send private message
cvadlamudi

New User


Joined: 19 Apr 2007
Posts: 68
Location: India

PostPosted: Mon Jun 25, 2007 5:44 pm    Post subject:
Reply with quote

Hi,

File status 10 indicates end of file (i.e) you have opened the infile properly & read the data.
But in case if the file is empty you cannot open the file itself. so immediately after opening the file u will get the file status as 35 and no need to read the file & u can't read the file.

ex : OPEN input INFILE.
IF INFILE-STATUS = 35
Perform your logic to abort or what ever ur option
END-IF

Thanks,
Mouli
Back to top
View user's profile Send private message
ramfrom84

New User


Joined: 23 Aug 2006
Posts: 93
Location: chennai

PostPosted: Mon Jun 25, 2007 8:28 pm    Post subject:
Reply with quote

Hi All,
It is simple to find Empty File or Not..See the below code to find it.

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
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 Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm


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