Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
lylererger
Creator II
Creator II

Variable as expression in script

Hi friends!

Help me to use variable as code fragment in script.

I'm using next config file with content:

LET vCycleString = null;

LET vFullReload  = 0;

SWITCH vFullReload

   CASE '0' //----------0 - incremental reload

  LET vYear_Beg_ = Year(Div(Num(MonthEnd(Now(1))),1))-4;

  LET vYear_End_ = Year(Div(Num(MonthEnd(Now(1))),1));

  LET vYearMonth_Beg = Year(vStartDocDate)*100+Month(vStartDocDate);

  LET vYearMonth_End = Year(vEndDocDate)*100+Month(vEndDocDate);

LET vCycleString = 'IF vYM >= vYearMonth_Beg and vYM <= vYearMonth_End then';

  CASE '1' //----------full reload

  LET vYear_Beg_ =2013;

  LET vYear_End_ =2014;

  LET vYearMonth_Beg_ =vYear_Beg_*100+1;

  LET vYearMonth_End_ =vYear_End_*100+12;

LET vCycleString = 'IF vYM >= vYearMonth_Beg_ and vYM <= vYearMonth_End_ then';

ENDSWITCH

And I want to use variable vFullReload to get one condition from two cases. With variables(vYear_Beg_,vYear_End_,vYearMonth_Beg_,vYearMonth_End_) is all ok. But the variable  vCycleString looks like some peace of script. I need to use that variable in script.

But when i'm coding something like $(vCycleString) in script - QlikView doesn't want to interpret as a line of a code.


Help.

Thanks in advance.

1 Solution

Accepted Solutions
Not applicable

Hello!

Have you tried looking at the difference between LET and SET statements? There are helpful examples in the help

You need to use the SET statement with no quotes, otherwise QV will try and evaluate it straight away in the LET.

SET vCycleString = IF vYM >= vYearMonth_Beg_ and vYM <= vYearMonth_End_ then;

Does this work?


Erica

View solution in original post

4 Replies
Not applicable

Hello!

Have you tried looking at the difference between LET and SET statements? There are helpful examples in the help

You need to use the SET statement with no quotes, otherwise QV will try and evaluate it straight away in the LET.

SET vCycleString = IF vYM >= vYearMonth_Beg_ and vYM <= vYearMonth_End_ then;

Does this work?


Erica

fkeuroglian
Partner - Master
Partner - Master

Hi,

The creation of this variable LET vCycleString = 'IF vYM >= vYearMonth_Beg_ and vYM <= vYearMonth_End_ then'; will not work, because you was writen as text with the " ' " you defined as a text.

if you want to use the IF , and THEN statement, you dont have to create as a string

i dont understand what do you want to create in the variable vCycleString, what you expect would be the result

because the wright way is

if(vYM >= vYearMonth_Beg_ and vYM <= vYearMonth_End) then

but not assing this result in a variable, because this will not work

pherphas change the order

example:

if(vYM >= vYearMonth_Beg_ and vYM <= vYearMonth_End) then

let createvariable1,

else

let createvariable2

end if;

hope this help;

lylererger
Creator II
Creator II
Author

Yes Erica ))) Thnx a lot )))

Not applicable

No worries