Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
agustinbobba
Partner - Creator
Partner - Creator

Execution finished by For Statement

Hi,

In my script I use an iteration statement for several loads, then I load other tables; something like this:

LET v.Product = NoOfRows('$(v.ProductTable)');

FOR i=0 to $(v.Product)-1

     Load *

     Resident AA;

Next;

ProductDetail:

Load *

Resident [Product Detail];

I execute the Script without Errors, but then realized that the execution of the script was not complete.

Then I saw on the log and I found that the variable v.Product was equals to -1, so never load the table ProductDetail; this table is out of the for statement.

My log:

25-Apr-16 11:46:47: 5437  FOR i=0 to -1

25-Apr-16 11:46:48:      Execution finished.

This is a bug?, when the for is from 0 to -1 the scipt stop without error message.

Thank!

Agustín

[Ediit] FOR i=0 to $(v.Product)-1

1 Solution

Accepted Solutions
agustinbobba
Partner - Creator
Partner - Creator
Author

I am trying to reproduce the same scenery in a example but I can't.

But I found the problem but like you said QV start to beheva weird, the thing is that below the for i have a drop table to the table Product.

FOR i=0 to $(v.Product)-1 

  TRACE For statement;

  

    LET v.Table = DATE(Today(),'YYYYMMDD');

  NOCONCATENATE

  [$(v.Table)]:

     Load * 

     Resident AA; 

Next; 

DROP TABLE $(v.ProductTable);  

If the v.productTable doesn't exist, the 'drop table' shows error message. But in my code only end the execution. In the example actually shows a error message.

4/25/2016 3:50:36 PM: 0034  LET v.Product = NoOfRows('Product')

4/25/2016 3:50:36 PM: 0036  FOR i=0 to -1 

4/25/2016 3:50:36 PM: 0048  DROP TABLE Product

4/25/2016 3:50:36 PM:          Execution finished.

If my code I put a trace statement before and after the drop table QV says doesn't exist the table and shows a error message.

dt.png

Yes, this is weird..

Well!, thank all for your comments

Agustin.

View solution in original post

14 Replies
sinanozdemir
Specialist III
Specialist III

Did you mean to put $(v.Product) - 1 instead of $(v.ProductTable) - 1?

Try with $(v.Product) since that's the variable storing the number of rows.

Thanks

trdandamudi
Master II
Master II

I think it should be:


FOR i=0 to $(v.Product) - 1 

agustinbobba
Partner - Creator
Partner - Creator
Author

Sorry my example was wrong, yes the FOR statement is like you said: FOR i=0 to $(v.Product)-1

sinanozdemir
Specialist III
Specialist III

Then either something is wrong with v.ProductTable variable. Take a look at if this variable is empty.

agustinbobba
Partner - Creator
Partner - Creator
Author

Yes indeed, the problem is when this variable is equal to 0, so the FOR fail.

agustinbobba
Partner - Creator
Partner - Creator
Author

Yes, I found the problem, but I don't understand why qlikview cut the execution of the script when the FOR go to 0 to -1, and not shows an error message, only cut the execution.

luis_pimentel
Partner - Creator III
Partner - Creator III

Hi Agustín,

The Qlik script is having the proper behaviour. A loop from 0 to -1 should not fail, since there is no error at all. Just the condition is not met, so the script keeps executing.

I suggest you to control the value of v.Product beforre the FOR sentence, and skip it (or do what you want) in case v.Product = 0.

Regards,

Luis.

agustinbobba
Partner - Creator
Partner - Creator
Author

Yes, I understand that the condition is not met; but is not have the proper behavior, because, below the FOR statement I have other tables to load but qlikview stopped the execution right after the FOR.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Two remarks (each probably worth 1ct so it all sums up to "my 2cts")

  1. The table for which you try to find the number of rows doesn't exist. NoOfRows returns NULL, not 0 because that's a value that indicates an empty but existing table. The FOR loop still has a valid syntax because the $-sign expansion for $(v.Product) will produce nothing and only the -1 part will remain.
  2. FOR i = 0 TO -1 should never produce an error because it isn't an invalid specificaiton. If you consult the QV Desktop help on FOR NEXT, you will discover that the full syntax is: FOR var = expr1 TO expr2 [STEP expr3] meaning that negative step values are allowed and therefore expr2 can be negative as well. The default step value of course is +1, but that doesn't affect the validity of the FOR specification or its workings. The one you have on your hands will just never execute a single cycle.

Best,

Peter