Get the number of records in a file in CL PGM.

How can i get the number of records in a file in CL PGM.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Use the command RTVMBRD and its the NBRCURRCD parm


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Barry HarperConsultantCommented:
To elaborate on Dave's answer, Retrieve Member Description (RTVMBRD) returns the current number of records and the number of deleted records. Here is some CL to get you started (it needs testing, message monitoring, etc.):

PGM  (&FILE  &LIB  &MBR)                                                  
DCL &FILE       *CHAR    10                                                
DCL &LIB        *CHAR    10                                                
DCL &NBRCURRCD  *DEC  (10 0)                                              
DCL &NBRCURRCDC *CHAR    10                                                
DCL &NBRDLTRCD  *DEC  (10 0)                                              
DCL &NBRDLTRCDC *CHAR    10                                                
DCL &NBRTOTRCD  *DEC  (10 0)                                              
DCL &NBRTOTRCDC *CHAR    10                                                
             RTVMBRD    FILE(&LIB/&FILE) MBR(&MBR) +                      
                          NBRCURRCD(&NBRCURRCD) NBRDLTRCD(&NBRDLTRCD)      
             CHGVAR   &NBRTOTRCD (&NBRCURRCD + &NBRDLTRCD)                
             CHGVAR   &NBRCURRCDC  &NBRCURRCD                              
             CHGVAR   &NBRDLTRCDC  &NBRDLTRCD                              
             CHGVAR   &NBRTOTRCDC  &NBRTOTRCD                              
             SNDPGMMSG ('CURRENT RECORD COUNT:' || &NBRCURRCDC)            
             SNDPGMMSG ('DELETED RECORD COUNT:' || &NBRDLTRCDC)            
             SNDPGMMSG ('*TOTAL* RECORD COUNT:' || &NBRTOTRCDC)            

If the program is named RTVMBRD, you can call it like:

call rtvmbrd (debtin bh '*FIRST')

and it produces output like:

> call rtvmbrd (debtin bh '*FIRST')  
  CURRENT RECORD COUNT:0000000016    
  DELETED RECORD COUNT:0000000002    
  *TOTAL* RECORD COUNT:0000000018    

So, if you want the total number of records including the deleted ones, you need to add the current and deleted together.

Display File Description (DSPFD) shows in part:
                            Source Creation    Last Change                          Deleted
Member           Size        Type  Date       Date     Time      Records    Records
DEBTIN                16384        04/02/06 09/07/06 13:44:27         16          2

If you need to know the number of records in ALL members of a multi-member file, please post back and I will amend my sample program.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.