Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
surajap123
Creator II
Creator II

variable creation script

Hi All,

To load variables from external file the below script works and i can see all the variable in variable overview window after the reload.

VariablesTable:

LOAD VariableName, VariableValue

FROM

[QVDStore\VariablesTable.QVD]

(qvd);

for i=0 to noofrows('VariablesTable')-1

LET var_name= peek('VariableName',i,'VariablesTable');

LET $(var_name) = peek('VariableValue',i,'VariablesTable');

next i

I cannot understand how the above 2 LET statements can able to create a variable and load value into the variable?

-The confusing part is, how the variable with DSE $(var_name) is loading value into the variable?

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Try using the debugger to step through the execution of the script step by step. You can follow what happens that way and see the values of the variables at each step.


talk is cheap, supply exceeds demand

View solution in original post

5 Replies
Gysbert_Wassenaar

The first LET statement gets the name of the variable you want to create and stores it in the variable var_name. Then the next LET statement uses that var_name variable to create a variable with then name of the variable that was retrieved from the table in the first LET statement. That's why the dollar expansion is used in the second LET statement.


talk is cheap, supply exceeds demand
surajap123
Creator II
Creator II
Author

Thanks for the reply Gysbert.

First of all, may be i never saw statement having LET with DSE. So I am still confused, about how it works.

-The 2nd LET statement is using the already existing variable(var_name, containing 1st value in field VariableName).

I think, in general DSE is only to evaluate the content and return the result, but how the $(var_name) is loaded with Value(VariableValue) to the existing variable var_name ??

Gysbert_Wassenaar

Try using the debugger to step through the execution of the script step by step. You can follow what happens that way and see the values of the variables at each step.


talk is cheap, supply exceeds demand
Peter_Cammaert
Partner - Champion III
Partner - Champion III

Enable log file generation and have a look at the resulting log file. You will see DSE in action.

BTW Dollar-sign expansion in this case is not about content evaluation, it's all bout text substitution. Before evaluating every individual statement and executing it, the script engine will pre-process a statement and replace all occurences of things that look like $(...) by the output of the pseudo-expression between the parentheses. This works recursively (you can embed dollar-sign expansions within DSE's). When all expansions have been performed, the resulting statement text will be fed to the script engine for proper execution. That last statement format is what is being printed in the log file.

Peter

surajap123
Creator II
Creator II
Author

Thanks Peter for the clear explanation.

-I understood how it works using debugger.

Yes, the 2nd LET statement is actually reading $(var_name) as vVar which is a value of var_name(created in 1st LET statement).