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

In cobol to know whether file is empty or not


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
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 Replace each space in cobol string wi... COBOL Programming 3
Search our Forums:

Back to Top