Zlog causing different outcome

field Date
sortup
zlog  "Selected: " + info(“selected”) 
firstrecord
let Distance_val = Distance
CDistance = Distance
let CDistance_pval = CDistance
loopwhile not info("eof") 
   zlog  "Selected: " + info(“selected”)         <----  Comment out
   downrecord
   CDistance = Distance + CDistance_pval
   let CDistance_pval = CDistance
   zlog id
   zlog CDistance
endloop

When I comment out the zlog statement the loop ends on the last record and I need to handle the last record properly. If I uncomment the zlog all records are addressed without me needing to handle the last record. Why is there a different execution occurring when using the instrumentation logging?

Initially, the loop was not addressing all records that were selected. When I added the zlog statement to check the select record counts my loop started working as expected.

Please advise why I am seeing different execution with and without the zlog messages.

Thank you,
Robb

I’m not sure about that, but in general, when looping through all records, I find it best to use loop ... downrecord ... until info("stopped") (or the loopwhile equivalent).

info("eof") returns true() while on the last record. Thus if you have ten records, for the first nine it returns false() and after the ninth downrecord it returns true(). On the other hand, info("stopped") only returns true(), to end the loop, after the tenth downrecord, allowing all records to be processed in the same way.

The same kind of situation caught me out several times in my early days using Panorama X. info("eof") has its uses, but not for stepping through a whole database in my experience.

Also, using arraybuild to build a temporary array from a one or more fields in the database, then looping through it using looparray — or even better, when applicable, processing it using arrayfilter( —, is generally far quicker than a loop of the form firstrecord loop ... downrecord until info("stopped")

Thank you. I am still seeing the loop end earlier than expected.

When I run without the zlog statement.
[Rowhouse Stats/cdistance-gen] id:496
[Rowhouse Stats/cdistance-gen] id:22

When I run with the log statement
Rowhouse Stats/cdistance-gen] id:496
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:528
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:561
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:562
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:2
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:25
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:24
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:23
[Rowhouse Stats/cdistance-gen] Selected: 40
[Rowhouse Stats/cdistance-gen] id:22

Is there a status or something that would cause the last few records to not be processed?

Robb

@RobbK - I cannot duplicate your results. I constructed a loop with the same logic as yours and it worked fine both with and without the zlog statement. I tried both commenting out the zlog statement and removing it entirely, it worked either way.

@pcnewble, I tend to agree with you, but Robb’s logic should work.

I think the simplest version of this would be:

field Date
sortup
firstrecord
let CDistance_pval = 0
loop
    CDistance = Distance + CDistance_pval
    CDistance_pval = Distance
    downrecord
until info("stopped")

Note that with this solution the special logic to process the first record before the loop starts is not necessary. Also, I got rid of the Distance_val variable since it was never used. Also, I think if this was my code I would use the variable name runningDistance instead of CDistance_pval. That would more clearly show the intent.

But wait! I think this can be MUCH simpler and faster.

field Date
sortup
field CDistance
formulafill Distance
runningtotal

Sometimes a benefit of simplifying the logic is that it can help you understand what you are really trying to do, and then an even better solution becomes apparent.

@admin Thank you for reviewing.
I will try your versions to see if I experience the same issue.
I appreciate your input as I am new to Panarama X, and the code is not as familiar.

Thank you,
Robb

In that case, welcome!

Since you’re new to Panorama, you may not be familiar with the running total operation. Here’s the help page for this.

If I’m understanding your application correctly, running total is the perfect feature for your task.

This worked great. I appreciate the assistance.

Robb