I just read a good post by Kamal Kumar Sanguri on QlikCommunity. Kamal’s post reminded me that managing variables in QlikView has always presented some challenges and over the years various techniques and code snippets have been shared to address those challenges.
Most folks quickly find that maintaining variables in external files loaded with a script loop is a good approach and resolves common concerns regarding shareability, dollar sign escaping and so on.
Sometimes you encounter a need for an adhoc import or export of variables. Kamal’s post offers some useful code snippets for that. Several years ago my colleague Barry Harmsen wrote a post on QlikFix.com that shows some useful macros to manipulate Variables. Barry and I subsequently collaborated on a desktop utility that handles both import and export from a menu. While the download link on the blog is dead, I’ve reposted the utility on the QlikViewCookbook Tools section for download.
Kamal said that there is no way to directly load variables from one QlikView document to another. That got me to thinking. It is possible, but gee, no one has ever asked for it.
What’s the use case? When I want to do an adhoc copy, I use the desktop utility referenced above. I have seen a number of customers who generate complex calendars into QVDs followed by generation of variable for use with the calendar. Calendar QVD consumers incorporate the variable generation logic with an include file. It works.
Would it be any better if calendar consumers loaded the variables directly from the calendar generating QVW? I think not because there is possibility of a mismatch between the QVW source and the Calendar QVD.
All that said, maybe you have a use case for loading variables from a QVW? No one asked, but for the record here is the script to load variables directly from another QVW.
VariableDescription: LOAD Name, RawValue FROM [..\..\data\StudentFile.qvw] (XmlSimple, Table is [DocumentSummary/VariableDescription]) Where IsConfig = 'false' and IsReserved = 'false' // Exclude system vars // Any addtional filtering here ; FOR idx=0 to NoOfRows('VariableDescription')-1 LET vVarname = Peek('Name',$(idx),'VariableDescription'); LET [$(vVarname)] = Peek('RawValue',$(idx),'VariableDescription'); NEXT idx SET idx=; SET vVarname=; DROP Table VariableDescription;