Now, some better news. If you are a Professional member of iSeries Network, you can read an article about using keyed data queues to sort subfiles in RPG in the November 2004 edition of the iSeries News magazine. The article, and a previous article on using keyed data queues to sort subfiles in COBOL, is also available at http://www.iseriesnetwork.com/ -- again, you must be a Professional member.
If you are not qualified to read the article, the gist of it is this:
1. Create a keyed data queue in QTEMP named for the program.
2. Load the subfile from your database.
3. If the user requests to see the data in a different order, clear the data queue and load it from the subfile. The key will be the key field chosen by the user. Note that the data length of a data queue entry must be exactly equal to the length of the subfile record you want to store (or whatever data structure you want to use), and the key length must be enough to hold the longest key value combination.
4. Once the data queue has been loaded, clear the subfile and reload it by reading from the data queue. The data is presented automatically in the keyed order.
There are some tricks involved, primarily in the handling of signed numbers as keys, which I am sure I can leave to you to fathom.
The APIs needed are QCLRDTAQ, QSNDDTAQ and QRCVDTAQ. You also need to use the CRTDTAQ command, either from a controlling CL program or from within the RPG program using QCMDEXC (ignoring error messages when the queue already exists).
Now, I have some reservations on sorting subfiles, because the longer the data is on the screen, the less current it is. With live data in my company, users need to know the up-to-date values - and if they refresh the screen, they believe that that's what they are seeing. If the program is only sorting the subfile, then the information is not up to date.
So use the same technique to copy data read from the database into the data queue, instead of the subfile data, and load the subfile from that. This will catch new, changed and deleted data and should not add much additional overhead to the process.
MORE INFORMATION ON THIS TOPIC
The Best Web Links: tips, tutorials and more.
Visit the ITKnowledge Exchange and get answers to your developing questions fast.
Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.
Dig Deeper on RPG iSeries programming
Related Q&A from John Blenkinsop
When an error occurs on an IBM command, the diagnostic messages are sent first, then an escape message, which you can monitor. On AS/400 you see the ... Continue Reading
Learn how to 'append data to the file' with the FTP DIR command, and eliminate the hassle of having to end the FTP session and restart to view ... Continue Reading
RPGIV will 'think of' incoming integer fields as binary, and then will redefine them in the program structures as PACKED. So, when you chain a record... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.