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....
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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.
Dig Deeper on Web Development
Related Q&A from Jim Mason
Java to Excel with the AS400 may be attractive, but if you have complex VBA macros in Excel, the JDBCODBC bridge will not work well for you. A better...continue reading
There are a couple of options for accessing AS/400 data, from the old way using Client Access ODBC drivers, to Java, to a new application from Groovy.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.