Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
anushree1
Specialist II
Specialist II

For Loop with Sub

Hi,

I was just trying to understand the usage of control statements in qlikview and wrote the below code:

let var1=0;

let var2=0;

//sub a

FOR i = 0 to 10

var1=$(var1)+1;

trace $(var1);

NEXT i

 

//end sub

var2=0+1;

trace $(var2);

  This code works as expected but when i uncomment the statements sub a and end sub I get var1=0 and var2=1.

Could someone please let me know whats the logic here, also please advice how i could gain more understanding on these aspects apart from help file.

Attached is the qlikview for reference

2 Replies
prat1507
Specialist
Specialist

The subroutine has to be called upon from a call statement. Use call a; at the end. PFA the app for your reference.


Regards

Pratyush

Anil_Babu_Samineni

Seems, You are not calling Sub function at the end. It should be like below

let var1=0;

let var2=0;

sub a

FOR i = 0 to 10

var1=$(var1)+1;

trace $(var1);

NEXT i

end sub

var2=0+1;

trace $(var2);

call a

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful