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



What release you are on?
Did you try the OPCode SORTA with the D extension, i.e. SORTA(D) ?

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> On Behalf Of Troy Foster
Sent: Mittwoch, 20. Juni 2018 23:43
To: RPG programming on the AS400 / iSeries <rpg400-l@xxxxxxxxxxxx>
Subject: How to Sort Data Structure array with negative values correctly ???

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?

I get this when it sorts.
NB(1) = 5.
NB(2) = 2.
NB(3) = 0.
NB(4) = -6.
NB(5) = -4.
NB(6) = -3.
NB(7) = 0.
NB(8) = 0.
NB(9) = 0.
NB(10) = 0.

I want to get:

NB(1) = 5.
NB(2) = 2.
NB(3) = 0.
NB(4) = -3.
NB(5) = -4.
NB(6) = -6.
NB(7) = 0.
NB(8) = 0.
NB(9) = 0.
NB(10) = 0.

This is a sample of the code that I use. I

H BNDDIR('QC2LE')

D qsort PR ExtProc('qsort')
D base * value
D num 10U 0 value
D width 10U 0 value
D compare * procptr value

D LastName PR 10I 0
D parm1 like(name)
D parm2 like(name)

D name s 5
D num_names s 10i 0

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

c eval NB(1) = -6
c eval NB(2) = -3
c eval NB(3) = 5
c eval NB(4) = -4
c eval NB(5) = 2
c eval NB(6) = 0
c Eval A(1) = 'A'
c Eval A(2) = 'Y'
c Eval A(3) = 'G'
c Eval A(4) = 'H'
c Eval A(5) = 'D'
c Eval A(6) = 'B'

c eval num_names = 6

c callp qsort(%addr(NB): num_names:
c %size(name): %paddr('LASTNAME'))
c eval *inlr = *on

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 > parm2
c return -1
c other
c return 0
c endsl

P E
--
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 ...

Follow-Ups:
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.