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: 
datanibbler
Champion
Champion

TRACE - directly enter an expression


Hi,

is there any way I can make the TRACE command put in the log the result of an expression without first putting this into a variable?

I have tried with like

>> $(=Weekday(Today(0))) <<

the way you do in set_expressions, but that didn't work.

I also tried with quotes around the whole, but that didn't work either - then it read like

>> TRACE ' '; <<

in the log, which isn't quite what I want ...

That didn't work, however. I then created a variable first and then put this into the TRACE command, like

>>  LET v_message = Weekday(Today(0)); <<

>> TRACE $(v_message); <<

>> LET v_message = NULL(); <<

That works. That is okay, but it should be possible to use this expression directly, no?

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
marcus_sommer

Hi DataNibbler,

I think it would only directly work if there are a possibilty to create an adhoc-variable within the script, like:

trace $(=function());

Therefore a workaround would be needed, maybe with a subroutine like this which could be outsourced in an include-variable for a global using:

sub ShowTraceStament(typ, statement)

if '$(typ)' = 'string' then

    let vTrace = '$(statement)';

else

    let vTrace = $(statement);

end if

trace $(vTrace);

end sub

call ShowTraceStament('string', 'hallo welt')

call ShowTraceStament('numeric', 'weekday(today())')

- Marcus

View solution in original post

4 Replies
marcus_sommer

Hi DataNibbler,

I think it would only directly work if there are a possibilty to create an adhoc-variable within the script, like:

trace $(=function());

Therefore a workaround would be needed, maybe with a subroutine like this which could be outsourced in an include-variable for a global using:

sub ShowTraceStament(typ, statement)

if '$(typ)' = 'string' then

    let vTrace = '$(statement)';

else

    let vTrace = $(statement);

end if

trace $(vTrace);

end sub

call ShowTraceStament('string', 'hallo welt')

call ShowTraceStament('numeric', 'weekday(today())')

- Marcus

datanibbler
Champion
Champion
Author

Ah.

And those ad-hoc-variables don't work in the script, do they? For that's what I tried ...

Thanks for helping! A subroutine seems to be a little much ado for that, though - and it wouldn't really make things easier for that's pretty much what I have now.

I will try putting some more code in that INCLUDE, that should do the job well enough.

Thanks a lot!

Best regards,

DataNibbler

mmarchese
Creator II
Creator II

Inspired by marcus's helpful answer, I made a simpler version.  (I didn't see any reason for the custom subroutine to handle tracing plain text when the built-in Trace() already does that just fine.)

Sub EvaluateAndTrace(expression)
    Let e = $(expression);
	Trace $(e);
    Let e = ;
End Sub

 

Usage:

Call EvaluateAndTrace('Weekday(Today())');  // Thu

 

Lots of examples to help with understanding the nuances:

Trace hello;                                // hello
Trace Weekday(Today());                     // Weekday(Today())
Call EvaluateAndTrace('Weekday(Today())');  // Thu

Set var = Weekday(Today());
Trace var                                   // var
Trace $(var);                               // Weekday(Today())
Call EvaluateAndTrace(var);                 // Thu

Set innerVar = Today();
Set var = Weekday($(innerVar));
Trace var;                                  // var
Trace $(var);                               // Weekday(Today())
Call EvaluateAndTrace(var);                 // Thu

 

shane_spencer
Specialist
Specialist

Awesome! I'm crunching some very big data and this will allow me to easily tune the script!