Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Read about the latest Qlik Community enhancements on the Community News blog!
cancel
Showing results for 
Search instead for 
Did you mean: 
olegsavinkov
Contributor
Contributor

Do While ...Loop continued working after the condition became invalid

Hello!

I write some code as

set FirstYear=2016;

Let CurrentYear = Year(Today()); //2018

......

DO while $(FirstYear)  <= $(CurrentYear)

             $(vTable)__c_Final:

                              SQL SELECT  *

                               FROM

                               $(vTable)  Where CreatedDate>= $(FirstYear)-01-01T00:00:00.000+0000 and CreatedDate<= $(FirstYear)-12-31T00:00:00.000+0000;

                                 Let  FirstYear = $(FirstYear)+1;

                                 DROP $(vTable)_Final

                                  SLEEP 1000;

LOOP

....

This code started working and continued working after the condition became invalid! It works with FirstYear = 2016 (true), 2017 (true), 2018(true), 2019 ( false!!) and so on. And when I debug it I don't see "Do.." string in debug cycle. When I write condition in 'LOOP' string, cycle works true:

DO...

LOOP  while $(FirstYear)  <= $(CurrentYear)

works true.

Could you please tell me why cycle does not   work in first case?

1 Solution

Accepted Solutions
rwunderlich

You should not use $() around FirstYear in the Do condition:

DO while FirstYear  <= $(CurrentYear)


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

View solution in original post

6 Replies
Digvijay_Singh

not sure but I think you don't need to use 'Let' in below statement as the variable is already defined at the top, looks like its kind of creating FirstYear newly inside the loop -

  Let  FirstYear = $(FirstYear)+1; change this to


FirstYear = $(FirstYear)+1;



rwunderlich

You should not use $() around FirstYear in the Do condition:

DO while FirstYear  <= $(CurrentYear)


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

View solution in original post

olegsavinkov
Contributor
Contributor
Author

No, I used this code


FirstYear = $(FirstYear)+1; 


and had same result.

olegsavinkov
Contributor
Contributor
Author

No, you code don't work too

olegsavinkov
Contributor
Contributor
Author

Sorry!!!!! I hurried.

You where right!

onmysi49
Contributor III
Contributor III

Hello Rob,

I have a question regarding this very old post.

Today I also found out that using dollar sign expansion does not work in certain cases. See my case below:

Do while ($(#vRefDate) <= $(#vEndDate))
.
.
.
Let vRefDate = AddMonths($(#vRefDate),+1);
Loop

This does not work. I have to either move the condition to the end of the loop like this:

Do
.
.
.
Let vRefDate = AddMonths($(#vRefDate),+1);
Loop while ($(#vRefDate) <= $(#vEndDate))

Or I have to remove the dollar sign expansion from vRefDate variable in the condition like this:

Do while ((vRefDate) <= $(#vEndDate))
.
.
.
Let vRefDate = AddMonths($(#vRefDate),+1);
Loop


But my question is why? What is the cause that the Loop while works with dollar sign exp. and Do while does not? From time to time I am confused by behaviour of dollar sign expansion, which is quite tricky to understand in different use cases.

I only found this https://support.qlik.com/articles/000073866 article but that does not give me the explanation.

Thanks a lot. Have a great day.