× 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.



"Fisher, Don" wrote:
>
> I would like to sort a multi-occurrence data structure containing, say, four
> fields, using the third field in the data structure.  After searching the
> archives and reading the example in the "Sorcerer's Guide", it appears that
> the QSORT routine needs the sort field to be the first in the data structure
> as there is no parameter for the starting position and length of the sort
> field.
>

Don, using qsort, you can write your comparison routine however you
want.  You still give qsort the beginning of the DS, but in your compare
routine you just compare the subfields you're interested in.

Example using a qualified ds:

D mods        ds              occurs(100)
D   sub1               10a
D   sub2                5p 0

P sortFunc    b
D sortFunc    pi       10i 0
D   parm1                     likeds(mods)
D   parm2                     likeds(mods)
c          if      parm1.sub2 > parm2.sub2
c          return  1
c          elseif  parm1.sub2 < parm2.sub2
c          return  -1
c          else
c          return  0
c          endif
P             e

If you're pre-V5R1, and can't use LIKEDS:

P sortFunc    b
D sortFunc    pi       10i 0
D   parm1                     like(mods)
D   parm2                     like(mods)
D ds1         ds              based(p1)
D   sub1a              10a
D   sub2a               5p 0
D ds2         ds              based(p2)
D   sub1b              10a
D   sub2b               5p 0

c          eval    p1 = %addr(firstparm)
c          eval    p2 = %addr(secondparm)
c          if      sub2a > sub2b
c          return  1
c          elseif  sub2a < sub2b
c          return  -1
c          else
c          return  0
c          endif
P             e




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.