Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
vipin_mishra479
Creator II
Creator II

How i use this in my script

// ******************************************************************

// EmptyQvd is a generic procedure which deletes all records within a

// given QVD file.

// This is especially usefull if you do not need the records within

// this file anymore but do not want to rely on macros/batch-commands

// to delete the file.

// The fields will remain within the QVD file so you will not have any

// problems doing a wildcard load like "LOAD * FROM 'QVD_*.qvd'" ...

//

// ~~

// Usage:

// Call EmptyQvd('Sales_2009_02.qvd') // using a relative path

// or

// Call EmptyQvd('C:\QlikView\Sales_2009_02.qvd') // using an absolute path

//

// ~

// Author: Stefan Walther

// Date: 01/31/2011

// Version 1.0

// ******************************************************************

Sub EmptyQvd(qvdFilePath)

TRACE --;

TRACE Start EmptyQvd for file $(qvdFilePath);

// First check if the qvd-file exists

if (not IsNull(QvdCreateTime(qvdFilePath))) then

TRACE ... file exists ...;

// Check if the Qvd-file contains more than 0 records

if(QvdNoOfRecords(qvdFilePath) > 0) then

// Get one of the fields to create the fake "WHERE EXISTS" clause

LET vFieldName = QvdFieldName(qvdFilePath,1);

// Now let's create a random value which cannot exist within

// the first field

FakeFieldTable:

LOAD

// Create a fake-field which can never be found within

// the existing qvd

'FakeField' & 'ABCDEFGHIJKLMNOPQRSTWXYZ' &

text(round(rand())) as $(vFieldName)

AutoGenerate(1);

// Create a random table name to prevent collisions with already

// existing tables in memory

LET vTempTableName = '_TempTableName' &

text(round(rand() * pow(9,10)));

// Load the existing QVD-file with and EXISTS clause which cannot

// be found within the QVD-file; so the result will be an empty

// inline table with all field definitions of the QVD-file

$(vTempTableName):

LOAD

*,

1 as loadEnabler

FROM '$(qvdFilePath)' (qvd)

WHERE Exists(Dim1)

;

// Re-Store the QVD-file, just with the field definitions but

// without any data ...

STORE $(vTempTableName) INTO $(qvdFilePath) (qvd);

DROP TABLE $(vTempTableName);

DROP TABLE FakeFieldTable;

end if

else

TRACE ... file '$(qvdFilePath)' does not exist;

end if

TRACE finished EmptyQvd;

TRACE --;

End Sub

// __________________________________________________________________

Call the script with in your load script

Call emptyQvd('.\Sales_2011_10.qvd');

If a = 0 then

TRACE ... TEST SUCCEEDED: QVD file has 0 records ...;

Else

TRACE ... TEST FAILED: QVD file has $(a) records ...

End if

Any one please help me out

8 Replies
Anonymous
Not applicable

Is there something in particular you are having difficulty re using this script  ?

avinashelite

vipin_mishra479
Creator II
Creator II
Author

Hi Bill & Avinash,

Basically my requirement is i just want to delete my all qvd before reload my application and I read 1 blog whereis mention that my requirement but when i try it in my script i am not rectify it.

Blog - QlikTip #30: How to delete existing QVD files via load-script

Anonymous
Not applicable

Could share a sample qvw that demonstrates your issue ?

vipin_mishra479
Creator II
Creator II
Author

I don't have any Specific sample file

requirement is like that I have a 1 Qvw file like Sample Qvw

in this file 1st time i load my data and store a qvd A1.qvd and once i load in second time i store qvd A2.qvd So every day my Qvd will change So thats whay i want delete my all qvd before reload and get only 1 qvd in my qvd folder.

Thanks for your reply Bill

Anonymous
Not applicable

Why not simply keep the output qvd file name the same and then when you do the qvd store the 2nd and subsequent time it will simply overwrite any existing qvd.

Peter_Cammaert
Partner - Champion III
Partner - Champion III

This can also be done in a simpler way. For example by putting your QVD's by default in a single directory and using the EXECUTE; statement. And optionally a few loop constructs if you want to walk through a number of different (sub)directories.

LET vPath = 'C:\Temp\MyProject\Data\';

EXECUTE CMD.EXE DEL "$(vPath)\*.QVD";

vipin_mishra479
Creator II
Creator II
Author

Hi Peter Thanks for reply but i can not use batch in my application there are restriction issue

@Bill Actually what Every day i have load my application then i get one ID (like ID = 236) for each ID i have multiple (300 or 500) business rule like (1,5,9,11,13,15....) for each business rule i create a qvd if i am not create qvd then load script will failed so that i create qvd.

every day i load my application and every day i get Different ID so thats why i need to before reload my application i delete my all qvd.