Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
chrisbrain
Partner - Specialist II
Partner - Specialist II

Strange behaviour with for loop and peek?

This is confusing me! I have a table which I can correctly peek at values in using the following:

let y = peek('page', 0, FacebookProConnector_Page);    // y = "value1'

let y = peek('page', 1, FacebookProConnector_Page);    // y = "value2'   

let y = peek('page', 2, FacebookProConnector_Page);    // y = "value3'   

However, in a for loop, e.g.:

let noRows = NoOfRows('Table1');

for i=0 to $(noRows) // loop through every row

     let y = peek('page', $(i), Table1);

     // Additional load statement to other table here

next

I get weird behaviour.

- in the first iteration (i=0), y is correctly 'value1'

- In the second iteration (i=1), y = NULL ?????

But this only happens if I have the additional load statement (where the comment is above) present. If I remove the inner load to another table (and just have an empty loop) it seems to work ok.

I can't see what I could be doing wrong - would appreciate any ideas.

This is happening QlikView 9 desktop.

beeido.com - BI | Software | Qlik Integration Services
GitFirst - A CI/CD solution for Qlik Sense
1 Solution

Accepted Solutions
Not applicable

Hi Chris,

When I added quotes around the 'table name' it seemed to work, so:

let y = peek('page', 0, 'FacebookProConnector_Page');

instead of

let y = peek('page', 0, FacebookProConnector_Page);

View solution in original post

10 Replies
martin59
Specialist II
Specialist II

Hi,

What is you Additional load statement ?

chrisbrain
Partner - Specialist II
Partner - Specialist II
Author

Structurally it is along the lines of this.

for i=0 to $(noRows) // loop through every row

     let y = peek('page', $(i), Table1);

     let x = peek('page_id', $(i), Table1);

 

                    Table2:

                    LOAD

               $(x) as field_id,

               field1,

               field2,

               etc.

         FROM

                    [http://localhost:5555/QVSource/Connector/?config=$(y)]

                    (txt, utf8, embedded labels, delimiter is '\t', msq);

 

next

beeido.com - BI | Software | Qlik Integration Services
GitFirst - A CI/CD solution for Qlik Sense
martin59
Specialist II
Specialist II

I see anything wrong.

Have you a value for i=2, i=3 or always NULL ?

Is your X variable is in numeric format ?

Not applicable

Hi Chris,

When I added quotes around the 'table name' it seemed to work, so:

let y = peek('page', 0, 'FacebookProConnector_Page');

instead of

let y = peek('page', 0, FacebookProConnector_Page);

chrisbrain
Partner - Specialist II
Partner - Specialist II
Author

Thanks rsmeding! - That fixed it!

The QlikView docs/help file seems to suggest you don't need/use the apostrophes but it seems you do.

beeido.com - BI | Software | Qlik Integration Services
GitFirst - A CI/CD solution for Qlik Sense
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi Chris,

This is a common error and a difficult to debug issue. There used to be an article in the old wiki about it but that wiki is now gone.

What happens is this. Without the quotes, the tablename is not correcly resolved and so defaults to the current table. When you add the load statement, you change the current table to a table that did not contain field "page".

-Rob

//http://robwunderlich.com

chrisbrain
Partner - Specialist II
Partner - Specialist II
Author

Hi Rob,

Thanks for the additional info - good to know it wasn't just me..

beeido.com - BI | Software | Qlik Integration Services
GitFirst - A CI/CD solution for Qlik Sense
rbecher
MVP
MVP

Hi all,

they should change or mention this in the doc. There are several issues in the doc we've pointed out earlier. Maybe we can collect those things in the QlikBug group.

- Ralf

Astrato.io Head of R&D
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I started to write a bug report and then realized this is not a bug, although it could probably use some clarification. It's legal to use a fieldname to reference the tablename, in which case you would not quote. For example:

data1:

LOAD * INLINE [

V1

1

2

];

data2:

NOCONCATENATE LOAD * INLINE [

V1

5

6

];

control:

LOAD * INLINE [

Table

data1

data2

];

new:

LOAD

          Table,

          peek('V1', 0, Table) as PeekVal

RESIDENT control;