Debugging script - Qlik View

As with every form of scripting, writing QlikView scripts carries with it the risk of introducing bugs and errors. In this section, we will look at some of the available options to find and solve bugs in your script.

Syntax check

Improper use of syntax is a common cause of errors. Fortunately, QlikView has a feature that will catch these errors as they happen: Syntax Check.

As we saw earlier, QlikView script has syntax highlighting. Whenever incorrect syntax is detected, the statement is underlined in a red squiggly from that point onward. In practice, this means that often the error was made in the line that appears before the red underlined text. The following screenshot shows a piece of script with a syntax error, see if you can see what the error is.

Debugging script

If you looked closely at the script in the previous picture, you will have noticed that there was a comma missing after the TableName column. This causes the statement to be underlined in red from that point onward.

Besides catching errors on-the-fly, we can also run a syntax check over the entire document by selecting Tools | Syntax Check from the menu, or by clicking the icon showing an arrow underlined in red, the right-most icon on the toolbar.

Saving logs to disk

When a reload is performed in QlikView, a log of all activity is shown in the Script Execution Progress window. A copy of this log can also be saved to disk so you can review it at a later time. If you haven't already set this up for the current example document, please follow these steps to generate log files:

  1. Go to Settings | Document Properties to open the Document Properties.
  2. On the General tab, check the Generate Logfilecheckbox.
  3. To create individual log files for each time the script is executed, check the Timestamp in Logfile Name checkbox.
  4. Click on OK to close the Document Properties dialog.

Now, each time the script is run, an additional log file is created in the same folder as your QlikView document. The log file has the name of your document, with the date, time, and .log extension post fixed to it. For example Airline Operations. qvw. 2012_07_07_10_24_43. log.

The script debugger

The Debugger offers some handy features to troubleshoot issues in your QlikView script. We can open the Debugger window, shown in the following screenshot, by clicking on the icon labeled debug on the toolbar, or by selecting File | Debug from the menu.

The script debugger

Besides buttons that trigger the various actions, the debugger dialog contains, from top to bottom, the following areas:

  • The script from all tabs concatenated into a single script.
  • The statement that is currently being executed.
  • On the left, the script execution log file. This shows the same information as the Script Execution Progress dialog window during normal reload.
  • On the right, the current values of the document's variables.

We can run the script in the following different ways:

  • Using the Run button, which will run the script in the regular manner to the end, or until a breakpoint is reached.
  • When clicking on the Animate button, the script is run in the regular manner, but a small pause is added after each step. This way the script execution can be monitored more easily.
  • When the Step button is clicked, the script executes a single statement.

The statement that is currently being executed is marked with a yellow bar, in the preceding screenshot this can be seen on line 73.
The following functions within the debugger are noteworthy.

Using breakpoints

Breakpoints are used to pause execution of the script at a particular point so that the intermediate state of the environment can be inspected without having to Step through the entire script.

A breakpoint is represented by a red dot, which is added by clicking on the row number. The preceding screenshot shows a breakpoint on line 82. A single breakpoint is removed by clicking on it. We can remove all breakpoints by clicking on the Clear button.

Limited load

With their long load times, debugging scripts that load a lot of data can be rather cumbersome. This is where the Limited Load option proves useful. When this option is checked, QlikView will, for each statement, only load the number of rows that are specified in the input box.

As a limited load does not load all data, it is important to note that lookups, mappings, and joins may not function correctly.

Tracing script

Another option that can be used to debug your scripts is the Trace statement. This statement is called from the script and can be used to write all sorts of (debug) information to the Script Execution Progress window.

For example, we can check if the amount of rows in the Aircraft Types changes after we add the left join command to the data from the Aircraft_Group.csv file to it. This is done by putting the following code before and after the statement.

LET vNoOfRows = NoOfRows('Aircraft Types'); TRACE >>> Number of rows in Aircraft Types: $(vNoOfRows);

The first line of this script uses the No Of Rows() function to assign the value of the number of rows in the Aircraft Types table to the vNoOfRows variable. The second line uses the trace statement to write this value to the Script Execution Progress window.

The result is shown in the following screenshot; we can see that there are 369 rows before and after the left join statement, in the table.

Debugging-script-Figure

Now that we have seen the various options for debugging our QlikView scripts, it is time to think about how to keep things tidy and understandable.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Qlik View Topics