Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
nagasekhar
Contributor III
Contributor III

sub function

what is sub function?

what is the applications of sub function?

what is the procedure to implement it?

please provide different examples  to understand this function?

 

Labels (5)
2 Replies
micheledenardi
Specialist II
Specialist II

Sub..end sub 

 

This is for QlikView but is the same also for Sense: QlikView Tutorial | How to create Subroutines or functions in qlikview script | Data & Tools 

Michele De Nardi
If a post helps to resolve your issue, please accept it as a Solution.
eddie_wagt
Partner - Creator III
Partner - Creator III

Sub stands for subroutine. See post of @micheledenardi for some background.

Example:

 

Sub Example // begin statement name of subroutine is Example

Example:
LOAD * INLINE [Example_Key, Example_Dimension, Example_Measure
1, First Example, 1
2, Second Example, 2
];

End Sub // end statement of subroutine

 

If you would run the script like this then nothing will happens, because you didn't make the call for this subroutine.

If you want to run this code, you will have to use the Call function. Like this:

 

Sub Example

LOAD * INLINE [Payment ID,Payment Source,Payment Amount
1,Source 1,500
1,Source 1,400
1,Source 2,900
2,Source 1,100
2,Source 2,50
] (delimiter is ',')
;


End sub

Call Example

 

If you run this script then the table will be loaded.

Now, when to use this? With a subroutine you can make your own order of loads. Like:

Call Example

Call AnotherExample

This could be handy if you have to script and test if the code works or not. You could comment out one of the subroutines.

Another use case is that you have script that is of generic/general use and you have to use this piece of code all the time. So what you don't want to do, is copying this script over and over again.

 

Sub Store(vTablename)

STORE $(vTablename) into $(vTablename).qvd (qvd);

End Sub

 

This example shows a subroutine with a code for storing a table into a QVD file. Now if we want to store a table after loading the table we can call this subroutine and have the loadscript excecuted. Like this:

 

Sub Example

ExampleTable:
LOAD * INLINE [Payment ID,Payment Source,Payment Amount
1,Source 1,500
1,Source 1,400
1,Source 2,900
2,Source 1,100
2,Source 2,50
] (delimiter is ',')
;

Call Store('ExampleTable');

End sub

Call Example

 

There are some great subroutines available in this community for generic use. There is even a library (Qlikview components) here Qlikview Components .

 

Kind regards

Eddie

If this answers your question or solves your issue, be sure to mark the answer as correct by clicking 'Accept as Solution'. This will mark the post as solved and other Qlikkies will gravitate towards this post as it as a possible solution for their issue. Multiple responses can be accepted as a solution so make sure to select all that apply.