Databases Reference
In-Depth Information
3.
Enter the following script.
SUB TraceRowCount (SourceTable)
// Writes the number of rows in SourceTable
// to the Script Execution Progress window.
IF '$(SourceTable)' <> ''
LET vNoOfRows = NoOfRows('$(SourceTable)');
TRACE >>> Number of rows in $(SourceTable): $(vNoOfRows);
LET vNoOfRows = Null();
ELSE
TRACE >>> No table name specified;
END IF
END SUB
4. Go to the
Aircrafts
tab.
5. Immediately after the first
Aircraft Types
load statement, enter the
following statement:
CALL TraceRowCount('Aircraft Types');
6.
Add the same statement after the
LEFT JOIN ([Aircraft Types])
statement, just above the
DROP FIELD
statement.
Let's have a closer look at what this script does.
The subroutine is declared using the
SUB
control statement:
SUB TraceRowCount (SourceTable)
This tells QlikView that we want to declare a subroutine called
TraceRowCount
,
which takes a single parameter:
SourceTable
. This parameter is passed into the
subroutine as a variable, which only exists within the context of that subroutine.
The script checks if a value was given for the
SourceTable
parameter, if it has a
value the number of rows is written to the
Script Execution Progress
window in the
same way we saw earlier. If there is no value, an error message is returned.
The subroutine is ended using the
End Sub
statement.
You may wonder why we used the
LET vNoOfRows = Null();
statement. By default, variables that are created in script are also
available on the frontend. To prevent this, we delete the variable
by assigning it the value
Null()
. This approach does not work for
variables that already exist, in that case you will first have to delete
them manually from the
Variable Overview
(opened by pressing
Ctrl + Alt + V
in the frontend).