Ask the Expert

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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: