Page 1 of 1

Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 1:48 pm
by Prashant Ranade
For a file having just one row of data if ever, is of FB andLRECL 80. Along with that if the file is empty, I need to check if the file has some data. But the problem is that spaces are not considered as data.

I used IDCAMS REPRO with COUNT(1) but it does not flag the file as EMPTY as there are spaces.

Can you please help me?

Re: Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 2:41 pm
by Akatsukami
Why not just do a read on it and, if you do not get an EOF condition, check if the record has a non-space in it?

Re: Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 4:08 pm
by vikriih
use the following code

Code: Select all

//ST010   EXEC PGM=IDCAMS                                
 //SYSOUT   DD SYSOUT=*                                  
 //SYSPRINT DD SYSOUT=*                                  
 //FILEIN   DD DSN=TSO.REC.IN,DISP=SHR      
 //SYSIN    DD *                                          
   PRINT INFILE(FILEIN) -                                
       CHARACTER COUNT(1)  
It should return a return code of 4 if the dataset is empty

Re: Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 4:13 pm
by enrico-sorichetti
a plain utility will not do...

NON empty in this context means significant data
which means at least ONE NON blank record

for idcams a record containing just blanks is ... A RECORD

Re: Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 4:20 pm
by nicc
Cannot do it with JCL - JCL does not look at data. Your sort product may be able to do it - include where String Search finds data in 1 to 80 > x'40' and stop after 1 record.

Re: Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 7:58 pm
by Akatsukami
Prashant-kun, you'll likely also want to use the NULLOUT opton to have DFSORT or Syncsort give a non-zero return code if the data set is empty.

Re: Checking the Data existence in a file.

Posted: Mon Oct 26, 2015 8:37 pm
by zprogrammer
Prashanth,

Do you expect multiple records with SPACE?