View previous topic :: View next topic
|
Author |
Message |
ranjeeth03
New User
Joined: 24 May 2007 Posts: 1 Location: hyderabad
|
|
|
|
hw to code in cobol to knw whether file is empty or not? |
|
Back to top |
|
|
krisprems
Active Member
Joined: 27 Nov 2006 Posts: 649 Location: India
|
|
|
|
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 |
|
|
somnath
New User
Joined: 21 Mar 2005 Posts: 18 Location: India
|
|
|
|
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 |
|
|
cvadlamudi
New User
Joined: 19 Apr 2007 Posts: 68 Location: India
|
|
|
|
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 |
|
|
dr_te_z
New User
Joined: 08 Jun 2007 Posts: 71 Location: Zoetermeer, the Netherlands
|
|
|
|
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 |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
cvadlamudi
New User
Joined: 19 Apr 2007 Posts: 68 Location: India
|
|
|
|
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 |
|
|
ramfrom84
New User
Joined: 23 Aug 2006 Posts: 93 Location: chennai
|
|
|
|
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 |
|
|
|