/
Qvc_ExportTables.qvs
65 lines (51 loc) · 2.9 KB
/
Qvc_ExportTables.qvs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
///$tab ExportTables
SUB Qvc.ExportTables (_outputDir, _format, _filter)
/**
@source Qvc_ExportTables.qvs
Export tables to a QVD or CSV files.
The output filename will be Tablename.format. For example, a QV table named "Orders" will be stored as "Orders.csv" if param#2 is "csv".
@param 1 String. Optional. Relative or absolute directory where the tables will be stored. If relative, it follows the same rules as the STORE script statement for relative directory.
@param 2 String, Optional. Format and extension of the stored file. Valid values are "qvd", "txt", "csv". "qvd" will create files in the QVD format, "txt" or "csv" will create file in CSV format. If omitted, default is "qvd".
@param 3 String, Optional. Filter expression that can be used to limit the tables processed. In the expression, $1 is used to represent the tablename. For example, 'NOT $1 LIKE ''Log*''' will exclude any tablenames that begin with "Log*" (note the quote escaping). If omitted, the default is 'NOT $1 LIKE ''Qvc.LogTable'''
@syntax CALL Qvc.ExportTables(['outputDir'],['format'],['filter']);
*/
UNQUALIFY "_qvctemp.*"; // UNQUALIFY all qvctemp fields
LET _qvctemp.TableName=left(DocumentName(),len(DocumentName())-4); // Table name is document name
//Set default values for params if not passed
// Directory to Store in
LET _qvctemp.qvddir = if(len(Trim('$(_outputDir)'))=0, '', Trim('$(_outputDir)'));
// Add the ending \ if the passed path is missing it
IF len('$(_qvctemp.qvddir)')>0 AND NOT right(_qvctemp.qvddirqvddir,1)='\' THEN
LET _qvctemp.qvddir = _qvctemp.qvddir & '\';
END IF
// Format to Store
IF NOT WildMatch(trim('$(_format)'),'','qvd','csv','txt') THEN
SET _qvctemp.ErrorMsg='Qvc.ExportTables: Invalid value "$(_format)" specified for parameter #2. Valid values are "qvd", "txt", "csv"';
CALL _Qvc.Error('$(Qvc.Log.v.Level.ERROR)', '$(_qvctemp.ErrorMsg)')
EXIT SCRIPT;
ENDIF
LET _qvctemp.format = if(len(trim('$(_format)'))=0, 'qvd', lower(trim('$(_format)')));
// File extension to use. Same as Format parameter.
LET _qvctemp.ext = '$(_qvctemp.format)';
// We are allowing "csv" as an alias for the STORE (txt) format. if "csv", change to "txt"
LET _qvctemp.format = if('$(_qvctemp.format)' = 'csv', 'txt','$(_qvctemp.format)');
// Filter expression
LET _qvctemp.filter =
if(len(trim('$(_filter)'))=0, 'NOT $1 LIKE ''Qvc.LogTable'''
, '$(_filter)'
);
// Loop through the tables, storing those not excluded;
FOR _qvctemp.i = NoOfTables()-1 to 0 step -1
LET _qvctemp.vTable = TableName($(_qvctemp.i));
IF $(_qvctemp.filter('$(_qvctemp.vTable)')) THEN
STORE [$(_qvctemp.vTable)] INTO [$(_qvctemp.qvddir)$(_qvctemp.vTable).$(_qvctemp.ext)] ($(_qvctemp.format));
CALL Qvc.Log('Table [$(_qvctemp.vTable)] STOREd INTO [$(_qvctemp.qvddir)$(_qvctemp.vTable).$(_qvctemp.ext)]')
ENDIF
NEXT _qvctemp.i
// Clean up temp variables
SET _qvctemp.vTable=;
SET _qvctemp.qvddir=;
SET _qvctemp.i=;
SET _qvctemp.format=;
SET _qvctemp.ext=;
END SUB