× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Maria!

If you truly don't want to keep re-executing the same query, you will have to save the results somehow.  How many records are you returning?  Is it small enough to create a work file?  Or perhaps a work file of just the keys for the records, which you could then join back to the master table(s)?  If your connection is stateless, you could use a dedicated work file keyed by a unique session ID.  If it's stateful, you could probably use a global temporary table in SQL.


On 7/28/2020 2:16 AM, Maria Lucia Stoppa wrote:
Hi all,
Hope you are well.

A REST API I am working on returns data split into pages: many calls are
necessary to get the complete set of data, but in this way, the user
doesn't wait too much for the first page. Data are retrieved within an RPG
ILE service program by a static SQL statement which applies some dynamic
filters that come within the request.

Everything works fine, except the same static SQL statement is run at least
twice to know the total number of rows (a simple count(*)) and the rows
themselves page by page.
Now, on the same data retrieved by this SQL statement, others select
statements must be run to get some totals according to different group by
clauses in order to present the data set distribution to the final user.

I hardly accepted the idea of running the same SQL statement (which, by
the way, is pretty complex) at least twice to get both the total and the
row, but I can't stand the idea of even more runs to get data distribution.

There might be errors in my design of how the procedure should work,
nonetheless, I wonder if a single common table expression might be used
many times to serve many different select statements, as I would avoid the
use of other solutions like global temporary tables.

Any suggestion is really appreciated.

Many thanks



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.