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



If you want to keep the ASCEND and performance benefit you get from the
binary search, all you need to do is resort the array after you add an
entry.

Tracking the number of elements loaded will also increase performance.
If you have only added 10 elements to a 9999 element array, there is no
reason to scan the elements that have not been loaded.

I've used something like this to build a list of elements after I
determine they are not inside my array.

P = %LookUp(Arr1(Idx1) : poArr : 1 : elementCount);
If p=0;
elementCount += 1;
poArray(elementCount) = newdata;
sorta %subarr(poArr :1 :elementCount);
endif;

Chris Hiebert
Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the
author and do not necessarily represent those of the company.


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of
j.beckeringh@xxxxxxxxxxxxxxxxxxxxxxxxxx
Sent: Thursday, August 08, 2013 1:58 AM
To: RPG programming on the IBM i (AS/400 and iSeries)
Subject: Re: %Lookup Clarification

Chamara,

The fact that removing ASCEND changes the outcome should give you a
clue.
With the ASCEND keyword you promise the compiler that the entries in the
array will be in ascending order, so the compiler can use a binary
search.
Initially all entries in the array are blank; when you fill entry 1 the
order is broken. The manual has a special paragraph about this (page 553
in 7.1).

You have several options:
- Don't specify ASCEND - the search will be somewhat slower
- Keep track of how many entries in the array are filled and give that
number als fourth parameter to %lookup
- (For completeness' sake:) Initialize all entries with *HIVAL

Joep Beckeringh


%Lookup Clarification

Chamara Withanachchi

Hi,

I cannot recall this earlier, I'm in a 7.1 box with latest PTFs
applied,
I
have done a %Lookup operation to a array as bellow

D poArr S 6 DIM(9999) ASCEND

C Eval P = 1
C Eval P = %LookUp(Arr1(Idx1) : poArr : P)

When I see the array in Debug mode I can see the search criteria is in

the poArr array, but P become 0 after the %Lookup even though values
are in poArr array

When I removed the ASCEND keyword, P became the element no of the
poArr Array, (%Lookup Success) any idea What I'm I missing here?


--
Regards,

Chamara Withanachchi


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.