Comments

It is very important that while coding the script, you write the comments along with it. Normally, this is little time consuming, because a coder has to write some extra keywords which describe the code and the logic.

If possible, the comments should be written in simple English, so that it can be easily read and understood by other people. These comments will help you in documenting the entire code and the logic after finishing the scripting.

Comments can be used mainly for two reasons. They are listed as follows:

  • To describe the logic written in the code
  • To disable a code without deleting it, while doing the R&D

In Qlik Sense, there are three ways in which you can write comments in the code:

  • Single line comment: To comment a single line of the code, the double slash //is used. Any code which has the preceding double slash will be considered as comment by Qlik Sense. It is used to comment a single line. In case you want to comment multi lines using this method, every line should be preceded by the double slash. For example:

// This is a single line comment.

Mostly, it is used to comment the fields used in the load script, so that you dont need to remove it from the script. This helps in adding those fields as and when required, just by un-commenting it.

  • Multi line comment: Multi line comments should start with a single slash and star, that is /*, and end with a star and single slash, that is */. Any code between these symbols will be considered as comment.

              This type of commenting is used when a large chunk of code needs to be commented.

              For example:

              /* This is a multiline comment */

  • Comment using keyword: In addition to the previously listed ways, Qlik also has one more way of commenting the code, namely, using the keyword REM. Any sentence preceded by the REM keyword will be considered as comment, but it should be ended using the semi-colon. 

For example:

REM This is another type of comment;
One thing to note is that whichever way you use for commenting, the color of the text becomes gray.

Tracing: Debugging the script is one of the important parts of scripting. While writing complex business logic in Qlik Sense script, at times it becomes difficult to find the issue in the script. In such cases, we can debug the script using the debugger, or through the Trace statement.

Trace statement is used to write strings to script the execution process window which pops up when you reload the script. So it helps by indicating which part of the script is being reloaded.

Trace command is very helpful to debug the code when it contains loops or when you want to find how many records were updated when you used the join statements in the script. So by using the trace command, you can easily write to the script execution window and check the status of your code. This statement not only writes on the execution window but it also write backs to the script execution logs. This makes it more useful to find any issue in the script.

Trace statement can be used to write static text and to print the variable values using the $ sign expansion.

              Following is an example of a trace statement:

Trace "Script loading started";   
Trace "The Max Value is 1000" ;

Following is the screenshot of the script execution window:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset