Switch... Case... Default... End Switch

This control statement executes the Case that matches the expression. Switch is generally used when we want to avoid the use of nested IF statements. 

The syntax is as follows:

Switch expression {case valuelist [ statements ]} [default statements] end switch

The following example checks the environment in which the application is hosted by including a file which contains the variable with the environment. After this, we load a file from a folder connection created in the server. The load will point to the file in the current environment:

/*
The following code includes a file containing a variable definition with string Live, UAT or Development.
Folder connections with name ConnectionLive, ConnectionUAT and ConnectionDevelopment must be setup
in the server. Each server will have the file Environment.txt.
*/

$(must_include=lib://Environment/Environment.txt);

Switch vEnvironment
CASE 'Live';
SET vFolderConnection = 'ConnectionLive';
CASE 'UAT';
SET vFolderConnection = 'ConnectionUAT';
CASE 'Development';
SET vFolderConnection = 'ConnectionDevelopment';
End Switch;
LOAD * From
[lib://$(vFolderConnection)/Customers.txt]
(txt, codepage is 28591, embedded labels, delimiter is ' ', msq);

In the former example, I used three connections. This is useful when working with single node environments in which we access Development, UAT and Live data sources from the same node. If, however, each server node has access to its own environment, it is recommended to name the folder connection with the same name. Qlik Sense will automatically pick up the file using the same folder connection but will be pointing to the source where the application is currently running.

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

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