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: 
Not applicable

FOR ... NEXT + DO while LOOP

Hi All,

I'm loading web data from several links. It happens that a request returns no data (supposedly web server issues) but if requested again it does return the data. I need to implement DO while LOOP into the below code so that when the requests returns no data the loop requests again until it gets the data. I've tried with FieldValue but ended up with errors. Any help will be much appreciated.

Links:

LOAD * Inline [

http://www.rates1.com

http://www.rates2.com

http://www.rates3.com

];

Rates:

LET vNoOfLinks = NoOfRows('Links');

FOR i=0 to $(vNoOfLinks)-1;

LET vLink = Peek('Link',$(i),'Links');

LOAD

  [@1:n] as Data

FROM $(vLink) (fix, utf8);

NEXT

Regards,

Przemek

1 Solution

Accepted Solutions
MarcoWedel

Hi,

maybe like this?:

Links:

LOAD * Inline [

Link

http://www.rates1.com

http://www.rates2.com

];

LET vNoOfLinks = NoOfRows('Links');

FOR i=0 to $(vNoOfLinks)-1;

LET vLink = Peek('Link',$(i),'Links');

LET vNoOfRowsRates = Alt(NoOfRows('Rates'),0);

DO

  Rates:

  LOAD

  [@1:n] as Data

  FROM $(vLink) (fix, utf8);

LOOP until NoOfRows('Rates') > $(vNoOfRowsRates);

NEXT;

hope this helps

regards

Marco

View solution in original post

12 Replies
MarcoWedel

Hi,

one solution could be:

QlikCommunity_Thread_143360_Pic1.JPG.jpg

Links:

LOAD * Inline [

Link

http://www.rates.com

http://www.rates1.com

http://www.rates2.com

];

LET vNoOfLinks = NoOfRows('Links');

FOR i=0 to $(vNoOfLinks)-1;

LET vLink = Peek('Link',$(i),'Links');

Rates:

LOAD

  [@1:n] as Data

FROM $(vLink) (fix, utf8);

NEXT;

hope this helps

regards

Marco

Not applicable
Author

Hi Marco,

the file you've attached is just a reloaded code of mine? Am I missing something?

Regards,

Przemek

MarcoWedel

Hi Przemek,

I thought you needed a version of your code that does not throw errors or am I missing something?

regards

Marco

Not applicable
Author

Ok. Let me put this way - I run the above code, the for...next loop requests data from 3 web links. Now, link 2 returns no data because of some web server error so I end up with data from link 1 and link 3. I know that at link 2 there is some data stored and if I run the code above I will most probably get the data from link 2. So, to avoid reloading whole script I want to put in do while loop to loop until every single link returns data.


In my script there's over 50 links so the do while loop must be nested into for ... next loop not the other way round.

Regards,

Przemek

MarcoWedel

Hi,

maybe like this?:

Links:

LOAD * Inline [

Link

http://www.rates1.com

http://www.rates2.com

];

LET vNoOfLinks = NoOfRows('Links');

FOR i=0 to $(vNoOfLinks)-1;

LET vLink = Peek('Link',$(i),'Links');

LET vNoOfRowsRates = Alt(NoOfRows('Rates'),0);

DO

  Rates:

  LOAD

  [@1:n] as Data

  FROM $(vLink) (fix, utf8);

LOOP until NoOfRows('Rates') > $(vNoOfRowsRates);

NEXT;

hope this helps

regards

Marco

Not applicable
Author

Beautiful! Thank you.

MarcoWedel

You're welcome

Regards

Marco

Not applicable
Author

Hi Marco,

I'm struggling with another loop - a tuned version of the last one.

Table 'Rates' consists of sets of data from Links. Each Link set (except the last one) should have exactly 10 records including '*increase*' string. However, due to web server issue, a load from a Link happens to return less than 10 records with the string. In such cases I need to load the data again from this very Link. The last Link set may return less than 10 records and that's ok.

Any idea how to play this scenario?

Regards,

Przemek

Anonymous
Not applicable
Author

Why You do this inside Qlik View  ?

Regards

AC