Mindmajix

How Debugging works in QlikView Script Debugger

Debugging

Understanding debugging process is very important for troubleshooting. This post describes how to use the qlikview tools and functions, helping you identify the bugs and flaws in your qlikview scripts using syntax checker, the qlikview script debugger tool, EXIT SCRIPT, TRACE, partial loads, and log files.

QlikView Script Debugger

The qlikview debugger is a tool used to help you identify the problems in the script that may cause errors or issues otherwise. The debugger allows close monitoring of the script and also allows you to view the script actions and variable settings. The debugger window, as shown in the following screenshot, is accessed by clicking on the debug button in the main toolbar in script editor.

The following illustration is a diagram of the qlikview debugger dialog (debugger):

Screenshot_36

The features of the qlikview debugger include:

  • Clear: In the breakpoints section, this button clears all the established breakpoints. You can set a breakpoint (a pause in the script created by clicking a line number). Breakpoints are represented in the debugger main window by a red circle near the code line numbers. You can set as many breakpoints as you want in the code. Not all lines can support a breakpoint, so it may sometimes be helpful to set ‘breakpoint’ to occur.
  • Run: In the debug section, this button starts and runs the script execution. The script will run until it hits an error, breakpoint, the EXIST SCRIPT command, or the end of the script. It starts the script from the beginning or restarts the script after a breakpoint. It also restarts the script running at a normal speed after animate or step.
  • Animate: This button executes the script slowly and allows you to more easily track the progress and outputs of the script and set breakpoints ahead of the code execution. The script will run until stopped as explained in the previous feature.
  • Step: This button executes the script one line at a time, and stops. The user must click on the step again to move one line forward, or click on run or animate to start the script execution again. The comment lines will be ignored.
  • Limited load: This is a useful debugging feature that saves the developers time when running scripts against the large data sets. The maximum number of rows to be loaded per table is selected in the limited load box (after enabling the check box). If the maximum number of rows is set too low, note that it is possible that no data associates across tables.
  • Help: This button displays qlikview help
  • End here: This button ends the debugger run of the script and closes the debugger window. All the data loaded to that point in the last debugging script execution remains loaded in the current qlikview application.
  • Cancel: This button stops the script execution in the debugger, closes the debugger, and discards the data loaded, if any.
  • Close: This button closes the debugger immediately (usually with an execution of script failed error dialog). If you click on yes to reload old data, the previous data set will be loaded, and the application will remain open. If you click on no, then  the application will be closed with no data loading.

Tip

After a successful run of  the script in the debug mode, you will need to close the window, usually by clicking on the x icon in the debug dialog window.

The qlikview debugger has four windows, as follows:

  • The main large window is the script window, which displays the script portions as it executes them. You can set breakpoints by clicking on any code line. Clicking once again on the breakpoint removes it (as done while clicking on the clear button). The current script line that is being executed is annotated with a horizontal yellow bar. The include files execution will appear on separate tabs of the main window.
  • The lower-middle section of the screen is the script execution window, which shows the current script statement that is being executed.
  • The bottom-left section of the screen displays the status codes and script errors, if any.
  • The bottom-right section of the screen displays all the variables and current values. If a variable has changed in value, it is displayed in red.

Using the Exit Script Function

We can exit the entire script by just calling the function :

  Exit Script;

It will terminate at a point where its mentioned least caring about the additional script. It is a good practice to use the Exit Script function, whenever needed in the script, instead of a debugger breakpoint. Breakpoint only works while in the debugging mode and will be lost upon closing the debugging window. When a script execution encounters the Exit Script command, it stops running the script immediately. All the data loaded, so far in the script execution remains as it is.

The Exit Script command is a useful tool to use when incrementally debugging the portions of the script. You can insert Exit Script at some point after a Load statement, such as before the Store statement, then preview the table in table viewer to see if the data accumulated in the same way you intended, if all is well, you can remove the Exit Script command or comment it out (note that the Exit Script command has the same effect as commenting out the remainder of the script as it stops any script execution from that point forward). Typically, Exit Script is placed on a separate tab and promoted and demoted to test various sections of the script.

Using Syntax Checker

Improper use of syntax is the most common cause of errors. The first line of defence in Qlikview debugging is the built-in syntax checker. QlikView script editor performs an interactive syntax check while creating a script. Qlikview automatically color codes the code statements for you (the color and font can be customized by the developer in the script editor dialog). You can also explicitly call the syntax checker by selecting the command, tools/syntax check, from the menu bar in script editor. Paying careful attention to what qlikview is telling you about your code should be of primary importance before running the reload script. The common errors are lack of parentheses (shown in red and bold) in nested statements, missing semicolons and colons, and lack of commans. As the case illustrated in the following screenshot, there is a comma missing after sales. Any code underlined with squiggly red lines is coded in error. In the following case, the error starts at the point of sales because there is no comma at the end of that line (comments in green text are ignored by the syntax checker). The syntax checker is a useful tool, but it is not perfect. It can miss errors, particularly when encountering the dollar sign expansion of variables. This is covered as a part of Qlikview Course.

Screenshot_37

Common QlikView Script Errors

Qlikview error messages displayed during the running of the script, during reload, or just after the script is run are key to understand the errors are contained in your code. After an error is detected and the error dialog appears, review the error, and click on ok or cancel on the script error dialog box. If you have the debugger open, click on close, then click cancel on the sheet properties dialog. Re-enter the script editor and examine your script to fix the error. Errors can come up as a result of syntax, formula or expression errors,  join errors, circular logic, or any number of issues in your script.

