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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
SonPhanHumanIT
Contributor III
Contributor III

Include in Loops

Hello Qlik Experts,

I am experiencing an issue where including commands within a loop does not work as expected. However, I have noticed that when I place the "include" statement outside the loop, the function functions properly. Could you provide any insights into why this might be happening? The include statement got a subroutine. (When i include a example table it works), but it doesnt work for subroutines.

 

FOR EXAMPLE:

FOR EACH vSub IN FieldValueList('SUBROUTINE')
Trace $(SCRIPT_PATH_PA_SUB)$(vSub).qvs;
    $(include=[lib://DemoSystem/script/sub/CalendarFromField.qvs]);
NEXT
 
Best regards Son
 
 
 
 
Labels (1)
1 Solution

Accepted Solutions
marcus_sommer

I think you are struggling with the validity of variables because within script control statements created variables are not global variables. It's a common behaviour of programming tools and also the basis below the Qlik script-layer.

I have also dozens of include-variables with a lot of path/file-formatting/connections variables, functions and routines, various loads, comments and tags and so on and also cleaning/finishing (dropping tables/fields/variables, renaming them, moving/storing sources/log-files and so on) the load in the end.

The common ones are logically grouped in another one and even those are partly also grouped. So I need just to specify a few includes at the beginning and the end - the common ones and the specific ones (for example section access tables).

View solution in original post

6 Replies
Kushal_Chawda

@SonPhanHumanIT  I think you need to call your subroutine  in the loop to work it properly

Call SubRoutine_Name;

SonPhanHumanIT
Contributor III
Contributor III
Author

thanks for the info, unfortunately I will need this outside the loop!

Kushal_Chawda

@SonPhanHumanIT  what you are trying to achieve in loop?

SonPhanHumanIT
Contributor III
Contributor III
Author

I possess several subroutines that are based on an Excel file. I will include the necessary subroutine from the file, which will be required in the script at a later stage.

Kushal_Chawda

@SonPhanHumanIT  I have just tested that if you call the sub routine within loop using include statement it works.  So Include statement in loop should work fine it's just that you need to call subroutine within loop itself instead outside of loop like below. 

If you want to call your subroutine outside of loop you need to again call the include statement outside of the loop to work as expected which will work only for last iteration of loop. 

FOR EACH vSub IN FieldValueList('SUBROUTINE')
Trace $(SCRIPT_PATH_PA_SUB)$(vSub).qvs;
    $(include=[lib://DemoSystem/script/sub/$(vSub).qvs]);
    Call $(vSub) ;
NEXT
marcus_sommer

I think you are struggling with the validity of variables because within script control statements created variables are not global variables. It's a common behaviour of programming tools and also the basis below the Qlik script-layer.

I have also dozens of include-variables with a lot of path/file-formatting/connections variables, functions and routines, various loads, comments and tags and so on and also cleaning/finishing (dropping tables/fields/variables, renaming them, moving/storing sources/log-files and so on) the load in the end.

The common ones are logically grouped in another one and even those are partly also grouped. So I need just to specify a few includes at the beginning and the end - the common ones and the specific ones (for example section access tables).