Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
datanibbler
Esteemed Contributor

Large loop - keywords five tabs apart


HI,

I always split my script into several parts, one part of the script on one tab.

Now I have one large loop that encompasses two subroutines and several more loops

=> To the effect that the keywords "FROM ..." and "NEXT" are five tabs apart

There should actually be no big issue about that - I can easily put "NEXT [Counter]" instead of just "NEXT" and it should be clear for QlikView what is what

<=> It doesn't work: I have tested what is to be my meta_loop on its own - it parses through an inline_table with six sheet_names which  correspond to the names of worksheets in an Excel_workbook.

<=> Still, when I activate this meta_loop around all the other stuff - the first time round, my counter_variable (which is not identical to
           any of the "inner" ones, I have named them all differently) is populated all right and so is the variable for the worksheet I'm
           currently processing, but after the first iteration is completed, the variable has a NULL value ...

Can anyone help me there?

Thanks a lot!

Best regards,

DataNibbler

Tags (2)
13 Replies
datanibbler
Esteemed Contributor

Re: Large loop - keywords five tabs apart

Hi,

there is another way I could try: By making it all into one big subroutine

<=> Can I define a subroutine which contains several others?

Re: Large loop - keywords five tabs apart

Hi DataNibbler,

I think it's only a small (unexpected) logic-issue. I would run these script within the debugger to see on which step your variable becomes NULL.

- Marcus

Re: Large loop - keywords five tabs apart

You could create a routine which called many sub-routines and this is often better then jump from one routine to another and from there jump again ...

- Marcus

datanibbler
Esteemed Contributor

Re: Large loop - keywords five tabs apart

Hi Marcus,

I am stepwise_debugging all the time ;-) With the first vrs., the variable (current_list) became NULL just when the first iteration was completed and I was back in the meta_loop.

I'm trying the thing with a meta_subroutine now (that will encompass the two other subroutines).

The difficulty is, I need to pass two variables now - a counter_variable and the current list_name.

I'll keep you posted.

Re: Large loop - keywords five tabs apart

Hi DataNibbler.

I often add TRACE commands to output various variables whilst processing the loop so I can debug exactly what is going on from the log files or load progress window without the need to invoke the debugger.

I also add a "Trace === TabName=== ;" as the first line of every tab.

Re: Large loop - keywords five tabs apart

Hi DataNibbler,

it looks that these variable will be defined several times - first in your meta-loop and then in your sub-routine and then in your meta-loop again  - if yes you need some logic, either you worked with two variables and/or you need to check if the variable-value had changed.

- Marcus

datanibbler
Esteemed Contributor

Re: Large loop - keywords five tabs apart

Hi Marcus,

no - I am aware of that issue, so I'm trying to give a new name to each one of my variables and I assign them a NULL value when they are not needed anymore so there can't be any confusion.

I have now successfully established a meta_routine that is called once for every one of my six sheets (six times) and that will itself call the two other subroutines. That works - but only for the first sheet (in the first iteration, my counter "superi" has the value 0 because I use the PEEK() fct. from a small inline_table to determine the name of the sheet to process.

<=> In the second iteration, "superi" has the value 1 and the table_name becomes NULL. I have yet to find out why that is happening.

Best regards,

DataNibbler

P.S.: I am at a loss - when I try only that LOOP, I deactivate the CALL statement and put an EXIT SCRIPT directly after the loop, then it works - I debug it step_by_step and the current_list_variable is properly updated every time.

When, on the other hand, I activate the CALL statement and thus have all the code inbetween, then for the second iteration, "superi" (my counter) is updated from 0 to 1 - and my current_list_variable gets assigned a NULL value ...

P.P.S.: I have just performed a backward search across all tabs for the name of that counter_variable in that meta_loop, but it is definitely unique.

Re: Large loop - keywords five tabs apart

Hi DataNibbler,

maybe it's really peek() whereat it generally worked good as loop through a table. Perhaps your syntax missed the tablename: peek('field', $(counter), 'tablename') ?

- Marcus

datanibbler
Esteemed Contributor

Re: Large loop - keywords five tabs apart

Hmm ... it generally works very well, yes.

I didn't put the tablename into quotes - I wrote like

>> peek('Name', $(v_List), Sheetnames) <<

I will try with putting both in quotes.

(just to be sure, I tested it again and it is definitely just at the start of the second iteration...)

Community Browser