|
One approach I have used when the data can not be used as the index is to have three arrays. One to load, one to sort (Ascend), and one to hold the summary data (can even be an MODS). Program initializes the load array with high values, then for each index information, looks it up in the load array. If not found, lookup highvalues, and place in that element. Increment data array/MODS element/occurance with whatever is being summarized. Cycle end: move load array to sort array and do a SORTA. Then do till high values against elements in sort array: lookup sort array element in load array and print data that matches. -----Original Message----- From: rpg400-l-admin@midrange.com [mailto:rpg400-l-admin@midrange.com]On Behalf Of Buck Calabro Sent: Thursday, September 06, 2001 6:52 PM To: rpg400-l@midrange.com Subject: RE: Array help >I need to count the number of people for each >age that work within the company An alternative to arrays is SQL: select age,count(*) from ... group by age order by 1 fetch each record and do what you need. Arrays have an advantage if you need to know what ages are not present in your dataset - the element will be zero. SQL has an advantage if you need to do the same sort of calculation on a very diverse dataset like postal code, where the number of elements would be impractical without developing a hash function. It also has an advantage in that you can readily sort the results by descending count viz.: order by 2 desc. Buck Calabro Commsoft; Albany, NY Visit the Midrange archives and FAQ at http://www.midrange.com "As a rule, men worry more about what they can't see than about what they can." -- Julius Caesar _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l or email: RPG400-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.