Select arraysearch(

While debugging a procedure from sometime last year I discovered the following code:

select arraysearch(lvArDecline,«memno»,1,cr())>0

Where lvArCommit is an array of Member Numbers formed earlier in the procedure, and «memno» is the Member Number field. I don’t recall how I came up with this (something similar is discussed in the Pan 6 topics) but it works, except when it doesn’t.

I have three iterations of the following sequence:

select arraysearch(lvArDecline,«memno»,1,cr())>0
if info(“Empty”)
lvDeclineTotal=0
else
field «ASK»
Total
lvDeclineTotal=«ASK»
endif

removeallsummaries

The difference is just the variable holding the Member Numbers.

The correct records are selected with each array.

I can run the full procedure over and over with no errors in the first to iterations, but the third sometimes gets it right, sometimes produces the same error. The recurring error is the «ASK» field not totalling.

if I use

lvDeclineTotal=pattern(«ASK»,“$#,.##”)

the «ASK» field will fail to total about 4 times, total correctly once or twice, then back to not totalling. If I take off the pattern( ) , the result alternates between not totalling and correctly totalling.

This procedure has been working fine for the last year because the lvArDecline search always turned up Empty. Now that it has two records, the error shows up.

Assuming I’ve done something wrong along the line, but not seeing it. That the correct records are chosen with the select arraysearch() seems to indicate that is not the problem, but everything else seems pretty straight forward.

I don’t see the problem from the information provided. I am wondering, is memno a numeric field? Also, I don’t understand what you mean when you say “the difference is just the variable holding the Member Numbers”? Looks like the variable is the same to me. Or maybe you mean the contents of the variable?

If your desired end result is simply the lvDeclineTotal variable, you can do that in Panorama X with just the aggregate( function. I haven’t tested this so theere could be a minor typo but you should be able to calculate this value with a single line of code!

let lvDeclineTotal({ASK},"sum",{arraysearch(lvArDecline,memno,1,cr())>0}

The aggregate( function is one of the most powerful features that are new in Panorama X, it makes it so much easier to perform calculations like this.

In thinking about this further, why are you using arraysearch(? Seems like arraycontains( would do the same job and be slightly clearer.

let lvDeclineTotal({ASK},"sum",{arraycontains(lvArDecline,memno,cr())}

Jim:
Thanks. I’ve never tried the aggregate function, so I will give it a try.

As for your question, I have three different variables holding different sets of numbers that I was processing. I was just showing the section that was giving me problems, though all three sections were identical except for the the specific variable and their contents.

The minor typo when writing about the minor typo is a nice touch;>

I wish I could say I did that on purpose. :roll_eyes: