Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Empty Dataset determination

Status
Not open for further replies.

balajipn

Programmer
Mar 30, 2004
65
IN
Hi,

I have a new requirement. I need to find out if a dataset is empty or not. If the dataset is empty, I need to display a message and if it is not, I need to view the dataset with ISPEXEC VIEW DATASET command.

Is there a way to find out if a dataset is empty or not?. The dataset would have been allocated, but may be empty or not.

Thanks,
Balaji.
 
hi Balaji,
the variable SYSUSED from the function LISTDSI is what you are looking for.

SYSUSED Allocation used, in space units

/* REXX */
DSNAME = "'DV20HEY.DSFP1101.COBOL'"
x=LISTDSI(DSNAME)
if DATATYPE(SYSUSED) = 'NUM' then do
if SYSUSED > 0 then
ADDRESS ISPEXEC "BROWSE DATASET(" DSNAME ")"
else
Say 'Dataset is empty'
end
else
say "Dataset not exists!"
exit

i hope its help...

cu
kai
 
Hi kai,

Thanks for your reply.

The LISTDSI function is not implemented in our TSO environment. For now, I have used the following code to see if it is empty or not.

"ALLOC DA ("DSNAME") F(JCL) SHR REUSE"
IF RC <> 0 THEN DO
SAY "DSN ALLOCATION FAILED."
EXIT 1
END
"EXECIO 0 DISKR JCL (OPEN"
"EXECIO * DISKR JCL (STEM J0."
"EXECIO * DISKR JCL (FINIS"
"FREE F(JCL)"

IF J0.0 <> 0 THEN
ADDRESS ISPEXEC "VIEW DATASET("DSNAME")"
ELSE DO
DROP J0.
SAY "DATASET IS EMPTY"
EXIT 1
END
DROP J0.

In the above code, I am reading all the lines of the dataset into a STEM variable and checking for its STEM.0 variable to see if the dataset is empty or not.

It works fine.

How different is LISTDSI command from LISTDS?. LISTDS is supported in our TSO environment.

Thanks,
Balaji.


 
Alternative solution: Make an edit macro SIZECHEK, put it in a library that you have allocated to SYSPROC or SYSEXEC.
Code:
/* rexx */
address ispexec;
   'ISREDIT MACRO';
   'ISREDIT (DSIZE) = LINENUM .ZLAST';
if dsize = 0 then 'ISREDIT CANCEL';
return 0;
Then, your original program just reduces to
Code:
/* rexx */
'VIEW DATASET(SOURCE.REXX(EMPTY)) MACRO(SIZECHEK)';
if dsize = 0 then say 'Dataset was empty' dsize;
This gets rid of all the messing about with ALLOC and EXECIO.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top