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



You are correct - currently, those keywords are not supported for DS arrays.

In these situations, I use bsearch() which is easy to use once you get the hang of it. I also used to use qsort to do the sequencing of the array but SORTA now allows multiple keys so it can be used instead.

For examples of qsort/bsearch take a look here: https://www.itjungle.com/2012/02/08/fhg020812-story01/

You can also find a number of other related examples by searching here: https://authory.com/JonParisAndSusanGantner


Jon P

On Dec 2, 2022, at 3:38 PM, Vinay Gavankar <vinaygav@xxxxxxxxx> wrote:

Hi Mark,

*Since a binary search is used by the %LOOKUPxx built-in functions for a
sequenced array*

I think the key words here are "sequenced array". For that it must be
'defined' with Ascend or Descend. I don't know how to add that keyword on
data structure array (I get compile error).

Am I missing something?

On Fri, Dec 2, 2022 at 10:20 AM Mark Waterbury <
mark.s.waterbury@xxxxxxxxxxxxx> wrote:

Vinay,
A binary search is exactly what %lookup does. For that algorithm to work
correctly, you must ensure that the table or array is sorted properly.
See: https://www.rpgpgm.com/2015/09/when-lookup-ne-lookup.html


Excerpt from the above article below:
Referring to IBM's KnowledgeCenter I found a link at the bottom of
the %LOKUPxx page that took me to a page called: Sequenced arrays that are
not in the correct sequence ... an interesting passage on this page states:

... the %LOOKUPxx built-in functions and the LOOKUP operation code may
find different values. The %LOOKUPxx built-in functions may not find a data
value even if it is present in the array.

Since a binary search is used by the %LOOKUPxx built-in functions for a
sequenced array, and the correct function of a binary search depends on the
data being in order, the search may only look at a few elements of the
array. When the array is out of order, the result of a binary search is
unpredictable.


See:
- %LOOKUPxx BIF
- LOOKUP Operation code
- Sequenced arrays that are not in the correct sequence


See also: http://www.itjungle.com/fhg/fhg020409.html


Hope that helps,
Mark S. Waterbury

On Friday, December 2, 2022 at 09:25:54 AM EST, Vinay Gavankar <
vinaygav@xxxxxxxxx> wrote:

Hi,

Is there a way to define a "sequenced" keyed array data structure, so that
the system uses Binary Search when doing a %lookupxx on it using the key?

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

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

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

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com

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

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link: https://amazon.midrange.com


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.