Databases Reference
In-Depth Information
Controlling script flow
As we have seen before, QlikView script is executed from left to right and from top
to bottom. Sometimes, however, we may want to skip certain parts of the script or
execute a piece of script a few times in succession. This is where control statements
prove useful.
A control statement is a conditional statement whose results determines which path
will be followed. Let's open the script editor and follow these steps to conditionally
load
Main Data
based on a variable:
1.
Select the
Main
tab.
2.
At the bottom of the script, add the following expression:
SET vLoadMainData= 'N';
3.
Select the
Main Data
tab.
4.
Before the
Main Data LOAD
statement, create a new line that contains the
following statement:
IF '$(vLoadMainData)' = 'Y' THEN
5.
At the bottom of the script, add the following statement:
END IF
Now when we reload the script, we will notice that the
Main Data
table will not be
loaded. Only when we change the value of the variable
vLoadMainData
to
Y
and
reload the script will the
Main Data
table be included. Also notice that we are using
Dollar Sign Expansion in the same way we've used it in the frontend earlier.
Before continuing make sure that the value of
vLoadMainData
is set to
Y
in the script.
The control statement that we used in our example is
IF .. THEN .. END IF
. This
checks
If
a certain condition is met; if it is, a piece of script is executed. As QlikView
needs to know how much of the script should be executed, the statement is ended
with
END IF
.