Array Sorting
Posted in 2009
A user wanted to sort records held in a 4GL program array by one field before passing them to a report. Respondents advised letting SQL do the work: add an ORDER BY to the original SELECT that fills the array, or put an ORDER BY section in the 4GL REPORT module (which spools rows to a temp table and re-reads them sorted; use ORDER BY ... INTERNAL if data is already sorted). Alternatives offered were writing the data to a temp table and re-reading it sorted, or calling C qsort() via a 4GL wrapper. Resolved by advice.
Auto-generated by DrWatson from the posts below — may be imperfect; read the full thread.
Topics: General Discussion
Hi, I have a set of data stored in a program array. I wanted to sort this array records based on one particulr field (Which is there in the array). How to do this..? This is informix report program. Thanks
KRISHNAN BALASUBRAMANIAN wrote: > Hi, > > I have a set of data stored in a program array. I wanted to sort this array > records based on one particulr field (Which is there in the array). > > How to do this..? This is informix report program. Select the data into the array using an ORDER BY clause. -- Cheers, Obnoxio The Clown http://obotheclown.blogspot.com
If it's a 4GL or ISQL/ACE report you can also add an ORDER BY clause to the report module. Art On Mon, Jan 5, 2009 at 3:35 AM, Obnoxio The Clown <obnoxio@serendipita.com>wrote: > KRISHNAN BALASUBRAMANIAN wrote: > > Hi, > > > > I have a set of data stored in a program array. I wanted to sort this > array > > records based on one particulr field (Which is there in the array). > > > > How to do this..? This is informix report program. > > Select the data into the array using an ORDER BY clause. > > -- > Cheers, > Obnoxio The Clown > > http://obotheclown.blogspot.com > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > -- Art S. Kagel Oninit (www.oninit.com) IIUG Board of Directors (art@iiug.org) Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Oninit, the IIUG, nor any other organization with which I am associated either explicitly or implicitly. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves.
Thanks Art, Basically in a 4gl foreach loop the program is moving each records to the program array. Now the program array holding all the records which is not sorted based on my required column. How to do this without having any perofrmance issues. Thanks for the all helping to sorting out thisproblem. Regards
Are you then passing the data into a report ? Or is the FOREACH in the report already ? On Monday 05 January 2009 08:31:11 KRISHNAN BALASUBRAMANIAN wrote: > Hi, > > I have a set of data stored in a program array. I wanted to sort this array > records based on one particulr field (Which is there in the array). > > How to do this..? This is informix report program. > > Thanks > > > *************************************************************************** >**** Forum Note: Use "Reply" to post a response in the discussion forum. -- Mike Aubury http://www.aubit.com/ Aubit Computing Ltd is registered in England and Wales, Number: 3112827 Registered Address : Clayton House,59 Piccadilly,Manchester,M1 2AQ
Then passing to report for printing.
So - as Art says - do the ordering in the report with an ORDER BY section.. On Monday 05 January 2009 12:27:13 KRISHNAN BALASUBRAMANIAN wrote: > Then passing to report for printing. > > > *************************************************************************** >**** Forum Note: Use "Reply" to post a response in the discussion forum. -- Mike Aubury http://www.aubit.com/ Aubit Computing Ltd is registered in England and Wales, Number: 3112827 Registered Address : Clayton House,59 Piccadilly,Manchester,M1 2AQ
The original suggestion to include an ORDER BY clause in the original SQL query would cause the data to be naturally sorted when it's read into the array. If ultimately you are passing the array elements to a 4GL REPORT module, you can include an ORDER BY clause in the report module and the module itself will gather the array into a temp table in the database and retrieve the rows with an ORDER BY (if you have already sorted the data look at the ORDER BY...INTERNAL clause in the 4GL manual). Another option if you cannot pre-sort the data and are not using a report module, would be to write the data to a temp table yourself and reread it with an ORDER BY clause. Finally, you could write a 4GL callable wrapper for the C qsort() function and pass the array to that function for sorting. Art On Mon, Jan 5, 2009 at 6:38 AM, KRISHNAN BALASUBRAMANIAN < krishnanbalasubramanian@rediffmail.com> wrote: > Thanks Art, > > Basically in a 4gl foreach loop the program is moving each records to the > program array. > > Now the program array holding all the records which is not sorted based on > my > required column. > > How to do this without having any perofrmance issues. > > Thanks for the all helping to sorting out thisproblem. > > Regards > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > -- Art S. Kagel Oninit (www.oninit.com) IIUG Board of Directors (art@iiug.org) Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Oninit, the IIUG, nor any other organization with which I am associated either explicitly or implicitly. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves.