Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
DennisvD
Contributor II
Contributor II

How to integrate a do while loop within a for each loop

Hello,


I'm facing the following problem and hope I can explain it well.

There is the following table

Table:

Item | Status | Alternative item

A       |     x        |     B

B      |     x        |     D

C     |              |      I

D    |        x        |    E

E    |                  |   H

F    |                  |  K

For this  I need the following calculation.

If Item is not available (x), there needs to be a check on the alternative item.

I need to know from each item which is the available alternative and the road to it.
Table Solution would look as following

Aggr | Item | Alternative Item

A       |    A      |   B

A      |    B      |    D

A      |    D     |     E

B    |     B      |     D

B   |     D      |     E

D   |    D      |     E

So the check is only done for items that are not available untill first available substitute is found. The items won't be in order, because can replacements can be added any time and removed at any time too (so i dont think peek or previous can be used).

So  an applymap() will be used to find the replacement item. This data is available (in my eyes basically the table itself, because all this information is in the table).

My idea was to start with put filter on table to only check if status is 'x' and where there is an alternative item

Then comes to outerloop,  (for each loop).

For each vItem in FieldValueList('Item') (this is to check for all items which arent filtered out and to get the field: Aggr

But then comes my problem, how can I add her a do while loop. To keep searching till condition is met (applymap doesnt have a postitive result). My idea was to have vItem to aggr column and also items for the first loop (row) which gives me a replacement item with applymap on the input.

Then this needs to be saved in a variable to get the replacement item for that current item. (then row 1 is done)

And after that the replacement item needs to moved to a new row in the item column to use as input again for the applymap() (row 2) untill  there is no replacement is found.  After that u go to the next item in Item column and start it all over again till all Items are done

Is this possible and how would I need to write this? My main problems are:

- how to set the variables so they can be used in the loop and that after row 1 the outcome from the mapping will become item of next row and by that also the input of the next mapping iteration untill conditon is met and broken out of innerloop.

- How to nest the do while loop in the for each loop.

 

 

Labels (3)
10 Replies
Saravanan_Desingh

Also if u find my solution as acceptable, please mark it. You can mark more than one response as solution.