Skip to content

Instantly share code, notes, and snippets.

@treysmithdev
Created September 18, 2019 19:13
Show Gist options
  • Save treysmithdev/234be710d951a39d6bccf7a3edc214f1 to your computer and use it in GitHub Desktop.
Save treysmithdev/234be710d951a39d6bccf7a3edc214f1 to your computer and use it in GitHub Desktop.
// ****************************************************************************
// **
// ** Reduce Tables
// **
// ****************************************************************************
/*
File: vRT_v1.0.qvs
Version: 1.0
Function: This scripts purpose is to loop through the tables and reload then with
with a where clause and keep or drop the tables not specified.
Usage: $(vMasterScriptsDir)DropTables\IncludeScripts\DropTables.qvs [Version number should be specified in the file path]
CALL vRT('TableField','WhereClauseField'[,KeepFlag])
Bugs: None.
Version Information:
1.0 Initial Build
*/
// ****************************************************************************
// ** Start
// ****************************************************************************
Sub ReduceTables(pReduceDetailTable, pTableField, pWhereClauseField, pDropFlag)
Let vRT_ReduceDetailTable = pReduceDetailTable;
Let vRT_TableField = pTableField;
Let vRT_WhereClauseField = pWhereClauseField;
Let vRT_DropFlag = If(Len(pDropFlag)<1,0,pDropFlag);
Let vRT_TableCount = NoOfTables(); // Determine number of tables.
Let vRT_TablesToKeep = chr(39) & Concat($(pTableField),chr(39)&','&chr(39));
For x = $(vRT_TableCount) to 0 Step -1 // Loop through tables.
Let vRT_TableName = TableName(x-1); // Determine the current table.
If WildMatch(vRT_TableName,vRT_TablesToKeep) = 1 Then
Let vRT_WhereClause = LookUp('$(vRT_WhereClauseField)','$(vRT_TableField)',vRT_TableName, '$(vRT_ReduceDetailTable)')
Rename Table vRT_TableName to 'OrgTable';
$(vRT_TableName):
Load
*
Resident
OrgTable
$(vRT_WhereClause);
Drop Table OrgTable;
vRT_WhereClause=;
TRACE >>>>>>>>>>>>>>>>>>>>>>> Reduced $(vRT_TableName).
Else
If vRT_DropFlag Then
Drop Table $(vRT_TableName); // Drop the table.
Else
TRACE >>>>>>>>>>>>>>>>>>>>>>> Keeping $(vRT_TableName) as is.
EndIF;
EndIf;
Next x
// Repeat.
vRT_TableCount=;vRT_TableName=;x=; // Clean up.
EndSub;
// ****************************************************************************
// ** End
// ****************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment