Display the number of rows in a table on iSeries

Number of rows EXCLUDING deleted – three methods

1. The SQL COUNT function

> STRSQL 
> SELECT COUNT(*) FROM cities

....+....1....
COUNT ( * )
          6
******** End of data ********

2. The display file description command

> DSPFD cities

Go to the bottom of the information and look for the line “Total records”

Total number of members . . . . . . . . . : 1
Total number of members not available . . : 0
Total records . . . . . . . . . . . . . . : 6
Total deleted records . . . . . . . . . . : 1
Total of member sizes . . . . . . . . . . : 12288

3. The run query command

> runqry *n cities

Go to the bottom and look at the last line number

Line ....+....1....+....2....+....3....
       CITYNAME 
000001 Cardiff 
000002 London 
000003 Bristol 
000004 Exeter 
000005 Bath 
000006 Plymouth 
****** ******** End of report ********

Alternatively, the summary option just gives a count without showing any rows:

> RUNQRY QRYFILE((CITIES)) OUTFORM(*SUMMARY)

 

Position to line . . . . . 
Line ....+....1....+ 
000001 FINAL TOTALS 
000002 COUNT 6 
****** ******** End of report ********

 

Number of rows INCLUDING deleted – three methods

1. The display physical file member command

> DSPPFM cities

Position to the bottom line with B command and a series of +1 commands and  look for the record count in the heading

  
File . . . . . . : CITIES           Library . . . . : QGPL
Member . . . . . : CITIES           Record . . . . . : 7 
Control . . . . . +1                Column . . . . . : 1 
Find . . . . . . . 
*...+....1....+....2....+....3....+....4....+....5....+....6....+.
Plymouth 
 ****** END OF DATA ******

 

2. The update data command

> UPDDTA cities

Press page up (twice) to position to the last record in file

 

WORK WITH DATA IN A FILE 
Format . . . . : CITIES 
 
*RECNBR:      7 
CITYNAME: Plymouth 

 

3. The SQL MAX & RRN functions

> STRSQL
> SELECT MAX(RRN(cities)) FROM cities
 
 Position to line . . . . . 
....+....1....+....2 
 MAX 
 7 
******** End of data ********
Posted in tips.