Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
LINKEDIN LIVE: Democratizing data to enhance customer-centricity. JULY 29TH REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

For loop slows down, why?

Hi!

I use for .. next loop to go through one table row by row and I add with autogenerate line/lines if there is missing line.

This loop works quite fast when it is just started. I get about 20 rounds in minute. But after one or two hour, this loop is running very slow.

Then I get about 2 new lines in minute. This is 10x speed difference.

And if I abort manually for... next loop and replace starting value from 1 to the value it was before aborting, then loop is running again normally.

Has someone else noticed this kind of slowliness with long running for .. next loops. And is there any solutions to fix this.

Thank you,

Harri

Here is the for loop (sorry if the

tagging is not working, i tried...)


for i=1 to NoOfRows('TR_Hist_Sorted')-1

//read values from current row and store value from above to another variable
LET moment_before=$(ajankohta_nyt);
LET moment_now=PEEK('SMONTHENDKEY',$(i),'TR_Hist_Sorted');

LET product_before='$(product_now)';
LET product_now=PEEK('S%%%ITEMKEY',$(i),'TR_Hist_Sorted');

LET value_before='$(value_now)';
LET value_now=PEEK('SQTY_OH',$(i),'TR_Hist_Sorted');

//calculate current row´s and row above time difference.
LET difference=$(moment_now)-$(moment_before);

//if product is same, lets make missing rows with for next loop
// if time difference is 1 then this next loop is not done because we have 1 to 0 in loops definition
IF '$(product_now)'='$(product_before)' then
for adding_loop=1 to ($(difference)-1)
concatenate(TR_Hist_Sorted)
//lets build missing row with autogenerate
load
'$(product_now)' as S%%%ITEMKEY,
($(moment_now))-($(adding_loop)) as SMONTHENDKEY,

$(value_before) as SQTY_OH,
applymap('Month_Key_Map',($(moment_now))-($(adding_loop)),'N/A') as SMONTH_END_DATE
autogenerate(1);
next // now we have added one missing row for one product
end if // End of "is this same product"
next // next line in main table


1 Reply
Not applicable
Author

Hi,

Maybe this is an idea to solve your problem without a loop.

Good luck!

Rainer