Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

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

13 Replies
datanibbler
Champion
Champion
Author

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?

marcus_sommer

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

marcus_sommer

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
Champion
Champion
Author

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.

Colin-Albert

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.

marcus_sommer

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
Champion
Champion
Author

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.

marcus_sommer

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
Champion
Champion
Author

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...)