How to retrieve a file’s record count

430 pts.
Tags:
AS/400
John needs your help. He recently wrote the editors at Search400.com and asked, "Is there another way of retrieving a file's record count besides reading the file and counting? Can you use RTVMBRD?" What do you think? Michelle Davidson Editor Search400.com

Answer Wiki

Thanks. We'll let you know when a new response is added.

I routinely use the CL command DSPFD command and direct the output to the system-supplied outfile QAFDMBR.
The CL code is:

DCLF FILE(QAFDMBR)

DSPFD FILE(MyLib/MyFile) TYPE(*MBR) OUTPUT(*OUTFILE) FILEATR(*ALL) OUTFILE(QTEMP/QAFDMBR)

OVRDBF FILE(QAFDMBR) TOFILE(QTEMP/QAFDMBR) POSITION(*START)

RCVF

Then check the DB field &MBNRCD to determine the number of records.

If you are executing this code in batch then the QTEMP file will disappear when the batch job ends. If you execute this code interactively then the QTEMP file will not disappear when your session ends. You should include additional code to handle the existence of the QTEMP file if you plkn to run your code multiple times within the same interactive session.

===========================================================

Retrieving record counts is a major purpose of RTVMBRD. The NBRCURRCD() parameter returns the number of <i>current</i> records. ‘Current’ are ones that are not deleted. This is meaningful because RTVMBRD can also return the number of deleted records in the NBRDLTRCD() parameter. Adding the two values together results in the total amount of space taken for records by the member.

Tom

Discuss This Question: 9  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

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
  • Bradskk
    We routinely use the following in our CL's to get the number of records in a file. DCL VAR(&RCDNBR) TYPE(*DEC) LEN(10) RTVMBRD FILE(QS36F/CHP.3601) NBRCURRCD(&RCDNBR) You may then place &RCDNBR into the LDA and pass it to any RPG programs in a UDS.
    0 pointsBadges:
    report
  • Westdeb
    If you are looking for a record count in an rpg program you can use the INFDS the field FIRECS contains the record count.
    0 pointsBadges:
    report
  • Teandy
    Here's one example:
    
    DCL        VAR(&RECORDCNT) TYPE(*DEC) LEN(10 0) VALUE(0)
    
    DCLF       FILE(DSPPGMRFPF)  
                                 
    CLRPFM     FILE(WTI0001PF)   
    CLRPFM     FILE(DSPOBJDPF)                            
                                                          
    DSPOBJD    OBJ(*ALL/&WHPNAM) OBJTYPE(*PGM) +          
                 OUTPUT(*OUTFILE) OUTFILE(*LIBL/DSPOBJDPF)
    MONMSG     MSGID(CPF2123)                             
                                                          
    RTVMBRD    FILE(DSPOBJDPF) NBRCURRCD(&RECORDCNT)      
                                                          
    IF         COND(&RECORDCNT *GT 0) THEN(DO)            
                                                          
    CALL       PGM(WTI0001R)                              
    
    
    5,860 pointsBadges:
    report
  • pdraebel
    The record count from the INFDS in RPG works great, it even works without opening the file.
    2,570 pointsBadges:
    report
  • TomLiotta
    The record count from the INFDS in RPG works great, it even works without opening the file. The Open Feedback Information portion of the INFDS contains 'number of records' at the time the file was opened, as the name implies. Note that it only returns the count of active records. Deleted records are not included. Also, an INFDS and an open would have to be coded for each individual file. RTVMBRD can be called for any file without concern for level checks nor other complications. Tom
    125,585 pointsBadges:
    report
  • slateken
    Plenty of options here already, but here's a simple RPG/SQL option:
    Exec Sql Select count(*) into :FUNCOUNT from FUNFILE
    230 pointsBadges:
    report
  • slateken
    (assuming :FUNCOUNT is the declared variable to which you want to save the record count, of course...)
    230 pointsBadges:
    report
  • Srinathvasudevan
    We can use RTVMBRD

    DCL VAR(&R1) TYPE(*DEC) LEN(10 0) 

    DCL VAR(&D1) TYPE(*CHAR) LEN(2) 
    DCLF FILE(PF12) RCDFMT(RCD1) 
    RTVMBRD FILE(PF12) NBRCURRCD(&R1)
    20 pointsBadges:
    report
  • WilsonAlano
    No mention to QUSRMBRD API?

    Is the same result as RTVMBRD but using an API!

    Wilson
    2,485 pointsBadges:
    report

Forgot Password

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

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

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

Thanks! We'll email you when relevant content is added and updated.

Following