Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Modernize Your QlikView Deployment webinar, Nov. 3rd. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Master II
Master II

What is this script?

Hi Folks,

What is this script? When we use this?

Please explain. Thanks in advance.

SUB LoadQVD (Tablename)

   $(Tablename):

   Load * from [$(Path)$(Tablename).qvd] (Qvd);

END SUB

1 Solution

Accepted Solutions
Highlighted

Hope this helps you :

The sub..end sub control statement defines a subroutine which can be called upon from a call statement.

The syntax is:

sub name [ ( paramlist )] statements end sub

Where:

name is the name of the subroutine.
paramlist is a comma separated list of variable names for the formal parameters of the subroutine. These can be used as any variable inside the subroutine.
statements is any group of one or more QlikView script statements.

Arguments are copied into the subroutine and, if the corresponding actual parameters in the call statement is a variable name, copied back out again upon exiting the subroutine.

If a subroutine has more formal parameters than actual parameters passed by a call statement, the extra parameters will be initialized to NULL and can be used as local variables within the subroutine.

Since the sub statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its two clauses (sub and end sub) must not cross a line boundary.

If the sub statement is defined inside another control statement, for example a For … Next loop or an If … Then construction, the subroutine is only available inside the scope of that control statement. In other words: the sub statement cannot be defined inside another control statement if the subroutine call should be made from outside the control statement. This is also true if the subroutine is defined in a script file included using the include system variable within a control statement.

Examples:

// Example 1

sub INCR (I,J)

I = I + 1

exit sub when I < 10

J = J + 1

end sub

call INCR (X,Y)

// Example 2 - parameter transfer

sub ParTrans (A,B,C)

A=A+1

B=B+1

C=C+1

end sub

A=1

X=1

C=1

call ParTrans (A, (X+1)*2)

The result of the above will be that locally, inside the subroutine, A will be initialized to 1, B will be initialized to 4 and C will be initialized to NULL.

When exiting the subroutine, the global variable A will get 2 as value (copied back from subroutine). The second actual parameter “(X+1)*2” will not be copied back since it is not a variable. Finally, the global variable C will not be affected by the subroutine call.

View solution in original post

2 Replies
Highlighted

It is a reusable piece of code (A Sub Routine) that you can call as many times as you need

  1. SUB LoadQVD (Tablename) 
  2.    $(Tablename): 
  3.    Load * from [$(Path)$(Tablename).qvd] (Qvd); 
  4. END SUB 

LoadQVD : this is the name of the subroutine that has a parameter (Tablename)

if you write in your code LoadQVD(MyTable) you will have a table with the name MyTable that loads data from

a qvd file

Highlighted

Hope this helps you :

The sub..end sub control statement defines a subroutine which can be called upon from a call statement.

The syntax is:

sub name [ ( paramlist )] statements end sub

Where:

name is the name of the subroutine.
paramlist is a comma separated list of variable names for the formal parameters of the subroutine. These can be used as any variable inside the subroutine.
statements is any group of one or more QlikView script statements.

Arguments are copied into the subroutine and, if the corresponding actual parameters in the call statement is a variable name, copied back out again upon exiting the subroutine.

If a subroutine has more formal parameters than actual parameters passed by a call statement, the extra parameters will be initialized to NULL and can be used as local variables within the subroutine.

Since the sub statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its two clauses (sub and end sub) must not cross a line boundary.

If the sub statement is defined inside another control statement, for example a For … Next loop or an If … Then construction, the subroutine is only available inside the scope of that control statement. In other words: the sub statement cannot be defined inside another control statement if the subroutine call should be made from outside the control statement. This is also true if the subroutine is defined in a script file included using the include system variable within a control statement.

Examples:

// Example 1

sub INCR (I,J)

I = I + 1

exit sub when I < 10

J = J + 1

end sub

call INCR (X,Y)

// Example 2 - parameter transfer

sub ParTrans (A,B,C)

A=A+1

B=B+1

C=C+1

end sub

A=1

X=1

C=1

call ParTrans (A, (X+1)*2)

The result of the above will be that locally, inside the subroutine, A will be initialized to 1, B will be initialized to 4 and C will be initialized to NULL.

When exiting the subroutine, the global variable A will get 2 as value (copied back from subroutine). The second actual parameter “(X+1)*2” will not be copied back since it is not a variable. Finally, the global variable C will not be affected by the subroutine call.

View solution in original post