The thing to remember is that AL etc *assume the array is already sorted*!
Once you've got your head around a "location sort", it's easy to
understand how AL etc work.
FOR II = 1 TO DCOUNT( ARRAY, @FM)
VALUE = ARRAY<II>
LOCATE VALUE IN ARRAY<1> BY "AL" SETTING POSN
IF II <> POSN THEN
DEL ARRAY<II>
INSERT VALUE BEFORE ARRAY<POSN>
END
NEXT
(When trying to understand this code, just remember that POSN cannot be
greater than II :-)
I wouldn't recommend actually using this sort, it'll be horribly slow,
but it's a perfect example of using a sort-ed/ing locate.
(Oh, and I can't remember the details, 9.6 was a long time ago, but
there was a bug in the UV implementation that would sort "substring"
AFTER "substringexample", but only SOMETIMES. Perfectly reproducible,
but different behaviour in different use-cases.)
Cheers,
Wol
On 04/04/17 20:30, Kevin King wrote:
> George, good clarification. I agree wholeheartedly. However, just
> because the insert uses AR, AL,DR, DL doesn't mean the results will be
> in sorted order UNLESS the starting array was originally in sorted
> order. That's no fault of the LOCATE as much as a misunderstanding about
> the sort order of the source data.
>
> On Apr 4, 2017 7:56 AM, "George Gallen" <
g_ga...@hotmail.com
> <mailto:
g_ga...@hotmail.com>> wrote:
>
> Locate is one of those that is very different from D3/Reality vs
> Prime/Information
>
>
> D3 - LOCATE SOMETHING IN DYNARR BY 'AR' SETTING POS ELSE CLAUSE to
> Search using AM as the delimiter in the entire Array
>
> INFORMATION - LOCATE SOMETHING IN DYNARR<1> BY 'AR' SETTING POS ELSE
> CLAUSE to Search using AM as the delimiter in the entire Array
>
>
> I only don't trust the POS marker on the ELSE if the array is
> non-sorted - but if the array was created and
>
> is sorted, I've found it to be reliable.
>
>
> ------------------------------------------------------------------------
> *From:* 'Ed Clark' via Pick and MultiValue Databases
> <
mvd...@googlegroups.com <mailto:
mvd...@googlegroups.com>>
> *Sent:* Monday, April 3, 2017 9:35 PM
> *To:*
mvd...@googlegroups.com <mailto:
mvd...@googlegroups.com>
> *Subject:* Re: [mvdbms] An almost beginner-level question
>
> When LOCATE doesn’t find the element it's searching for, it returns
> the position where the element *should* be inserted. If it’s a
> simple locate, then it will be 1 past the last
> attribute/value/subvalue. If you used locate with an ascending or
> descending flag on a sorted array then it will be the sorted
> location. In either case the returned pointer from LOCATE is
> appropriate and trustworthy to use with an insert:
> INS “!@$#” BEFORE SOMEDATA<1,PCNT)
> which will add the element in sorted order.
>
> In the example, of course, it looks like they used it just as a
> silly way to get the dcount, and it has to be a lot less efficient,
> UNLESS for some reason “!@#$” is sometimes actually used in the
> application as a marker for a special location, in witch case the
> code returns either the value before the point, or the last value.
> Who knows—I’ve seen stranger code.
>
>> On Apr 3, 2017, at 4:59 PM, Kevin King <
precis...@gmail.com
>> <mailto:
precis...@gmail.com>> wrote:
>>
>> Locate will tell the location where the string is found in the
>> dynamic array. If the search string is not found in the string,
>> many (most?) MV platforms will set the location to ... I think
>> it's one past the last value. I may be mistaken on that last part;
>> I don't trust the value in the location variable on the else.
>>
>> On Apr 3, 2017 2:20 PM, "Kevin Doiron" <
kdoir...@gmail.com
>> <mailto:
kdoir...@gmail.com>> wrote:
>>
>> Hi everyone,
>>
>> I'm finding myself back in the Pick world after an extended
>> absence to work on other systems. It's almost like riding a
>> bicycle, but a few things keep throwing me off, especially the
>> syntax differences between UniBasic and Python (where I was
>> focused for the last decade),
>>
>> Anyway, I'm reviewing some code that I need to figure out, and
>> I came across the following line:
>>
>> * LOCATE('!@#$',SOMEDATA<1>,1;PCNT) ELSE PCNT=PCNT-1
>>
>>
>> In this case, "SOMEDATA" is a single attribute data item, with
>> multiple values (e.g., '413ý428ý457'), that seems to be sorted
>> in ascending order. Of course, my target string ('!@#$') does
>> nt exist in this attribute. As a result, PCNT has a value of
>> 3 after this command. I've been able to figure out that the
>> command is effectively saying "tell me how many values are in
>> this attribute", but is there a reason (perhaps performance)
>> for using this convoluted format instead of something simpler like
>>
>> * PCNT=DCOUNT(SOMEDATA<1>,@VM)
>>
>>
>>
>> --
>> You received this message because you are subscribed to
>> the "Pick and MultiValue Databases" group.
>> To post, email to:
mvd...@googlegroups.com
>> <mailto:
mvd...@googlegroups.com>
>> To unsubscribe, email to:
mvdbms+un...@googlegroups.com
>> <mailto:
mvdbms%2Bunsu...@googlegroups.com>
>> <mailto:
mvd...@googlegroups.com>
>> To unsubscribe, email to:
mvdbms+un...@googlegroups.com
>> <mailto:
mvdbms+un...@googlegroups.com>
> <mailto:
mvd...@googlegroups.com>
> To unsubscribe, email to:
mvdbms+un...@googlegroups.com
> <mailto:
mvdbms%2Bunsu...@googlegroups.com>
> <mailto:
mvd...@googlegroups.com>
> To unsubscribe, email to:
mvdbms+un...@googlegroups.com
> <mailto:
mvdbms%2Bunsu...@googlegroups.com>
> To unsubscribe, email to:
mvdbms+un...@googlegroups.com