Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Everyone,
What I mean by the title is in regards to the many Qlik Language script examples I've seen online and at work, where variables are declared once with either the LET or SET keyword and used repeatedly on the same variable through the script, where I am not sure if this is a case of redundancy, taking into account that I do know the usage and purpose of both keywords. Now the question is, is there really any need for anyone to do this?
SET vVariableA = "";
LET vVariableA = someExpression;
or
LET vVariableA = someExpression;
LET vVariableA = aDifferentExpression;
Why not:
LET vVariableA = "";
vVariableA = someExpression;
or
LET vVariableA = someExpression;
vVariableA = aDifferentExpression;
Where we want the variable to hold an empty string if the expression returns null in the first example and a different expression in the second.
Although it appears that once you declare a variable with the SET keyword and called again with SET omitted it appears that the variable is evaluated as an expression (but I am not sure about this), which would mean SET would be required every time you want the value inside to be a string - I would like for this to be confirmed so correct me if I'm wrong, but so far from what I've tried and tested it appears that the latter is accepted by the Language Compiler (or whatever it is or called).
Also I wanted to know if the Qlik Language has any Garbage Collection in place, or do we always have to release memory by doing:
LET vVariableA = something;
then release it at the end of the script:
vVariableA = ; OR LET vVariableA = ;
It's not quite clear for me which points of the Qlik variable-handling isn't clear enough. Therefore here a short try:
SET is assigning everything which is on the right side of the =
LET evaluates what is on the right side of the = and assigned this result to variables
Also I recommend of always using the SET/LET keywords for assigning a variable to be able to differ between both types and to increase the readability of the script. Each re-assigning of any value to this variable overwrites the older ones unless it is NULL which deletes the variable.
Further each variable/field/table which is created and won't be needed in the end must be explicitly removed with a drop-statement or assigning NULL to be deleted.
Many more to these things could you find here: Variables
- Marcus
Hi ,
Below is the explanation for creating variables using LET & SET.
SET is assigning everything which is on the right side of the =
LET evaluates what is on the right side of the = and assigned this result to variables
The examples for LET & SET are
SET 2*5 => Output 2*5
LET 2*5 => Output 10
Thanks,
Venkata Sreekanth
Thank you for the answer but I already know the usage of LET and SET and how to declare such variables, it is a bit long to explain so you'll have to re-read it again.
Thank you for the answer but I am not exactly asking how to use LET and SET or what the purpose of each is, what I am asking is a bit more complicated, basically I'm asking if we can cut the usage of SET and LET on the same variable after its declaration, except when we want to re-assign some value to a SET variable, you'd have to re-read my post, still thank you for trying.
Let is optional. If the Let/Set is omitted Let is assumed. Set is mandatory, so if you want Set behaviour, you must specify Set.
QV script does not require variables to be declared, so the rules are the same whether its the first reference or a subsequent reference to the variable. The downside of this is that QV/QS will not throw an error if you reference an unassigned variable (it will be implicitly set to null).
A few points that may provide some insight:
With respect to your prolonged question (it took me 15 mins. to decypher the description and I'm still not sure that I fully understand what you're after, sorry about that), I think you are actually looking for an AltXX() function that works on any non-null value instead of just numbers. Sort of Default Value for assignments. If you post this as an Idea, you may get it in some future release. I'll immediately vote for it because that would remove a long-time gripe of mine with the current set of functions.
AFAIK there is no Garbage Collection being done in QlikView Script, except for the removal of all Mapping Tables at the very end of a script run. So yes you have to tidy up your environment yourself. But I always found that to be good programming practice. Am I wrong?
Best,
Peter
[Edit] Still some bad grammar. Corrected.