32,825 pts.
 AS/400 Record Count
I need a command to use in a CL program that will give me the record count for all records in a file. RTVMBRD will do it for a single member, but I need it for MBR(*ALL).

I know I can dump a *MBRLIST to a file and tally it up form there, but if someone already has this, why reinvent the wheel.



Software/Hardware used:
AS400 V5R4
ASKED: February 28, 2011  7:07 PM
UPDATED: March 1, 2011  2:07 AM
  Help
 Approved Answer - Chosen by MelanieYarbrough

Maybe you do something like this:

pgm

   dcl   &int         *int           value( 0 )
   dcl   &rtnmbr      *char   10
   dcl   &eom         *lgl           value( '0' )
   dcl   &nbrrcd      *dec (  10 0 ) value( 0 )

   rtvmbrd     toml/qclsrc +
                 mbr( *FIRSTMBR *SAME ) +
                 rtnmbr( &rtnmbr ) +
                 nbrcurrcd( &nbrrcd )

   dowhile ( *not &eom )

      sndpgmmsg msg( 'Counting' *bcat &rtnmbr )

      chgvar         &int                    ( &int + &nbrrcd )

      rtvmbrd  mylib/qclsrc +
                 mbr( &rtnmbr *NEXT ) +
                 rtnmbr( &rtnmbr ) +
                 nbrcurrcd( &nbrrcd )
      monmsg ( CPF3049 )  exec( chgvar  &eom  '1' )

   enddo

   return

endpgm

Does that make sense? Test the logic on something like MYLIB/QCLSRC. It seems to work, but I haven't seriously tested it.

Tom

ANSWERED:  Mar 1, 2011  1:41 AM (GMT)  by MelanieYarbrough

 
Other Answers:

Thanks Tom
I got impatient and whipped up something myself.
*
<pre>
PGM PARM(&pLib &pFile &pRcdCnt)

DCL VAR(&pLib) TYPE(*CHAR) LEN(10)
DCL VAR(&pFile) TYPE(*CHAR) LEN(10)
DCL VAR(&pRcdCnt) TYPE(*CHAR) LEN(10)
DCL VAR(&vADD) TYPE(*Dec ) LEN(9 0)
/*——————————————————————-*/
/* Build file in QTEMP with Member List */
/*——————————————————————-*/
DltF Qtemp/QAFDMBR
MonMsg CPF0000
DSPFD &pLib/&pFile *MBR OUTPUT(*OUTFILE) +
OUTFILE(Qtemp/QAFDMBR)
/*——————————————————————-*/
/* Call RPGSQLI program to sum(NMBRCD) */
/*——————————————————————-*/
Call GetRcdCntR &pRcdCnt
/*——————————————————————-*/
/* Cleanup after yourself */
/*——————————————————————-*/
DltF Qtemp/QAFDMBR
MonMsg CPF0000
END: ENDPGM

D DS
D vRecCount 1 10S 0
D pCount# 1 10
* Entry Parm list
c *entry plist
c parm pCount 10
*===================================================================
*= Program Logic
*===================================================================
/free
exsr getCounts;
pCount = pCount#;
*inlr = *on;

// ================================================================
// GetCounts
// ================================================================
begsr GetCounts;
/end-free
c/exec sql
c+ select Sum(MBNRCD) into :vRecCount
c+ from QTEMP/QAFDMBR
c/end-exec

/free
endsr;</pre>

Last Wiki Answer Submitted:  March 1, 2011  2:06 am  by  CharlieBrowne   32,825 pts.
Latest Answer Wiki Contributors:  CharlieBrowne   32,825 pts.
To see other answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _