Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Peek function is not working in for loop

Hi,

See the below code:

DistinctLotNo:

LOAD Distinct LotNo as DistLotNo

FROM

Table1

(qvd);

for k =0 to (NoOfRows('DistinctLotNo')-1)

Let data = Peek('DistLotNo',$(k));

LOAD   LotNo,A,B,C,D

FROM

Table1.qvd(qvd)

Where LotNo = '$(data)';

NEXT k

- Here the peek function is not working properly. What i'm saying is for 1st iteration data variable can able to hold the value but in 2nd second iteration the data variable shows the NULL value.

1 Solution

Accepted Solutions
matt_crowther
Luminary Alumni
Luminary Alumni

Take the variable $ and brackets away from your 'k' reference. Eg: 'Let data = Peek('DistLotNo',k,'DistinctLotNo');

Hope that helps,

Matt - Visual Analytics Ltd

View solution in original post

7 Replies
matt_crowther
Luminary Alumni
Luminary Alumni

Take the variable $ and brackets away from your 'k' reference. Eg: 'Let data = Peek('DistLotNo',k,'DistinctLotNo');

Hope that helps,

Matt - Visual Analytics Ltd

Not applicable
Author

Thanks for your help.. I don't know what i did now my code is executing perfectly.

Not applicable
Author

I got problem again but when i use your code it is working perfectly.

swuehl
MVP
MVP

I'm not sure if it's about the variable enclosing in $() or not, but I think it's definitely about using the third parameter to peek function given the table name - you'll need that outside a table load context, I believe.

Not applicable
Author

Swuehl

I don't know where i'm doing wrong. Sometimes my code is working excellently but sometimes not. I'm using every time same data only there is now change in my data.

But if i use the code given by Matt.. It is working everytime for n no. of executions.

swuehl
MVP
MVP

So you don't have a problem then

No seriously, I assume you are comparing your code with Matts.

As said, Matt has indicated the table name with third parameter, I believe that is making the difference. I'm not quite sure why yours seems to work from time to time, and I would have also used the dollar sign variable syntax like in your original code.

But for now, if Matts code is working just fine, you don't have a problem, do you?

Regards,

Stefan

Not applicable
Author

If i use dollar sign in matt code i don't have any problem. Any way it's working fine thanks to share your knowledge also on this.