Consultor Eletrônico



Kbase 35496: 4GL. Which is the faster way to count records in a Table?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   8/15/2000
Solution ID: P5496

GOAL:

4GL. Which is the faster way to count records in a Table?

FIX:

You could have to approaches for counting records in a Table.
Use the COUNT function available in the Progress 4GL or you can implement a Query to do the same .
In terms of performances it will depend on the Amount of Records within the Table and the Operating System. However Queries in average give a better result.


The COUNT function Approach:

DEFINE VARIABLE A AS INTEGER NO-UNDO.
A = ETIME(YES).
FOR EACH CUSTOMER NO-LOCK:
   ACCUMULATE BALANCE (COUNT).
END.

MESSAGE "TOTAL OF RECORDS    = " (ACCUM COUNT BALANCE) SKIP(1)
       "TIME FOR PROCESSING = " ETIME VIEW-AS ALERT-BOX.



The Query approach:

DEFINE VARIABLE A AS INTEGER NO-UNDO.
DEFINE QUERY MYQUERY FOR CUSTOMER SCROLLING.

A = ETIME(YES).
OPEN QUERY MYQUERY FOR EACH CUSTOMER NO-LOCK.

REPEAT WHILE NOT QUERY-OFF-END("MYQUERY"):
    GET NEXT CUSTOMER.
END.

MESSAGE "TOTAL OF RECORDS    = " NUM-RESULTS("MYQUERY")  SKIP(1)
       "TIME FOR PROCESSING = " ETIME VIEW-AS ALERT-BOX.