On 2013/1/30 8:21 PM, Peter Connell wrote:
I've just discovered (or perhaps too old to remember) the section in the RPGLE doc on %LOOKUP that says:
Sequenced arrays that are not in the correct sequence<http://publib.boulder.ibm.com/infocenter/iseries/v6r1m0/topic/rzasd/sc09250802.htm#ToC_863>

I've been copying the RPG spec that defines a standard array that we use from a template which has DESCEND without realizing this.
Fortunately, our bread and butter comes from code that still uses the old LOOKUP in the operation column of a C spec which does not suffer from the effects of a binary search like %LOOKUP.

If your sequenced arrays aren't sorted, your LOOKUP opcodes are ok as long as you only have the EQ indicator set. But you can get unexpected results for an unsorted array when the LOOKUP opcode has the LO or HI indicators set.

D arr s 1a dim(10) ascend
D i s 10i 0
C movea 'edkmzajtbp' arr
C eval i = 1
* HiLoEq
C 'j' lookup arr(i) 1011
C '<= j' dsply arr(i)
*
C sorta arr
*
C eval i = 1
C 'j' lookup arr(i) 1011
C '<= j' dsply arr(i)
*
C seton lr

It displays d for the unsorted version and j for the sorted version. For the unsorted version, it stops checking when it gets to the k element since that is bigger than the search argument j, and it's looking for one that's less than or equal.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.