Home > Ask the AS/400 Experts > Questions & Answers > Options for sorting subfiles in RPG
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

Options for sorting subfiles in RPG

John Blenkinsop EXPERT RESPONSE FROM: John Blenkinsop

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site
>
QUESTION POSED ON: 12 November 2004
I sort subfiles in RPG LE by copying the subfile records to array and then SORTA and copy the array back to the subfile. Is there another ways to sort subfile in RPG? How can I pass (to QSORT) a pointer to the subfile?


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


First, the bad news: You cannot pass a pointer to the subfile. That pointer is not available to your program.

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.




Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts