What is the command to find the number of entries/rows in a temp table? version 10.2b
Asked
Active
Viewed 6,280 times
4
-
Ok thanks. Why does this deserve a down vote?!?! I looked everywhere and couldn't find one so I though I would ask here in case i was missing something. – Bill Aug 10 '12 at 15:41
-
1@Bill There's nothing wrong with your question. People are probably just mad that you're highlighting a major deficiency in OpenEdge's most core data structure – Abe Voelker Aug 10 '12 at 17:56
-
2Some people just view everything through a "Progress sucks" lens. When you take the blinders off things usually go better. – Tom Bascom Aug 11 '12 at 19:07
-
@TomBascom Couldn't agree with you more – TerryB Aug 12 '12 at 21:09
-
3Don't be fooled, people, Progress does suck. It even gets worse with the blinders off. – Lieven Cardoen Apr 08 '14 at 07:13
3 Answers
4
/* create a temp-table so that we can test this technique
*/
define temp-table ttTest
field id as int
.
create ttTest.
id = 1.
create ttTest.
id = 2.
/* how many records?
*/
define query q for ttTest cache 0.
open query q preselect each ttTest.
display num-results( "q" ).

firhang
- 244
- 2
- 11

Tom Bascom
- 13,405
- 2
- 27
- 33
-
It's too bad there isn't a `NUM-RECORDS` attribute for temp-table objects. Surely a temp-table knows exactly how many rows it contains, and being single-threaded, Progress doesn't have any type of concurrency complications to worry about. Weird that they thought to add a `HAS-RECORDS` attribute to check for emptiness but not one with the actual number. – Abe Voelker Aug 16 '12 at 19:09
-
2I had the same thought. I'll try to remember to suggest it the net time I'm providing helpful input to development ;) – Tom Bascom Aug 16 '12 at 21:55
1
or you can use clasic FOR EACH:
DEFINE VARIABLE iCount AS INT NO-UNDO.
FOR EACH ttTest:
iCount = iCount + 1.
END.
DISPLAY iCount.

firhang
- 244
- 2
- 11
0
Here's mine, that works for any temp-table :
FUNCTION TT_NBREC RETURNS INTEGER ( INPUT pr_hd_temptable AS HANDLE ) :
DEFINE VARIABLE in_nbrec AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE hd_buffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hd_query AS HANDLE NO-UNDO.
DEFINE VARIABLE ch_query AS CHARACTER NO-UNDO.
DEFINE VARIABLE ch_table AS CHARACTER NO-UNDO.
DEFINE VARIABLE lg_error AS LOGICAL NO-UNDO.
ASSIGN
ch_table = pr_hd_temptable:NAME
ch_query = "FOR EACH " + ch_table + " NO-LOCK".
CREATE BUFFER hd_buffer FOR TABLE ch_table.
CREATE QUERY hd_query.
hd_query:ADD-BUFFER( hd_buffer ).
lg_error = hd_query:QUERY-PREPARE( ch_query ) NO-ERROR.
hd_query:QUERY-OPEN().
hd_query:GET-FIRST().
DO WHILE NOT hd_query:QUERY-OFF-END :
ASSIGN in_nbrec = in_nbrec + 1.
hd_query:GET-NEXT().
END.
hd_query:QUERY-CLOSE().
DELETE OBJECT hd_query.
DELETE OBJECT hd_buffer.
ASSIGN
hd_query = ?
hd_buffer = ?.
RETURN in_nbrec.
END FUNCTION.
Just pass it the handle of your temp-table and you get the number of records. It can certainly be improved, but it works fast enough for me.

Gabriel Hautclocq
- 3,230
- 2
- 26
- 31