MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to retrieve the number of rows in a query?

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
prog_mario
Beginner


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Fri Dec 18, 2009 4:49 pm    Post subject: How to retrieve the number of rows in a query? Reply with quote

I have a very big query in a store procedure and I need to return to the caller progam the results and the number of pages it produces (50 rows per pay). To solve this I run the same query using only a count to get this number, but the procedure becomes very heavy running the query twice. I'd like to know if there is any sql field that keeps the number of the rows retrieved.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Dec 18, 2009 4:54 pm    Post subject: Reply with quote

if you are doing a multirow fetch sqlerrd(3) will give you a count.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
prog_mario
Beginner


Joined: 08 Sep 2007
Posts: 86
Topics: 27

PostPosted: Sat Dec 19, 2009 7:14 am    Post subject: Reply with quote

No, I'm using fetch first 50 rows only.
_________________
The more I learn, the more I want to learn.
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Sat Dec 19, 2009 11:21 am    Post subject: Reply with quote

if you are doing singleton FETCHs, then you have to count them yourself with a cobol variable.

FETCH FIRST 50 ROWS ONLY is a optimization clause.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Tue Dec 22, 2009 5:49 pm    Post subject: Reply with quote

Are you going to display the result set of the query in web page paging. If so, we have similar situation come across in our application and we wrote them in array and tried to get the data 25 rows per page using paging logic.
Back to top
View user's profile Send private message
jctgf
Beginner


Joined: 05 Nov 2006
Posts: 89
Topics: 36

PostPosted: Tue Dec 29, 2009 10:11 am    Post subject: Reply with quote

I think the most resource-consuming operation is the DB2 access.
Sometimes, creating an index will increase your sql performance a lot.
Other possible solution would be to store the rows selected with your Sql in a Temporary Storage (with AUXILIARY), and then use it to display the screen.
You'd run your Sql once only and store the rows retrieved in the TS.
As you fetch, you'd count the number of rows.
After filling the TS, you'd read it forward and backwards and display the screen.
Each item in the TS may contain the entire page you want to display instead of each line of the page.
We've done it here and seems to work pretty well.
If the number of rows is too big or unpredictable, make sure to use the TS AUXILIARY option, otherwise the application may cause some instability to Cics.
TS I/O (even using the AUXILIARY option) is faster that DB2 access.
Regards.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group