The following are few common error messages you will encounter when developing your qlikview script. The first one, illustrated in the following screen shot, is the syntax error, we received when running the code that missed a comma after sales, from the previous section of this book. This is a common syntax error. It’s a little bit cryptic, but the error is present in the code snippet that is displayed. The error dialog does not exactly tell you that it expected a comma in a certain place, but with practice, you will realize the error quickly.

Screenshot_38

The next error is a circular reference error. This error has been discussed previously in the book and will be handled automatically by qlikview. You can choose to accept qlikview’s fix of loosening one of the tables in the circular reference (view the data model in table viewer for more information on which table is loosened, or view the document properties dialog, tables tab to find out which table is marked loosely coupled). Alternatively, you can choose another table to be loosely coupled in the document properties, tables tab, or you can go back into the script and fix the circular reference with one of the methods described in advanced scripting and data model optimization.

The following diagram is a warning/error dialog displayed when you have a circular reference in a script:

Screenshot_39

Another common issue is an unknown statement error that can be caused due to an error in writing your script like to miss commas, colons, semicolons, brackets, quotation marks, or an improperly written formula. In the case illustrated in the following screen shot, the error has encountered due to an unknown statement-namely, the customers line that qlikview is attempting to interpret as customers load*…. the fix for this error is to add a colon after customers in the following way: customers:

Screenshot_40

There are instances when a load script will fail silently. Attempting to store a QVD or CSV in a file that is locked by another user viewing it, is one such error. Another example is when you have two fields with the same name in your statement. The debugger can help you find the script lines in which the silent error is present.

Debugging using Log Files

The log file is a very useful debugging tool  when your document is deployed to a server. Script logging for the current qlikview application can be activated by opening the document properties dialog, general tab. If the generate log file, check box is selected (as in the following screenshot), qlikview will create a log file of the script execution (the output will be as seen in the script execution progress dialog when you run the script). This file, with the default name qv.log , is stored in the same folder in which the current qlikview application is. If you activate the time stamp in log file name checkbox, the file name is saved to the current script run time stamp in the log file name.

The log file is usually the first place to look for errors if a load fails or displays errors and is a key tool in your debugging. Find the errors in the log file, and work through your script again to spot the errors using the debugger and exit script functions to help you isolate the errors.

Screenshot_41

You can place a custom text that is displayed in the script execution dialog and appears in the log file using the TRACE command. Place your custom text (which can also be a variable) to flag the area of the script that you want to examine upon script runtime and also in the log file.

The format is:

TRACE   “string”;

Here’s a screen shot of the debugger window with a custom trace message. Note that we could have used a custom message from a variable we set, instead of this string text.

Screenshot_42

Using find/replace in Debugging

Though not a debugging tool, the find/replace across tabs is a useful tool to mention. In the script editor window, using the find feature by navigating to edit/find/replace in the command menu or pressing ctrl+f on the keyboard allows you to search (and/or replace text) across all the script tabs by selecting the search all tabs check box.

Screenshot_43

Removing or partially Loading Data

There is certainly value in removing the data that have already been loaded into the qlikview application. You can do this in a number of ways, including opening the debugger window and immediately closing it and then choosing to select old data. You can also open the qlikview application with the recent documents (on the qlikview start page) list and right-click and choose to load without any data. Lastly, you can open a loaded document and choose file/reduce data/remove all values.

Alternatively, you could choose a partial load of one or more tables (either adding a new table with data or replacing an existing table with data). The syntax for the partial load is to cast either add or replace just before the load statement, then use the file/partial load menu command or the ctrl+shift+r keyboard command to reload only those tables marked with add load or replace, instructing qlikview that the statement should be ignored during normal (non partial) reloads, but during a partial reload it will run and ignore other load statement. Some examples:

Table:1

LOAD product, ID FROM product.csv;

ADD LOAD product, ID FROM

New product.csv;

During a normal reload, data is loaded from  the product . Csv and stored in the qlikview table, table1. Data from new product.csv is then concatenated to table1.

During a partial reload, data is loaded from new products . Csv and added to the qlikview table, table1. No check for duplicates is made because ‘where not exists statement’ is not included.

 Table:2

SELECT product, ID FROM product. Csv;

ADD LOAD product, ID FROM new product.csv

Where not exist (product);

A check for duplicates is made by means of seeing if the product exists in the previously loaded table data (using the where not exists clause).

During a normal reload, data is loaded from the product. Csv and stored in the qlikview table, table2. Data from new product.csv is then concatenated to table2.

During a partial reload, data is loaded from new product.csv, which is appended to the qlikview table, table2.

Table:3

LOAD product, ID FROM product. Csv;

ADD ONLY LOAD product, ID FROM

New product.csv where not exists (product);               

A check for duplicates is made by means of seeing if the product exists in the previously loaded table data (using the where not exists clause).

During a normal reload, data is loaded from product.csv and stored in the qlikview table, table3. The statement (add only) loading new product.csv is disregarded.

During a partial reload, data is loaded from new product.csv, which is appended to the qlikview table, table3.

Enroll for Live Instructor Led Online QlikView Training


0 Responses on How Debugging works in QlikView Script Debugger"

Leave a Message

Your email address will not be published. Required fields are marked *

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.
Course Adviser

Fill your details, course adviser will reach you.