Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

nicolas_martin
Contributor II

Problem with peek()

Hello,

I would like to loop on every value of a field, with the "peek" function.

The following code works:

Table1:

LOAD * INLINE [

Field1

Aaa

Bbb

Ccc

];

LET nbVal = FieldValueCount('Field1');

FOR _i = 0 TO nbVal - 1

  LET _val = peek('Field1', _i);

  LET _res = MsgBox('$(_val)');

NEXT _i

This will pop up "Aaa", "Bbb" and "Ccc".

But if I load another table between the table and the loop, it doesn't work anymore:

Table1:

LOAD * INLINE [

Field1

Aaa

Bbb

Ccc

];

LET nbVal = FieldValueCount('Field1');

Table2:

LOAD * INLINE [

Field2

1

2

3

];

FOR _i = 0 TO nbVal - 1

  LET _val = peek('Field1', _i);

  LET _res = MsgBox('$(_val)');

NEXT _i

I don't understand why loading another table prevents the "peek()" to succeed.

If I'm adding the table:

LET _val = peek('Field1', _i, 'Table1');

it works.

Does that means the function "peek" with 2 parameters is not reliable?

1 Solution

Accepted Solutions
nagaiank
Valued Contributor III

Re: Problem with peek()

The Reference manual states that if the Tablename argument is not specified, the current table is assumed. If you want to refer any table other than the current table, you need to specify the table.

6 Replies
neetha_p
Honored Contributor

Re: Problem with peek()

Hi,

Table1: 

LOAD * INLINE [ 

Field1 

Aaa 

Bbb 

Ccc 

]; 

 

LET nbVal = FieldValueCount('Field1'); 

 

Table2: 

LOAD * INLINE [ 

Field2 

]; 

 

FOR _i = 0 TO nbVal - 1 

  LET _val = peek('Field1', _i,'TableName');  //Give table name here when another table in between

  LET _res = MsgBox('$(_val)'); 

NEXT _i 

nicolas_martin
Contributor II

Re: Problem with peek()

Indeed, but I would like to understand why.

The "Field1" field is only in the table "Table1". Why do I have to make the precision?

neetha_p
Honored Contributor

Re: Problem with peek()

Hi,

The Peek() function can be used in a load to retrieve data from the same table or from another table. in these case the table name is mandatory, as table which we are refering is not immediate table in the script.

nagaiank
Valued Contributor III

Re: Problem with peek()

The Reference manual states that if the Tablename argument is not specified, the current table is assumed. If you want to refer any table other than the current table, you need to specify the table.

nicolas_martin
Contributor II

Re: Problem with peek()

Thank you.

I misunderstood the meaning of the phrase in the Reference Manual.

I thought it was "it takes the last table having this field".

neetha_p
Honored Contributor

Re: Problem with peek()

Hi Nicolas,

The Peek() function can be used in a load to retrieve data from the same table or from another table. in these case the table name is mandatory, as table which we are refering is not immediate(Current) table in the script.

Community Browser