Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
datanibbler
Champion
Champion

Cleaning up old variables

Hi,

I know the tool "DocumentAnalyzer". We have it, though probably not the newest version. For fields, there is a built-in function to generate the "DROP FIELD" statements for all unused fields.

=> is there an alike functionality - or is there some other possibility - to generate the necessary LET statements to reset all variables in the app?

(as QlikView keeps all variables when closing, it might well be that at some point a variable was changed and its name also, and so the old, outdated variable is still around which can cause malfunctions to not be immediately detected ...

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
marcus_sommer

Hi DataNibbler,

if a variable has reached the gui it could unfortunately only be there deleted. Another possibility is to remove the variables per macro with a loop like:

sub x

rem ** Show name of all variables in document **

set vars = ActiveDocument.GetVariableDescriptions

for i = 0 to vars.Count - 1

    set v = vars.Item(i)

    msgbox(v.Name)

    'ActiveDocument.RemoveVariable v.Name

next

end sub

See also: Variables and QlikTip #9: Deleting variables via user-interface, within the load-script or by using macros (transl...

- Marcus

View solution in original post

24 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

If (1) the variable does not exist at the start of the script, (2) is created in the script, but (3) set to null before the script terminates, it is not stored in the document, nor is it visible in the front end.

To set the variable to null, use one of:

Set vVar =;

or

Let vVar - null();

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Gysbert_Wassenaar

You can load the variables from the xml table VariableDescription of the qvw file itself and use that table to loop through the variables and clean them up.


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

Here is a script for that:


Let zFileName = DocumentPath();

Set ErrorMode = 0;

VariableDescription:

LOAD

  Name As SOE.Name,

  RawValue As SOE.Definition

FROM [$(zFileName)] (XmlSimple, Table is [DocumentSummary/VariableDescription])

Where Not(IsReserved = 'true' Or IsConfig = 'true');

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
datanibbler
Champion
Champion
Author

Hi Jonathan,

that is exactly my point 😉

Unfortunately, in a lot of apps we have here, all the variables are not set to NULL() in that way - that's why I ask if there is some way to make up a routine to quickly generate all those statements ...

datanibbler
Champion
Champion
Author

Wow!

That looks awesome!

I will try it.

Thanks a lot!

datanibbler
Champion
Champion
Author

Hmm ... now I have a listing of all the variables in a script - but how can I get rid of them?

I have picked some one or two out to try and I tried

>> LET vVar = NULL(); <<

but they are still there - with an empty value all right, but I want them altogether gone.

How could I achieve that?

jonathandienst
Partner - Champion III
Partner - Champion III

I don't use it for that, but maybe this to conditionally delete all variables starting with 'z':

Let zFileName = DocumentPath();

Set ErrorMode = 0;

VariableDescription:

LOAD

  Name As SOE.Name,

  RawValue As SOE.Definition

FROM [$(zFileName)] (XmlSimple, Table is [DocumentSummary/VariableDescription])

Where Not(IsReserved = 'true' Or IsConfig = 'true');

For i = 0 To NoOfRows('VariableDescription')

  Let zName = Peek('SOE.Name', i, 'VariableDescription');

  If zName like 'z*' Then

       Set $(zName) = ;

  End If

Next

Set zFileName = ;

Set i = ;

Set zName = ;

Note that the set of variables is from the previous reload as we load the data before the file has been saved, so a new variable created this run will only be deleted on the next run.

BUT once the script-created variable is deleted then it will resurface the next run as it will no longer be in the list of variables to be deleted - every second run .... so I don't think this will work.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
marcus_sommer

Hi DataNibbler,

if a variable has reached the gui it could unfortunately only be there deleted. Another possibility is to remove the variables per macro with a loop like:

sub x

rem ** Show name of all variables in document **

set vars = ActiveDocument.GetVariableDescriptions

for i = 0 to vars.Count - 1

    set v = vars.Item(i)

    msgbox(v.Name)

    'ActiveDocument.RemoveVariable v.Name

next

end sub

See also: Variables and QlikTip #9: Deleting variables via user-interface, within the load-script or by using macros (transl...

- Marcus

datanibbler
Champion
Champion
Author

Hi Jonathan,

this only has to be done every once in a while, not regularly - I just want to delete all variables in a script for good once - and on the next run, all the variables that are necessary for proper working will be regenerated. That is quite okay - I just want to get rid of the outdated variables that are not supposed to be used anymore.

^However, I have tried both  >> SET $(vVar) = ; << and >> LET vVar = NULL() << - then the value of the variable is empty as can be seen in the >SOE.DEFINITION< listbox, but the name is still there, even after closing down QlikView altogether (all QlikView windows).

How could I get rid of it without any leftovers?