×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
Don't define separate/related arrays. That's just a bad practice. I
realize that in RPG III, we had no alternative.
Hopefully you aren't still using RPG III!
Use an overlay DS for a very simple method. There have been loads of
examples posted to this forum in the past. With that technique, you
make only one array, and have all of the related fields appear within it
and can sort it via SORTA to your heart's content.
Perhaps a better (although more complex) alternative is to load all of
your fields into an array of DSes instead of arrays of fields. This is
more complex to code because you can't use SORTA, but have to use an
API. But data structure arrays provide tons of useful features not
available with overlay arrays. (albeit, unrelated to sorting) In an
encapsulated, modular, world I would not dream of trying to use overlay
arrays, they're too hard to pass in a meaninful way to subprocedures.
When sorting an array of DSes, I would suggest using the qsort() API,
which is about the simplest way. There's also the QLGSORT API, but I
would steer well away from it, since it's significantly more complex,
less versatile, and slower than qsort(). Though it DOES provide better
internationalization...
You *could* resort to a work file, but that won't be as fast as an array
-- plus, IMHO, it won't be as elegant to code. Whatever you do, stay
clear of using a data queue or user index, both of which I've found to
be MUCH slower even than a work file, plus they're MORE cumbersome.
Personally, I'd either use an overlay array and SORTA or I'd use a DS
array with QSORT. You probably don't need any more options than those two.
Booth Martin wrote:
I'd enjoy following a discussion about sorting related arrays. I have
already solved the problem I am about to present, but as I look at my
solution it occurs to me that I am embarrassed to show my solution to
knowledgeable people. There _has_ to be a better way.
Here's the sceanrio: To display a multi-column load-all subfile and
have each column heading clickable. The click would determine which
column is sorted. A second click on a clicked column would sort the
column in the other direction.
There are images of this at
http://www.martinvt.com/Code_Samples/SFL_Sort/sfl_sort.html
The code is also there. It works. But gads, its awful code.
So, lets define the problem a bit more? A load-all subfile with 5
columns of data How would one define the needed array(s), data
structure(s), or whatever(s) so that they can be sorted up or down by a
selected column?
As an Amazon Associate we earn from qualifying purchases.