I think this would do what Booth wants:
Jeff,
I'm assuming that Booth is keeping track of how many elements there are in
his subfile
If you use RTNCSRLOC in the display file, e.g.:
A RTNCSRLOC(&CSRFMT &CSRFLD)
A CSRFMT 10A H
A CSRFLD 10A H
then you'd have this in the RPG (in addition to Jeff's data-structure)
D ElemNbr S 10I 0
D SortField S 10A
D SortSeq S 10I 0 Inz(1)
D SortFieldSave S 10A
// Set the sort field from the column clicked
SortField = CSRFLD;
// If the user has re-clicked the same column, swap the sequence
If SortField = SortFieldSave;
SortSeq = -SortSeq;
endif;
// Save the sort column
SortFieldSave = SortField;
// Sort the array
qsort( %addr(Scrn_Field) : ElemNbr : %size( Scrn_Field ) : sortprocptr );
// Now redisplay the subfile
and in sortprocptr, yuo'd have this:
P sortprocptr B Export
D PI 10I 0
D Elem1ptr * Value
D Elem2ptr * Value
D Elem1 DS Likeds(Scrn_Field) Based(Elem1ptr)
D Elem2 DS Likeds(Scrn_Field) Based(Elem2ptr)
D rtncde S 10I 0 Inz
select;
when SortField = 'PRES';
if Elem1.President < Elem2.President;
rtncde = -1
if Elem1.President = Elem2.President;
rtncde = 1;
if Elem1.President = Elem2.President;
rtncde = 0;
when SortField = 'COLOR';
if Elem1.Color < Elem2.Color;
rtncde = -1
if Elem1.Color = Elem2.Color;
rtncde = 1;
if Elem1.Color = Elem2.Color;
rtncde = 0;
...and so on...
endsl;
return rtncde * SortSeq;
On Wed, Oct 22, 2008 at 8:47 AM, <jdavis@xxxxxxxx> wrote:
The only thing about my method is that it also sorts the rows with the
columns, in the example only the column was effected.
Would qsort only sort the subarray in the DS or would it sort the whole DS
like SORTA?
Jeff Davis
As an Amazon Associate we earn from qualifying purchases.