Category

Sunday, April 20, 2014

Qlikview Script from QVD Files

QlikView stores some metadata with qvd files in the qvd header section. This information is in the form of XML and includes name of thw qvw that generated qvd, field headers, length, format etc.
Along with this information, you will also find code that is used to create the qvd file like Load, SQL select statements and store statements along with database connection string.
There are 3 ways to get the script code from the qvd files.

Text editor: 
If the QVD file is moderately small size, you can simply open the  QVD file with Text editor like NotePad++ and look out the contents of the QVD file.  The file starts with xml version info followed  <QvdTableHeader> which marks beginning of the header section.
At the end of the header section, SQL statements, Load, Store statements and data base connect statements are enclosed between <Statment> </Statement> tags and <LineageInfo> </LineageInfo> tags.
Please be careful before opening any huge QVD file with text editor as it may freeze the system. The other options mentioned below are ideal to huge QVD files.

QlikView Desktop:
Click on Table Files in script window and select the QVD file. Once dialog window opens with QVD preview, select Xml radio button. Under the tables section, select  QvdTableHeader/Lineage/LineageInfo to view the code.
QVD import window

EasyQlik QViewer:
As mentioned in one of my earlier post, EasyQlik QViewer is an useful tool to view QVD contents.
Open the QVD file with EasyQlik QViewer tool and navigate to View -> File Metadata. It pops up a File Metadata window and displays the code.


Feel free to comment, if you are aware of any other method to get the code from QVD files.

Import and export Qlikview documents into XML files

Qlikview provides option to export Qlikview documents into set of XML files. Once, you have created an XML files, it can be used to recreate the Qlikview application. 
Lets look at how to export the document into XML files.

Under Menu select File -> Export ->Export document and layout.

QV Document Export

Select the folder and click on OK. I suggest you create a new folder.

Browse Folders

Now open the folder and you will notice few XML files created.  These XML files contain metadata about the Qlikview document. This information can be used to recreate the Qlikview document.
Export option does not export the data from Qlikview document.

XML files

Now, lets look at how to recreate the Qlikview document from the XML files.
  1. Copy the folder and paste in to another folder.
  2. Rename the copied folder to have suffix "-prj". e.g: If the folder name is "Export example" , rename it to "Export example-prj".
  3. Create an new empty Qlikview document (no code, no objects) and save it in the same path as the folder copied in the above step with the same name as folder name without "-prj". e.g: "Export example.qvw"
  4. Close the empty Qlikview document created in step 3.
  5. Navigate to the folder where the Qlikview document is saved and open the Qlikview document.


Project folder


Surprise! the empty document we saved few minutes back has got the nice layout and script code. The layout and code is exactly same as the document exported. But, without the data.  You can now reload the document and save the document with data.

Thursday, April 3, 2014

Partial Reload for Fast and Selective Reloads

How many times you have loaded huge application for hours and realized you either missed a table or need to reload data in a table. But, refreshing the application takes long time. This is where Partial Reload comes into play.
Partial Reload allows Qlikview applications to add or replace selective tables into the data model while retaining already existing tables unaffected. Due to selective tables load, full reload is eliminated and reload becomes faster.

Partial Reload option is available File menu option or invoked using Ctrl+Shift+R shortcut key.

This command executes only those load and select statements that are preceded by a replace or add prefix. Other data tables remain unaffected by the command. 
Note that, It also executes any other statement (excluding normal load and select) in the script such as drop, join, keep etc.

Let's look at the usage of 2  prefixes:
add load, replace load examples
ADD  - This prefix is used to add ( or create) a new table to the existing data model.

REPLACE - This prefix is used to replace an existing table in the data model. New table name should be identical to the existing table name. If the table does not exist already, new table is created and added to the data model.

ADD/REPLACE load statements are treated just like any other load statements during regular reloads. By using ONLY keyword we can restrict ADD/REPLACE load statements execution to partial reloads only. During normal reloads these ADD ONLY / REPLACE ONLY load statements are ignored.

ONLY example

During Partial Reload, to avoid executing any other statements apart from ADD/REPLACE loads,  we can use IsPartialReload() function. This function returns -1 (True) during partial reload and 0 (False) during normal reload.
During development or testing, if a table needs to added or reloaded without affecting other tables in the data model, use the code snippet in the first tab of the script.
IsPartialReload() example

We can also use  IsPartialReload() to execute any Qlikview script statements such as drop tables, drop field to manipulate the data model  or store tables in the qvw into QVDs etc.
IsPartialreload() example -2

Partial reloads are extremely useful during coding and testing phase of Qlikview dashboard. It saves lot of reload time, makes debugging and testing faster.