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



I use QSORT much more than SORTA (I can't remember last time I used SORTA) , but I suspect you can run SORTA on a %SUBARR to sort just part of the array. and get



Just saying.


I'm usually using qsort on result set arrays.


You can define your from and to parameters on the comparer as being LIKEDS the data structure being sorted, and then use EVAL-CORR to move the values from the parameters to comparer structures with the same field names to isolate the key adn get them in the correct order. Then modify any numbers that can be negative in the comparison structures. The step by step comparison works fine, and is probably faster, but the code gets long if there are a lot of fields in the key, and I'll go dyslexic on it.






Sent from Outlook<http://aka.ms/weboutlook>


________________________________
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> on behalf of Barbara Morris <bmorris@xxxxxxxxxx>
Sent: Wednesday, June 20, 2018 6:48 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: How to Sort Data Structure array with negative values correctly ???

On 2018-06-20 5:43 PM, Troy Foster wrote:
I have looked an I can't find a solution. This is example of what I am
trying to accomplish. Is it possible? Does anyone have an example?
...

P LastName B
D LastName PI 10I 0
D parm1 like(name)
D parm2 like(name)

c select
c when parm1 < parm2
c return 1
c when parm1 > parm2I
c return -1
c other
c return 0
c endsl

P E


Change your LastName procedure to handle the parameters as data
structures with NB and A subfields. First compare the NB values, then
compare the A values.

d ds
D DS 5 dIM(10)
D NB 1s 0 OVERLAY(DS:*NEXT) INZ(0)
d A 1 OVERLAY(DS:*NEXT) INZ(' ')
add D nameDs ds 5 qualified
add D nb 1s 0
add D a 1

...
P LastName B
D LastName PI 10I 0
chg D parm1 likeds(nameDs)
chg D parm2 likeds(nameDs)

Then code the select like this:
c select
* Compare the NB values first
c when parm1.nb < parm2.nb
c return 1
c when parm1.nb > parm2.nb
c return -1
* The NB values are the same. Compare the A values next
c when parm1.a < parm2.a
c return 1
c when parm1.a > parm2.a
c return -1
* The NB values and A values are the same
c other
c return 0
c endsl

--
Barbara

--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: http://amzn.to/2dEadiD

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.