Q

Is the file empty in CL?

I need to know if a file is empty or not in a CL. I want a program to run only if there are records in the file. On the S/36 there was a command to check the number of records. Is there a way on the iSeries?
There isn't any command I'm aware of to return the number of records in a file but you could easily create one with these steps.


CHKF (Check file command) to create:

CHKF FILE(MYLIB/MYFILE) NBRRCDS(&NBR)

The second parm in this command definition is a return variable type to return the record number to the caller. Running interactively, this should take about one or two seconds to complete at most on an iSeries.

In the CL program for your command:

1. DSPFD FILE(&FILENAME) TYPE(*MBRLIST) OUTPUT(*OUTFILE) OUTFILE(QTEMP/FD)

2. In a CALLED CL PGM, open the file QTEMP/FD.

3. Do RCVF cmd on QTEMP/FD. This reads in the first record for the first member in the file. It has a record format (QWHFDML) and 2 fields: MLFILE (filename) and MLNRCD (number of records). You now have the record count of the first member.

4. CHGVAR to set the return CL PGM VAR (&NBRRCDS) from the MLNRCD variable you accessed.

==================================
MORE INFORMATION ON THIS TOPIC
==================================

Check out these Best Web Links on Web development.

Ask the Experts yourself: Our Web development gurus are waiting to answer your questions.

Ask your Web development & WebSphere questions -- or help out your peers by answering them--in our .fMFNafNPDOX.2@.ee84637!viewtype=&skip=&expand=>WebSphere & Web Development Forum.


This was first published in January 2004

Dig deeper on Web Development

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

1 comment

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close