Sie sind auf Seite 1von 25

Getting Started with QlikView Part XV Variables, Functions & Debugging script

Description: BISP is committed to provide BEST learning material to the beginners and advance learners. In the same series, we have prepared a complete end-to end Hands-on Beginners G ide !or "li#view $ata %odeling and &eporting. The doc ment !oc ses on 'ariable, ( nctions and $eb gging Script. )oin o r pro!essional training program and learn !rom e*perts.

Histor+, 'ersion /.0 /.0 $escription -hange Initial $ra!t &eview20 . thor S rbhi sah .mit Sharma P blish $ate 10st . g 1/01 13th . g 1/01

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 0

Table of Contents
Table o! -ontents......................................................................................................................... 1 Storing Tables,.............................................................................................................................. 4 &enaming tables and !ields.......................................................................................................... 5 Setting variables........................................................................................................................... 6 -ontrolling script !low................................................................................................................... 6 7sing I( statement ................................................................................................................... 6 -onditional ! nctions.................................................................................................................... 8 String ! nctions......................................................................................................................... 8 9 mbers and n meric ! nctions................................................................................................. 04 $ate and time ! nctions............................................................................................................. 06 Saving logs to dis#...................................................................................................................... 0: S+nta* chec#.............................................................................................................................. 03 The script deb gger................................................................................................................... 1/ .dding comments....................................................................................................................... 11 Incl ding script !iles.................................................................................................................... 11 %anaging !ile locations and connection strings..........................................................................15

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 1

Storing Tables:
9ow that we have b ilt o r .ircra!t T+pe dimension table, we can se it in o r "li#'iew doc ment. In an environment with m ltiple doc ments, it is ver+ li#el+ we will want to re- se the same table in di!!erent apps. (ort natel+, there is an eas+ wa+ to e*port a "li#'iew table to an e*ternal "'$ !ile sing the ST;&E statement.

<ith =ST;&E #e+word, give the table name and the location where +o wants to store that !ile.

<e can save the !ile in te*t !ormat b+ sing the e*tension =.t*t as shown below.

.!ter re-loading the data > go to the location where +o have saved the !iles to chec# i! the+ are created or not.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 4

Renaming tables and fields


&enaming tables or !ields in "li#'iew is done sing the &E9.%E statement. The !ollowing code shows some e*amples o! this statement,

&E9.%E T.B?ES 7SI9G %ap@Table@9amesA &E9.%E (IE?$S 7SI9G %ap@(ield@9amesA Bo can see here the name o! table is been changed a!ter reloading the statement.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 5

Setting variables
. variable is a s+mbolic name that can be sed to store a val e or e*pression. Besides the !rontend, variables can also be sed within "li#'iew scripts. (or e*ample, we ma+ want to se a variable called v$ateToda+, which we will set to the present da+Cs date in o r script, ?ET v$ateToda+ D Toda+EFA The Toda+ ! nction is a b ilt-in ! nction that ret rns the present da+Cs date. ;nce the variable has been set, we can se its val e ever+where in o r statements. "li#'iew has two statements that can be sed to assign a val e to a variable, SET and ?ET. The di!!erence between these two is that the SET statement assigns the literal string to the variable, while the ?ET statement !irst eval ates the string be!ore assigning it. This is best ill strated with an e*ample, Statement D> 'al e o! v'ariable SET v'ariable D 0 G 1A D>0G1 ?ET v'ariable D 0 G 1A D> 4

Controlling script flow


"li#'iew script is e*ec ted !rom le!t to right and !rom top to bottom. Sometimes, however we ma+ want to s#ip certain parts o! the script or e*ec te a piece o! script a !ew times in s ccession. . control statement is a conditional statement whose res lts determines which path will be !ollowed.

%a#e the variable whose val e is eH als to 9 here we have se the SET statement !or assigning the val e 9 to the variable. 9ow its time to implement the variable.

Using IF statement
I! is a control statement which create while we want to implement some conditions within o r code.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 6

Here we have give the val e eH als to B which is not acceptable !or the variable which we have created beca se it alread+ reserved b+ the string 9 so that will not proceed be!ore that we have to se the i! statement as we have loaded be!ore the loading o! table (light $ata Table, the condition becomes !alse so the table will not be loaded.

> &eload the table > go to the table viewer, loo# here the table (light $ata Table is not loaded beca se the condition not satis!ied. Ieep one thing in mind, that to se the command E D!F !or ending o! the I( statement. www.bispsol tions.com www.bisptrainigs.com www.h+periong r .com Page :

I! we change string which given !or comparing in the control statement b+ giving C9C This will load the table

Conditional functions
These ! nctions are se to modi!+ data based on a condition.

String functions
String ! nctions are those ! nctions which process with strings or ta#e the inp t as a string. These are the ! nctions available in "li#'iew "# len$string# This ! nction ret rns the length o! a string. Goto the 9ewSheet;bJect->Te*t;bJect->write the e*pression in the te*t->.ppl+ then +o can see the res lt here

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 8

%# le&t$string,nu'ber o& characters# This ! nction Starting !rom the le!t o! the string, ret rns the speci!ied amo nt o! characters.

(# right$string,nu'ber o& characters# This ! nction Starting !rom the right o! the string, ret rns the speci!ied amo nt o! characters. www.bispsol tions.com www.bisptrainigs.com www.h+periong r .com Page K

)# 'id$string,starting character,nu'ber o& characters$optional## This ! nction ret rns a s bstring !rom the string, starting at the speci!ied character. ;ptionall+, the length o! the s bstring can be speci!ied. I! no length is speci!ied, the right-most part o! the string Estarting at the speci!ied positionF is ret rned.

*# inde+$string, substring,occurrence$optional## This ! nction ret rns the position at which the s bstring is !o nd in the string. I! an occ rrence is speci!ied, "li#'iew will loo# !or that speci!ic occ rrence, otherwise the !irst occ rrence is ass med. I! a negative n mber is s pplied !or occ rrence, "li#'iew starts searching !rom the end o! the string. I! no match is !o nd, the ! nction ret rns /.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 3

loo# here in the string "li#'iew the CiC comes two times i! we give 1 in the option this will give the position o! second i.

,# upper$string# This ! nction converts the string to pper case.

-# lower$string# This ! nction -onverts the string to lower case.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 0/

.# /apitali0e$string# This ! nction -apitaliLes each starting word in the string.

1# replace$string,search string,replace string# This ! nction &eplaces the search string in the string with the replace string.

"2# keepchar$string,characters to keep# This ! nction ret rns the string witho t the characters that are not speci!ied in the #eep list. www.bispsol tions.com www.bisptrainigs.com www.h+periong r .com Page 00

""# purgechar$string,characters to purge# This ! nction ret rns the string min s the characters speci!ied in the p rge list.

"%# te+tbetween$string, startte+t,end te+t,occurrence$optional## This ! nction ret rns the s bstring!o nd between the start and end te*t. I! an occ rrence is speci!ied "li#'iew will loo# !or that speci!ic occ rrence, otherwise the !irst occ rrence will be ass med.

I! we #eep 1 separated with commaE,F this will displa+ the second !ield.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 01

"(# tri'$string# This ! nction ret rns the string witho t an+ leading and trailing spaces. Its similar t+pe o! ! nctions are ltrimEstringF and rtrimEstringF

Numbers and numeric functions


9 mbers and n meric ! nctions are those ! nctions which process with strings or ta#e the inp t as a string. Basic operation we can per!orm li#e G,-,M,N b t some other n meric ! nctions available in "li#'iew.............. "# /eil$# This ! nction will ro nd p to nearest val e. ;ptionall+, a parameter can be speci!ied to indicate which m ltiple to ro nd p to.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 04

%# Floor$# This ! nction will ro nd down to the nearest val e. ;ptionall+, a parameter can be speci!ied to indicate which m ltiple to ro nd p to.

<ill see another e*ample

(# 3ound$# This ! nction ro nds the n mber. ;ptionall+, a parameter can be speci!ied to indicate which m ltiple to ro nd to.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 05

Here we will pass one more parameter.

Date and time functions


$ate and time ! nction give the in!ormation abo t the dates and times. <e can per!orm these tas#s b+ sing the ! nction. "# 4oda5$# This ! nction ret rns toda+Cs date, witho t a timestamp.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 06

%# 6onth$# This ! nction ret rns the month part o! the date.

(#7eek$# This ! nction &et rns the wee# n mber o! the date.

Saving logs to disk


<hen a reload is per!ormed in "li#'iew, a log o! all activit+ is shown in the Script E*ec tion Progress window. . cop+ o! this log can also be saved to dis# so +o can review it at a later time. This can be se! l when the application is not in active condition +o can access all in!ormation b+ generating these log !iles. These are the steps to !ollow in generating log !iles, these !iles gives the in!ormation abo t each log. Step 0, 9avigate to %en bar ->$oc ment properties

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 0:

Step 1, 9ow the window will open ->Go to the General tab Here two options are available 0st one is to generate log !iles and another is Timestamp in ?og!ile name, this will generate the log details a!ter each and ever+ reload. Step 4, (irstl+ chec# the !irst one option that is to generate log !ile->.ppl+->o#

Step 5, Then > &eload the data, this will generate the log !ile. www.bispsol tions.com www.bisptrainigs.com www.h+periong r .com Page 08

Step 5: Open the doc, this will give all the information of the reload.

Step 6: Now check the another option which is Timestamp in Logfile Name then - appl!- ok

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 0K

Step": #eload the data

This will generate the log !ile each and ever+ time reload is done, with the time stamp in the log !ile name in the relative path.

S nta! c"eck
Improper se o! s+nta* is a common ca se o! errors. (ort natel+, "li#'iew has a !eat re that will catch these errors as the+ happen, S+nta* -hec#. "li#'iew script has s+nta* highlighting. <henever incorrect s+nta* is detected, the statement is nderlined in a red sH iggl+ !rom that point onward. In practice, this means that o!ten the error was made in the line that appears be!ore the red nderlined te*t. The !ollowing screenshot shows a piece o! script with a s+nta* error, see i! +o can see what the error is.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 03

?oo# here d e to missing o! a semicolonEAF the whole code is highlighted.

T"e script debugger


The deb gging is the process o! !i*ing b gs. This option is available in men bar o! the script editor.

%ostl+ we will directl+ reload the data and not pre!er deb gging the data, these are the options available in the deb gger window. > clic# on the $eb g option.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 1/

0. 7sing the & n b tton, which will r n the script in the reg lar manner to the end, or brea#point is reached.

ntil a

1. <hen clic#ing on the .nimate b tton, the script is r n in the reg lar manner, b t a small pa se is added a!ter each step. This wa+ the script e*ec tion can be monitored more easil+. 4. <hen the Step b tton is clic#ed, the script e*ec tes a single statement with the help o! the +ellow strip shown in !ig re. 5. ?imited load > <ith their long load times, deb gging scripts that load a lot o! data can be rather c mbersome. This is where the ?imited ?oad option proves se! l. <hen this option is chec#ed, "li#'iew will, !or each statement, onl+ load the n mber o! rows that are speci!ied in the inp t bo*. 6.In this portion the whole script shown which is available in the script editor. :.In this portion onl+ the selected script is written which is c rrentl+ pointed.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 10

8.In this portion the val e o! variable is shown recentl+ we have no variable available so the portion is empt+. K. In this partition the path o! the partic lar !ile e*ist which is going to e*ec te. 3. 7sing brea#pointsD Brea#points are sed to pa se e*ec tion o! the script at a partic lar point so that the intermediate state o! the environment can be inspected witho t having to Step thro gh the entire script.This can be applied b+ J st clic#ing on the partic lar point. . brea#point is represented b+ a red dot, which is added b+ clic#ing on the row n mber. single brea#point is removed b+ clic#ing on it.

#dding comments
.ddition o! comment gives the important in!ormation which can be se! l !or remember o! an+ point or an+ in!ormation. NN!or single line comment

NM!or m ltiline commentMN

Including script files


<e can se s bro tines to re- se pieces o! script within a "li#'iew doc ment. It is also possible to re- se script between doc ments b+ incl ding e*ternal script !iles. &e- sing script between doc ments is a worthwhile goal as it eases development and simpli!ies maintenance.

These are the steps which follows: Step$: - go to notepad keep the varia%le v&olderSo'rce(ata)s val'e e*'ivalent to the path from where the *vd files are fetched in the application.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 11

Step 1, ->save it in an+where->save the !ile name with .Hvs e*tension

Step 4, Goto the script editor->insert->Incl de statement

Step 5, Then give the location o! the notepadCs doc ment which is con!ig.Hvs

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 14

Here the insertion o! script is done.

$anaging file locations and connection strings


I! an+ reason, the !older has to be moved somewhere else, we will have to man all+ change the so rce data path in man+ locations in man+ !iles.to overcome this length+ process we !ollow this proced re which replace the whole path with the help o! variable .

this is the location o! the so rce !ile. 9ow we are going to replace this location with the newl+ created variable v(olderSo rce$ata

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 15

Goto->Edit->(indN&eplace

Here we will replace the path with the newl+ created variable this is the variable thatswh+ we have se the O s+mbol. ->&eplace .ll Then the path get replaced with the variable.

and the data is still loaded in the charts no change occ r as +o can see.

www.bispsol tions.com

www.bisptrainigs.com

www.h+periong r .com

Page 16

Das könnte Ihnen auch gefallen