Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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.
Yes, this is weird..
Well!, thank all for your comments
Agustin.
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
I think it should be:
FOR i=0 to $(v.Product) - 1
Sorry my example was wrong, yes the FOR statement is like you said: FOR i=0 to $(v.Product)-1
Then either something is wrong with v.ProductTable variable. Take a look at if this variable is empty.
Yes indeed, the problem is when this variable is equal to 0, so the FOR fail.
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.
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.
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.
Two remarks (each probably worth 1ct so it all sums up to "my 2cts")
Best,
Peter