This article will cover the syntax of the ‘sub’ control script statement

This statement defines the start of a subroutine. A subroutine is a script part that will only be executed when called by a ‘call’ statement. 

Statement syntax

Sub name [ ( paramlist )] statements 
End sub


NameName of the subroutine.
ParamlistThis is a list of variables to be used in the subroutine. The list must be comma separated and values will be passed when calling the sub using the ‘call’ statement.
StatementsThe statements executed by the subroutine.

Example

This example will create a subroutine for loading an Excel file defined by a variable.

Sub Load (fileName)
	LOAD
    	*
    FROM [lib://Public:DataFiles/$(fileName)] (qvd);
End Sub
Call Load ('ITEM_DETAILS.qvd')

Result

After the subroutine is called, the file ITEM_DETAILS is loaded as a single table.