Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
blaise
Partner - Specialist
Partner - Specialist

calling sub-routine with table creation breaks peek()

Hello

Im developing an application where i first produce a list of field values that a later on send to a sub-routine that uses the field value when creating a table.

It works as expected if i do not create a table inside my sub-routine but the peek('fieldname',$(i)) I use to get the field value from the first table to send to the sub-routine only works for i = 0 (or the first peek() used.

Any suggestion that the issue could be?

I've attached a small qv app that shows the issue, setting the last parameter in the sub-routine call to 'Y' breaks the peek(). Setting it to 'N' everything is working as expected (as no table is created inside the sub-routine).

Script:

sub ffs(inputMonth,createTableYN)

  trace inside sub-routine month is '$(inputMonth)';

  if '$(createTableYN)' = 'Y' then

  subTable:

  load

  '$(inputMonth)' as subMonth

  autogenerate 1;

  else

  endif;

end sub;

months:

load

  month(addmonths(yearstart(today()),recNo())) as month

autogenerate 12

;

// by creating a table in the sub-routine call (last parameter = 'Y') the peek will cease to function properly as only first value is fetched

for i = 0 to fieldvalueCount('month')-1

  Let vMonth = peek('month',$(i));

  call ffs('$(vMonth)','N');

next;

App has been tested in 11.2 SR4 and 11.2 SR6 with the same result.

Br Johan

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

The Peek() function always fetches data from the latest created table - unless you use the third parameter. So, the solution is probably to use the third parameter:


Let vMonth = peek('month',$(i),'months');

HIC

View solution in original post

4 Replies
hic
Former Employee
Former Employee

The Peek() function always fetches data from the latest created table - unless you use the third parameter. So, the solution is probably to use the third parameter:


Let vMonth = peek('month',$(i),'months');

HIC

Peter_Cammaert
Partner - Champion III
Partner - Champion III

I guess QlikView Script Engine isn't really re-entrant.

blaise
Partner - Specialist
Partner - Specialist
Author

Ouch, what a newbie mistake!

Thanks Henric, and sorry for taking up your time with such simple questions

tresesco
MVP
MVP

You probably need a Concatenate, like:

if '$(createTableYN)' = 'Y' then

Concatenate

  subTable:

  load

   '$(inputMonth)' as subMonth

  autogenerate 1;