Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

Cleanup in script - set variables to NULL

Hi,

in principle I am already doing this: Every variable that is being used in a script is afterwards set to NULL so that I won't eventually end up with obsolete variables that can cause confusion in an app.

I have now a piece of code that loads an Excel_file with the two logons of the developers we have and creates out of those a visibility_condition like

>> OSUSER() = 'SYNCREON\name.surname OR OSUSER() = 'SYNCREON\name2.surname2'  <<

Pretty complex stuff. It's basically all being done in a loop which I will post here.

The challenge is: I already do set the variables to NULL, but I still have the evaluations of the variables left when I run that.

=> How can I set those to NULL?

(  >> SET $(varname) = ; <<  (inside the loop) doesn't work, that would be easy ... )

This is the loop (the Excel_file is attached)

FOR i = 1 TO $(v_admins) // that is the nr. of rows
  LET varname = 'v_admin' & $(i);
  LET $(varname) = PEEK('OSU', ($(i)-1), Developers_pre); //Developers_pre is the table that I first get when I load the file
  LET varname2 = 'e_admins_only_part' & $(i);
  LET $(varname2) = 'OSUSER() = ' & $(varname);
// I have exclamation_marks around the individual elements here to avoid confusion with upper_quotes (they are replaced lateron)

  LET e_admins_only = '$(e_admins_only)' & ' OR OSUSER() = ' & chr(33) & $(varname) & chr(33);
// The variables are now all deleted (set to NULL)

  SET varname2 = ;
  SET varname = ;
NEXT i;

Can anybody help me here?

Thanks a lot!

Best regards,

DataNibbler

10 Replies
Anonymous
Not applicable

Thanks for the answer, Marcus.

In the end, I'm opting to use SET v = ;

   1. It empties the variable so the value isn't stored (which is the point)

   2. It retains the variable for the next run so it doesn't have to be created again

Neither of these are likely to be noticeable as variable allocation/deallocation is not system-intensive.  It's more about best practices and deciding the best way to build something for future re-use.

As a side note, if I had a large, generic clean-up script that resets many (1000's) of the same variables across multiple scripts, I might opt for LET v = NULL(); instead.  This is so the SET statements don't create needless variables that linger in applications where they are not used.  But this is not a best-practice, either.