Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
vireshkolagimat
Creator III
Creator III

sub function script

Hi All,

Could anyone please explain the below code.

Sub StoreAndDrop(vTableName,vQvdFile)

let vNoFields = NoOfFields('$(vTableName)');

if Len('$(vNoFields)') > 0 Then

Store [$(vTableName)] into [$(vQvdFile)];

Drop Table [$(vTableName)];

Else

Trace ** Cannot Store - $(vTableName) does not exist.;

End if

End Sub

As per my understanding, a sub procedure is created to  store the table into a qvd file.

Regards,

Viresh

1 Solution

Accepted Solutions
felipedl
Partner - Specialist III
Partner - Specialist III

Hi Viresh,

The code is as you stated, storing the provided vTableName into the QVD only if there's fields to it with the statement

let vNoFields = NoOfFields('$(vTableName)');



This will check how many fields ("headers" with no data count as well) the table has.

As an example, the following


x:

load * Inline

[

A,B

];

let a = NoOfFields('x');

Lets 'a' with the value 2, even though there's no data in the table and so if i called the sub it would store the table.

Felipe.

View solution in original post

3 Replies
felipedl
Partner - Specialist III
Partner - Specialist III

Hi Viresh,

The code is as you stated, storing the provided vTableName into the QVD only if there's fields to it with the statement

let vNoFields = NoOfFields('$(vTableName)');



This will check how many fields ("headers" with no data count as well) the table has.

As an example, the following


x:

load * Inline

[

A,B

];

let a = NoOfFields('x');

Lets 'a' with the value 2, even though there's no data in the table and so if i called the sub it would store the table.

Felipe.

marcus_sommer

Yes, your understanding is right and this routine stored a table as qvd and dropped it afterwards. The meaning of it is to keep the real load-script small and clean and reducing the normally two-lines of store & drop to a single-line for the call - if we exclude the additionally if-condition which is here implemented and which would significantly increase the needed lines.

And this if-condition displayed very well what could be further done with such a sub-routine. For example the dropping could be optional, the fileformat could be changable - qvd/txt/qvx, ERRORMODE could be implemented and various other things and checks are thinkable - and this only once developed and maintained especially if you put it into an include-variable: The $(Include) which you $(Must_Include) into your toolkit.

- Marcus

vireshkolagimat
Creator III
Creator III
Author

Thanks for the clarification.