You are on page 1of 167

'MsgBox "Regression to begin " & Chr(10) & "Please click OK ",,"KRegression Tool"

'**********************************************************************************
**************************
'Project Name : <Generic Framework>
'Author : Khadeer
'Creation Date : 2-Apr-2015
'Module Name : Controller
'Description : Regression tool is used to compare two files/tables
also for executing testcases
'**********************************************************************************
**************************

'Option Explicit
'==================================================================================
==========================
'Declaration of Variables
'==================================================================================
==========================
Dim vProjectFdr_Path, vControllerFdr, vDatasheetFdr, vResultFdr,
vComparisonFilesFdr
Dim vTD_FileName, vTD_Mainsheet,vTD_DbCredentials
Dim vSmplResSumry_Path, vResSummary_SheetName
Dim vTDResult_FileName, vResSummary_FileName
Dim vColValdt_Path, vColValdt_SheetName
Dim vFixedWidth_Path, vFixedWidth_SheetName
Dim Obj_FSO, Obj_Dict_Conf, Obj_Dict_RegTC, Obj_Wsh
Dim ObjXL_Main, ObjWB_Main, ObjWS_Main
Dim vTotalColumn_Used, vTotalRow_Used, vRowTitleNo
Dim vTempTextValue
Dim vArrFilters(), vArrDifferences()
Dim vRowNoConf
Dim vAlphaExcl_TotCol_Used
Dim vModuleName_ColNo, vScenarioName_ColNo, vSetFlag_ColNo, vTDStatus_ColNo

'==================================================================================
==========================
'Initialisation of variable whose values will be constant

vProjectFdr_Path = "C:\temp\KRegression_Tool\"
'vProjectFdr_Path =
CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
'vProjectFdr_Path = Replace(Replace(vProjectFdr_Path, "Library",""),
"Controller","")
vControllerFdr = vProjectFdr_Path & "Controller\"
vDatasheetFdr = vProjectFdr_Path & "DataSheets\"
vResultFdr = vProjectFdr_Path & "Result\"
vComparisonFilesFdr = vProjectFdr_Path & "Comparison_Files\"
vLibraryFdr = vProjectFdr_Path & "Library\"
vLogFilesFdr = vProjectFdr_Path & "LogFiles\"
vTD_FileName = "RegressionTool_TD.xlsx"
vTD_Filepath = vDatasheetFdr & vTD_FileName
vTD_Mainsheet = "Configuration"
vTD_DbCrdnSheet = "DB_ConnectionDetails"
vTD_UnixCrdnSheet = "Unix_ConnectionDetails"
vTD_QCCrdnSheet = "QC_ConnectionDetails"
vSmplResSumry_Path = vControllerFdr & "Sample_Result_Summary.xlsx"
vResSummary_SheetName = "Result_Summary"
vResSummary_FileName = "ResultSummary" & Day(Date) & Month(Date) &
Hour(Time) & Minute(Time)
vExecutionLog_FileName = "ExecutionLog" & Day(Date) & Month(Date) & Hour(Time)
& Minute(Time) & ".txt"
vColValdt_Path = vDatasheetFdr & "Column_Validation.xlsx"
vFixedWidth_Path = vDatasheetFdr & "FixedWidth_Schema.xlsx"
vMasterData_Path = vDatasheetFdr & "Master_Data.xlsx"
vDiffSheetName = "Diff_Actual_Baseline"
varf_FilterFile_path = vResultFdr & "Filter.txt"
vNoOfRec_PerDynFilter = 500
vRowNoConf = 2
vRowNoTC = 1
Call KillProcessor("excel.exe")

'==================================================================================
==========================
'Defining the class objects FSO, Wscript, Excel, Dictionary

Set Obj_FSO = CreateObject("Scripting.FileSystemObject")


Set Obj_Dict_Conf = CreateObject("Scripting.Dictionary")
Set Obj_Dict_RegTC = CreateObject("Scripting.Dictionary")
Set Obj_Wsh = CreateObject("Wscript.Shell")
Set ObjXL_Main = CreateObject("Excel.Application")
Set Obj_WshNet = CreateObject("WScript.Network")
Set Obj_ExeLog = Obj_FSO.OpenTextFile(vResultFdr &
vExecutionLog_FileName,2,True)
Set ObjWB_Main = ObjXL_Main.Workbooks.Open(vTD_Filepath)
Set ObjWS_Main = ObjXL_Main.Worksheets(vTD_Mainsheet)
Set ObjWB_Master_Data = ObjXL_Main.WorkBooks.Open(vMasterData_Path)
ObjXL_Main.Visible = False
ObjXL_Main.DisplayAlerts = False

'==================================================================================
==========================
'Create and define the log file and validate the folder structure

Obj_ExeLog.WriteLine String(50,"*") & String(5," ") & "Regression_Main_Log" &


String(5," ") & String(50,"*")
Obj_ExeLog.WriteBlankLines 1
Obj_ExeLog.WriteLine "Execution Start Time : " & Now()
Obj_ExeLog.WriteLine "User Running the script : " & Ucase(Obj_WshNet.UserName)
Obj_ExeLog.WriteBlankLines 2
Obj_ExeLog.WriteLine "# Validating the folder structure of the regression pack"

If Not Obj_FSO.FolderExists(vComparisonFilesFdr) Then Obj_FSO.CreateFolder


vComparisonFilesFdr
If Not Obj_FSO.FolderExists(vComparisonFilesFdr & "temp\") Then
Obj_FSO.CreateFolder vComparisonFilesFdr & "temp\"
If Not Obj_FSO.FolderExists(vControllerFdr) Then Obj_FSO.CreateFolder
vControllerFdr
If Not Obj_FSO.FolderExists(vLibraryFdr) Then Obj_FSO.CreateFolder vLibraryFdr
If Not Obj_FSO.FolderExists(vResultFdr) Then Obj_FSO.CreateFolder vResultFdr
If Not Obj_FSO.FileExists(vTD_Filepath) Then
Obj_ExeLog.WriteLine "# Datasheet not found in the path vTD_Filepath"
Obj_ExeLog.WriteLine "# Execution is stopped"
Call KillProcessor("wscript.exe")
End If
If Not Obj_FSO.FileExists(vSmplResSumry_Path) Then
Obj_ExeLog.WriteLine "# Sample result structure file not found in the path
vTD_Filepath"
Obj_ExeLog.WriteLine "# Execution is stopped"
Call KillProcessor("wscript.exe")
End If

Obj_ExeLog.WriteLine "# Comparison_Files folder is available and also it has temp


folder"
Obj_ExeLog.WriteLine "# DataSheet Folder exist and it contains " & vTD_FileName
Obj_ExeLog.WriteLine "# Result and Library folder exist"
Obj_ExeLog.WriteLine "# Controller folder is available and also it has " &
vSmplResSumry_Path & " file"
Obj_ExeLog.WriteBlankLines 1
Obj_ExeLog.WriteLine String(15,"-") & "Executing the scenarios mentioned in
datasheet" & String(15,"-")

'==================================================================================
==========================
'Fetch the column Number from configuration sheet for few attributes

vTotCol_Main = Cint(ObjWS_Main.UsedRange.Columns.Count)
vTotRow_Main = Cint(ObjWS_Main.UsedRange.Rows.Count)

If vTotCol_Main > 50 Then vTotCol_Main = 50 ' handling the mistakes


while copying or unwanted test data
If vTotCol_Main > 26 Then
vAlphaExcl_TotCol_Used = "A" & Chr(vTotCol_Main + 38)
Else
vAlphaExcl_TotCol_Used = Chr(vTotCol_Main + 64)
End If

vScenarioName_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &


vAlphaExcl_TotCol_Used & vRowNoConf).Find("ScenarioName").Column
vSetFlag_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("SetFlag").Column
vTDStatus_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Status").Column

'==================================================================================
==========================
'Fetch the scenario for execution whose trigger mentioned in setflag "Y" from
configuration sheet

For vRowCnt_Conf = 3 To vTotRow_Main


If (StrComp(UCase(ObjWS_Main.Cells(vRowCnt_Conf, vSetFlag_ColNo).Value),
"Y",1) = 0) Or _
(StrComp(UCase(ObjWS_Main.Cells(vRowCnt_Conf,
vSetFlag_ColNo).Value), "CONTINUE",1) = 0) Then
If StrComp(UCase(ObjWS_Main.Cells(vRowCnt_Conf,
vSetFlag_ColNo).Value), "Y",1) = 0 Then
If Obj_FSO.FileExists(varf_FilterFile_path) Then
Obj_FSO.DeleteFile varf_FilterFile_path
End If
For vColCnt_Conf = 1 To vTotCol_Main
vKey_Conf = ObjWS_Main.Cells(vRowNoConf, vColCnt_Conf).Value
vItem_Conf = ObjWS_Main.Cells(vRowCnt_Conf,
vColCnt_Conf).Value
Obj_Dict_Conf.Add vKey_Conf, vItem_Conf
Next
vScenarioName = Trim(Obj_Dict_Conf("ScenarioName"))
vStaticTimestamp_DDMMHHMM = Day(Date) & Month(Date) & Hour(Time) &
Minute(Time) & Second(Time)
Obj_ExeLog.WriteBlankLines 1
Obj_ExeLog.WriteLine "# Scenario No. " & vRowCnt_Conf-2 & " " &
Chr(34) & vScenarioName & Chr(34) & " flag is set as Y"
Obj_ExeLog.WriteLine "# All the fileds of a Scenario No. " &
vRowCnt_Conf & " copied into dictionary object successfully"

'==================================================================================
==========================
'Create Result File with name as specific to scenario name, data and time stamp

vTDResult_FileName = Replace(vScenarioName, " ", "") &


vStaticTimestamp_DDMMHHMM & ".xlsx"
Obj_ExeLog.WriteLine "# Result file Name for the scenario " &
Chr(34) & vScenarioName & Chr(34) & " is " & vTDResult_FileName

'==================================================================================
==========================
'Create Result Folder if not exist and copy the TD to result folder and set the
result TD object

If Obj_Dict_Conf("Result_Location") = "" Or
Obj_Dict_Conf("Result_Location") = Empty Then
If Not Obj_FSO.FolderExists(vResultFdr) Then
Obj_FSO.CreateFolder(vResultFdr)
Obj_FSO.CopyFile (vTD_Filepath), (vResultFdr &
vTDResult_FileName), True
Set ObjWB_Result = ObjXL_Main.Workbooks.Open(vResultFdr &
vTDResult_FileName)
Obj_ExeLog.WriteLine "# Result Report " & vTDResult_FileName
& " is created into folder " & vResultFdr
varf_WBResultReport_Location = vResultFdr &
vTDResult_FileName
Else
If Obj_FSO.FolderExists(Obj_Dict_Conf("Result_Location")) =
True Then
Obj_FSO.CopyFile (vTD_Filepath),
Obj_Dict_Conf("Result_Location") & vTDResult_FileName , True
Set ObjWB_Result =
ObjXL_Main.Workbooks.Open(Obj_Dict_Conf("Result_Location") & vTDResult_FileName)
Obj_ExeLog.WriteLine "# Result Report " &
vTDResult_FileName & " is created into folder " & Obj_Dict_Conf("Result_Location")
varf_WBResultReport_Location =
Obj_Dict_Conf("Result_Location") & vTDResult_FileName
Else
If Not Obj_FSO.FolderExists(vResultFdr) Then
Obj_FSO.CreateFolder(vResultFdr)
Obj_FSO.CopyFile (vTD_Filepath), (vResultFdr &
vTDResult_FileName), True
Set ObjWB_Result =
ObjXL_Main.Workbooks.Open(vResultFdr & vTDResult_FileName)
Obj_ExeLog.WriteLine "# Provided Result location not
exist and so copying the TD into result folder"
Obj_ExeLog.WriteLine "# Result Report " &
vTDResult_FileName & " is created into folder " & vResultFdr
varf_WBResultReport_Location = vResultFdr &
vTDResult_FileName
End If
End If
'==================================================================================
==========================
'Delete all the records under result TD configuration sheet except being executed

Set ObjWS_Result = ObjWB_Result.Worksheets(vTD_Mainsheet)


vRowNo_DelScenario = 3

For vRowCntDel_Conf=3 To vTotRow_Main

If StrComp(ObjWS_Result.cells(vRowNo_DelScenario,
vScenarioName_ColNo).Value, vScenarioName, 1) <> 0 Then
On Error Resume Next
Set TargetSheet =
ObjWB_Result.Worksheets(ObjWS_Result.Cells(vRowNo_DelScenario,vScenarioName_ColNo).
Value)
If Not TargetSheet Is Nothing Then
ObjWB_Result.Worksheets(ObjWS_Result.Cells(vRowNo_DelScenario,vScenarioName_ColNo).
Value).Delete
ObjWS_Result.Rows(vRowNo_DelScenario).EntireRow.Delete
Set TargetSheet = Nothing
On Error Goto 0
Else
vRowNo_DelScenario = vRowNo_DelScenario + 1
End If
Next

ObjWB_Result.Worksheets(vTD_Mainsheet).Activate
ObjWB_Result.Worksheets(vTD_Mainsheet).Cells(1,3).Select
Obj_ExeLog.WriteLine "# All scenarios define in result report
configuration sheet are deleted except "& vScenarioName &" scenario which is under
execution"

'==================================================================================
==========================
' Based on the comparison data availablity column value specific function will be
executed

If UCase(Obj_Dict_Conf("Testing_Type")) = "FILE CMP" Then


varf_AutoResultFileOpening = varf_AutoResultFileOpening & "
CMP"
Obj_ExeLog.WriteLine "# File comparison function is triggered"
Call f_Comparison_Mainfunction ("FILE", vProjectFdr_Path,
vResultFdr, vComparisonFilesFdr, vColValdt_Path, vFixedWidth_Path, vTD_DbCrdnSheet,
_
varf_FilterFile_path, vSmplResSumry_Path,
vResSummary_SheetName, vResSummary_FileName, vTDResult_FileName, vDiffSheetName,
ObjXL_Main, _
Obj_Dict_Conf, Obj_FSO, Obj_Wsh, Obj_ExeLog,
ObjWB_Result, vNoOfRec_PerDynFilter,vStaticTimestamp_DDMMHHMM, vStatus)
ElseIf UCase(Obj_Dict_Conf("Testing_Type")) = "TABLE CMP" Then
varf_AutoResultFileOpening = varf_AutoResultFileOpening & "
CMP"
Obj_ExeLog.WriteLine "# Table comparison function is
triggered"
Call f_Comparison_Mainfunction ("TABLE", vProjectFdr_Path,
vResultFdr, vComparisonFilesFdr, vColValdt_Path, vFixedWidth_Path, vTD_DbCrdnSheet,
_
varf_FilterFile_path, vSmplResSumry_Path,
vResSummary_SheetName, vResSummary_FileName, vTDResult_FileName, vDiffSheetName,
ObjXL_Main, _
Obj_Dict_Conf, Obj_FSO, Obj_Wsh, Obj_ExeLog,
ObjWB_Result, vNoOfRec_PerDynFilter,vStaticTimestamp_DDMMHHMM, vStatus)
ElseIf UCase(Obj_Dict_Conf("Testing_Type")) = "TC_REGRESSION" Then

'==================================================================================
==========================
' Regression Framework to execute the test cases
varf_AutoResultFileOpening = varf_AutoResultFileOpening & "
REG"
Obj_ExeLog.WriteLine "# Test Case Regression Framework is
triggered"
If Func_Worksheet_Exist(vScenarioName, ObjWB_Result) =1 Then
Obj_ExeLog.WriteLine "# " & vScenarioName & " scenario
sheet found in Test data"
Set ObjWS_ResultScen =
ObjWB_Result.Worksheets(vScenarioName)
vTotRow_Scenario =
CInt(ObjWS_ResultScen.UsedRange.Rows.count)
vTotCol_Scenario =
CInt(ObjWS_ResultScen.UsedRange.Columns.count)

vTC_Name_ColNo = ObjWS_ResultScen.Range("A" &


vRowNoScen & ":" & Chr(64+vTotCol_Scenario) &
vRowNoScen).Find("TestCase_Name").Column
vTC_Execute_ColNo = ObjWS_ResultScen.Range("A" &
vRowNoScen & ":" & Chr(64+vTotCol_Scenario) & vRowNoScen).Find("Execute").Column
vTC_FuncRowNo_ColNo = ObjWS_ResultScen.Range("A" &
vRowNoScen & ":" & Chr(64+vTotCol_Scenario) &
vRowNoScen).Find("Func_RowNumber").Column
vTC_STATUS_ColNo = ObjWS_ResultScen.Range("A" &
vRowNoScen & ":" & Chr(64+vTotCol_Scenario) & vRowNoScen).Find("Status").Column

'==================================================================================
==================================
' Delete all Test cases sheet which are not mentioned as "Y" in scenario sheet

For vRowCnt_Scen = 2 To vTotRow_Scenario


On Error Resume Next
If StrComp(ObjWS_ResultScen.Cells(vRowCnt_Scen,
vTC_Execute_ColNo).Value,"Y",1) <> 0 Then

ObjWB_Result.Worksheets(ObjWS_ResultScen.Cells(vRowCnt_Scen,vTC_Name_ColNo).Value).
Delete
End If
On Error Goto 0
Next
Obj_ExeLog.WriteLine "# Deleted successfully all the TC
sheet which are not mentioned as Y in scenario sheet"

'==================================================================================
==================================
' Execute the TestCase on the basis of row number

For vRowCnt_Scen = 2 To vTotRow_Scenario


If StrComp(ObjWS_ResultScen.Cells(vRowCnt_Scen,
vTC_Execute_ColNo).Value,"Y",1) = 0 Then
vTC_Name =
ObjWS_ResultScen.Cells(vRowCnt_Scen,vTC_Name_ColNo).Value
Obj_ExeLog.WriteLine "# Test case function No.
" & vRowCnt_Scen-1 & " flag is true in TD file"
Obj_ExeLog.WriteLine "# "& vTC_Name & " TC is
trigerred and will be executed"
If (Func_WorkSheet_Exist(vTC_Name,
ObjWB_Result)) = 1 Then
Obj_ExeLog.WriteLine "# "& vTC_Name & "
TC sheet is found in test data file"
vTC_FuncRowNo =
ObjWS_ResultScen.Cells(vRowCnt_Scen,vTC_FuncRowNo_ColNo).Value
If (UCase(vTC_FuncRowNo) = "ALLROWS")
Then
Obj_ExeLog.WriteLine "# " &
vScenarioName & " sheet as TC " & vTC_Name & " whose function row number is " &
vTC_FuncRowNo
Set ObjWS_ResultTC =
ObjWB_Result.Worksheets(vTC_Name)
vTotRow_TC =
CInt(ObjWS_ResultTC.UsedRange.Rows.count)
vTotCol_TC =
CInt(ObjWS_ResultTC.UsedRange.Columns.count)
vFuncTC_Status_ColNo =
ObjWS_ResultTC.Range("A" & vRowNoTC & ":" & Chr(64+vTotCol_TC) &
vRowNoTC).Find("Status").Column
vFuncTC_Remarks_ColNo =
ObjWS_ResultTC.Range("A" & vRowNoTC & ":" & Chr(64+vTotCol_TC) &
vRowNoTC).Find("Remarks").Column
Obj_ExeLog.WriteLine "# Executing
all the rows define in TC " & vTC_Name & " sheet one by one"
Obj_ExeLog.WriteLine "# " &
vTotRow_TC-vRowNoTC & " itteration for function "& vTC_Name & " should be executed"
For vRowCnt_TC = 2 To vTotRow_TC
For vColCnt_TC = 1 To
vTotCol_TC
vKey_TC =
ObjWS_ResultTC.cells(vRowNoTC, vColCnt_TC).value
vItem_TC =
ObjWS_ResultTC.cells(vRowCnt_TC, vColCnt_TC).value
Obj_Dict_RegTC.Add
vKey_TC, vItem_TC
Next
vStatus = Empty
vTC_FuncRowNo_Value =
vRowCnt_TC
Execute "Call " & vTC_Name &
"(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main, ObjWB_Master_Data," & _

"vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rem
arks_ColNo,vTC_FuncRowNo_Value,vStatus)"
Call
Func_UpdateStatus(ObjWS_ResultTC, vRowCnt_TC, vFuncTC_Status_ColNo, vStatus)
'Update the status in TC Sheet
If vStatus = "FAIL" Then
vStatus_Once = "FAIL"
Obj_Dict_RegTC.RemoveAll
Obj_ExeLog.WriteLine "# " &
vRowCnt_TC-1 & " record executed successfully and its status is " & vStatus
Next
Obj_ExeLog.WriteLine "# All the
rows available in TC sheet " & vTC_Name & " are executed successfully"
Obj_ExeLog.WriteBlankLines 1

ElseIf Instr(1,vTC_FuncRowNo,"-")>0 Then


Obj_ExeLog.WriteLine "# " &
vScenarioName & " sheet as TC " & vTC_Name & " whose function row number is " &
vTC_FuncRowNo
Set ObjWS_ResultTC =
ObjWB_Result.Worksheets(vTC_Name)
vTotRow_TC =
CInt(ObjWS_ResultTC.UsedRange.Rows.count)
vTotCol_TC =
CInt(ObjWS_ResultTC.UsedRange.Columns.count)
vTC_FuncRowNo_LowNo =
Cint(Trim(Split(vTC_FuncRowNo,"-")(0)))
vTC_FuncRowNo_HighNo =
Cint(Trim(Split(vTC_FuncRowNo,"-")(1)))
vFuncTC_Status_ColNo =
ObjWS_ResultTC.Range("A" & vRowNoTC & ":" & Chr(64+vTotCol_TC) &
vRowNoTC).Find("Status").Column
vFuncTC_Remarks_ColNo =
ObjWS_ResultTC.Range("A" & vRowNoTC & ":" & Chr(64+vTotCol_TC) &
vRowNoTC).Find("Remarks").Column
Obj_ExeLog.WriteLine "# Executing
specific rows "& vTC_FuncRowNo & " define in TC " & vTC_Name & " sheet one by one"
Obj_ExeLog.WriteLine "# " &
vTC_FuncRowNo_HighNo-vTC_FuncRowNo_LowNo & " No. of itteration for function
vTC_Name should be executed"
For vTC_FuncRowNo_SplitCnt =
vTC_FuncRowNo_LowNo To vTC_FuncRowNo_HighNo
For vColCnt_TC = 1 To
vTotCol_TC
vKey_TC =
ObjWS_ResultTC.cells(vRowNoTC, vColCnt_TC).value
vItem_TC =
ObjWS_ResultTC.cells(vTC_FuncRowNo_SplitCnt, vColCnt_TC).Value
Obj_Dict_RegTC.Add
vKey_TC, vItem_TC
Next
vStatus = Empty
vTC_FuncRowNo_Value =
vTC_FuncRowNo_SplitCnt
Execute "Call " & vTC_Name &
"(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data," & _

"vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rem
arks_ColNo,vTC_FuncRowNo_Value,vStatus)"
Call
Func_UpdateStatus(ObjWS_ResultTC, vTC_FuncRowNo_Value, vFuncTC_Status_ColNo,
vStatus)
If vStatus = "FAIL" Then
vStatus_Once = "FAIL"
Obj_Dict_RegTC.RemoveAll
Obj_ExeLog.WriteLine "# " &
vTC_FuncRowNo_Value & " record executed successfully and its status is " & vStatus
Next
Obj_ExeLog.WriteLine "# " &
vTC_FuncRowNo & " row available in TC sheet " & vTC_Name & " are executed
successfully"

ElseIf (vTC_FuncRowNo <> Empty And


vTC_FuncRowNo <> "") Then
Obj_ExeLog.WriteLine "# " &
vScenarioName & " sheet as TC " & vTC_Name & " whose function row number is " &
vTC_FuncRowNo
Set ObjWS_ResultTC =
ObjWB_Result.Worksheets(vTC_Name)
vTotRow_TC =
CInt(ObjWS_ResultTC.UsedRange.Rows.count)
vTotCol_TC =
CInt(ObjWS_ResultTC.UsedRange.Columns.count)
If vTotCol_TC > 26 Then vTotCol_TC
= 10
vTC_FuncRowNo_Split =
Split(vTC_FuncRowNo, Chr(44))
vFuncTC_Status_ColNo =
ObjWS_ResultTC.Range("A" & vRowNoTC & ":" & Chr(64+vTotCol_TC) &
vRowNoTC).Find("Status").Column
vFuncTC_Remarks_ColNo =
ObjWS_ResultTC.Range("A" & vRowNoTC & ":" & Chr(64+vTotCol_TC) &
vRowNoTC).Find("Remarks").Column
Obj_ExeLog.WriteLine "# Executing
specific rows "& vTC_FuncRowNo & " define in TC " & vTC_Name & " sheet one by one"
Obj_ExeLog.WriteLine "# " &
UBound(vTC_FuncRowNo_Split) & " No. of itteration for function vTC_Name should be
executed"
For vTC_FuncRowNo_SplitCnt = 0 To
UBound(vTC_FuncRowNo_Split)
For vColCnt_TC = 1 To
vTotCol_TC
vKey_TC =
ObjWS_ResultTC.cells(vRowNoTC, vColCnt_TC).value
vItem_TC =
ObjWS_ResultTC.cells(vTC_FuncRowNo_Split(vTC_FuncRowNo_SplitCnt), vColCnt_TC).Value
Obj_Dict_RegTC.Add
vKey_TC, vItem_TC
Next
vStatus = Empty
vTC_FuncRowNo_Value =
vTC_FuncRowNo_Split(vTC_FuncRowNo_SplitCnt)
Execute "Call " & vTC_Name &
"(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data," & _

"vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rem
arks_ColNo,vTC_FuncRowNo_Value,vStatus)"
Call
Func_UpdateStatus(ObjWS_ResultTC, vTC_FuncRowNo_Value, vFuncTC_Status_ColNo,
vStatus)
If vStatus = "FAIL" Then
vStatus_Once = "FAIL"
Obj_Dict_RegTC.RemoveAll
Obj_ExeLog.WriteLine "# " &
vTC_FuncRowNo_Value & " record executed successfully and its status is " & vStatus
Next
Obj_ExeLog.WriteLine "# " &
vTC_FuncRowNo & " row available in TC sheet " & vTC_Name & " are executed
successfully"

ElseIf StrComp(vTC_FuncRowNo, "0",1) =0


Then
Obj_ExeLog.WriteLine "# No test
data required for executing the TC " & vTC_Name & " And output result will be
updated into TC sheet "& vTC_Name
Execute "Call " & vTC_Name &
"(vTC_Name, Obj_Dict_Conf, ObjWB_Result, Obj_FSO, ObjXL_Main, vStatus)"
Obj_ExeLog.WriteLine "# " &
vTC_Name & " TC executed successfully and its status is " & vStatus
Obj_ExeLog.WriteBlankLines 1

Else
vStatus = "FAIL"
' Row Number column for respective testcase should not be empty
Obj_ExeLog.WriteLine "# unexpected
or empty Function_RowNumber mentioned in scenario sheet"
End If

If vStatus_Once = "FAIL" Then vStatus =


"FAIL" 'Update the status in TC Sheet
Call Func_UpdateStatus(ObjWS_ResultScen,
vRowCnt_Scen, vTC_STATUS_ColNo, vStatus)
vStatus_once = Empty

Else
vStatus = "FAIL"
vRemarkcTC =
"None" ' TC sheet not found in TestDate
File
Obj_ExeLog.WriteLine "# Under scenarion
sheet TC " & vTC_Name & " flag is up but TC sheet is not available in TD file"
Call Func_UpdateStatus(ObjWS_ResultScen,
vRowCnt_Scen, vTC_STATUS_ColNo, vStatus,vFuncTC_Remarks_ColNo, vRemarkcTC)
End If

Else
vStatus = "Not Executed"
vRemarkcTC = "None"
' TC sheet not found in TestDate File ' Update
status TC not mentioned "Y"
Obj_ExeLog.WriteLine "# Test case function No.
" & vRowCnt_Scen-1 & " flag is not set in TD file"
Obj_ExeLog.WriteBlankLines 1
Call Func_UpdateStatus(ObjWS_ResultScen,
vRowCnt_Scen, vTC_STATUS_ColNo, vStatus)
End If

Next

' Extract the final vstatus from complete test cases executed under the scenario
vStatus_Fail = Empty
vStatus_Pass = Empty
For vRowScenCnt_Status = 2 To vTotRow_Scenario
If UCase(ObjWS_ResultScen.Cells(vRowScenCnt_Status,
vTC_STATUS_ColNo).Value) = "FAIL" Then
vStatus_Fail = "Found"
ElseIf
UCase(ObjWS_ResultScen.Cells(vRowScenCnt_Status, vTC_STATUS_ColNo).Value) = "PASS"
Then
vStatus_Pass = "Found"
End If
Next

If vStatus_Fail = "Found" Then vStatus = "FAIL"


If vStatus_Pass = "Found" And vStatus_Fail <> "Found" Then
vStatus = "PASS"
If vStatus_Pass <> "Found" And vStatus_Fail <> "Found"
Then vStatus = "Not Executed"

Else
vStatus = "FAIL" ' Scenario
Sheet not found in Test Data file
Obj_ExeLog.WriteLine "# Test Case regression scenario flag
is up in config sheet but scenario sheet " & vScenarioName & " is not available in
TD file"
Obj_ExeLog.WriteBlankLines 1
End If

Else
vStatus = "FAIL"
Obj_ExeLog.WriteLine "# Unexpected value found in column
cmp_data_avalibility"
Obj_ExeLog.WriteBlankLines 1
End If

' Delete the sheet which are not required in Result report
On Error Resume Next
If UCase(Obj_Dict_Conf("Testing_Type")) = "FILE CMP" Or
UCase(Obj_Dict_Conf("Testing_Type")) = "TABLE CMP" Then
For Each vSheet_to_Delete In ObjWB_Result.Sheets
If InStr(1, vSheet_to_Delete.Name, "Configuration") > 0
Or InStr(1, vSheet_to_Delete.Name, "===") > 0 Or _
((InStr(1, vSheet_to_Delete.Name,
"Diff_Actual_Baseline") > 0 And TRIM(UCASE(vStatus)) <> "PASS") And _

UCase(Trim(Obj_Dict_Conf("Result_Format"))) <> "CSV") Then

ObjWB_Result.Worksheets(vSheet_to_Delete.Name).Visible = True
Else
vSheet_to_Delete.Delete
End If
Next
Else
For Each vSheet_to_Delete In ObjWB_Result.Sheets
If InStr(1, vSheet_to_Delete.Name, vTD_DbCrdnSheet) > 0
Or InStr(1, vSheet_to_Delete.Name, vTD_UnixCrdnSheet) > 0 Or InStr(1,
vSheet_to_Delete.Name, vTD_QCCrdnSheet) > 0 Or _
InStr(1, vSheet_to_Delete.Name,
"Diff_Actual_Baseline") > 0 or InStr(1, vSheet_to_Delete.Name, "All_TC") > 0 Then
vSheet_to_Delete.Delete
Else

ObjWB_Result.Worksheets(vSheet_to_Delete.Name).Visible = True
End If
Next
ObjWB_Result.Worksheets("Configuration").Activate
End If
ObjWB_Result.Worksheets("===").Visible = False
On Error Goto 0

' Enter the Execution result of complete scenario in configuration sheet

Call Func_UpdateStatus (ObjWS_Result, 3, vTDStatus_ColNo, vStatus)

ObjWS_Result.Cells(1,vTDStatus_ColNo).EntireColumn.Hidden = False
ObjWB_Result.Save
ObjWB_Result.Close
Obj_Dict_Conf.RemoveAll

Else
' As per the framework all the scenarios which are mentioned as N or
empty will be deleted
' vStatus = "Not Executed" ' Update Status
scenario record not mentioned "Y" in scenraio sheet
Obj_ExeLog.WriteLine "# Scenario No. " & vRowCnt_Conf-2 & " Flag is
not set and it is not executed "
Obj_ExeLog.WriteBlankLines 1
End If
vStatus = ""
Next

Obj_ExeLog.WriteLine String(50,"*") & " Regression Completed " & String


(50,"*")

ObjWB_Main.Close
ObjXL_Main.Quit
Obj_ExeLog.Close

' De-allocate the memory of the object


Set ObjWS_Main = Nothing
Set ObjWB_Main = Nothing
Set ObjXL_Main = Nothing
Set Obj_Wsh = Nothing
Set Obj_Dict = Nothing
Set Obj_FSO = Nothing

Call KillProcessor("cmd.exe")
Call KillProcessor("Excel.exe")

MsgBox " Regression Completed "

If Instr(1, varf_AutoResultFileOpening,"CMP") > 0 and Instr(1,


varf_AutoResultFileOpening,"REG") > 0 Then
' Both Regression and comparison is used , cant open both files
' CreateObject("Wscript.Shell").run Chr(34) & (vResultFdr &
vExecutionLog_FileName) & Chr(34)
ElseIf Instr(1, varf_AutoResultFileOpening,"CMP") > 0 Then
CreateObject("Wscript.Shell").run Chr(34) & (vResultFdr &
vResSummary_FileName & ".xlsx") & Chr(34)
Else
CreateObject("Wscript.Shell").run Chr(34) &
(varf_WBResultReport_Location) & Chr(34)
End If
'==================================== End Of Controller
==========================================

'**********************************************************************************
**************************
' File Comparison Functions
'**********************************************************************************
**************************

Public Function f_Comparison_Mainfunction (vComparisonType, vProjectFdr_Path,


vResultFdr, vComparisonFilesFdr, vColValdt_Path, vFixedWidth_Path, vTD_DbCrdnSheet,
_
varf_FilterFile_path, vSmplResSumry_Path,
vResSummary_SheetName, vResSummary_FileName, vTDResult_FileName, vDiffSheetName,
ObjXL_Main, _
Obj_Dict_Conf, Obj_FSO, Obj_Wsh, Obj_ExeLog,
ObjWB_Result, vNoOfRec_PerDynFilter, vStaticTimestamp_DDMMHHMM, vStatus)

' Declaration of variables


Dim Obj_DBConn

' Extract the values from main dictionary object into variables

varf_ModuleName =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("ModuleName"))," ,
",",")," ,",","),", ",",")," ","_")
varf_ScenarioName =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("ScenarioName"))," ,
",",")," ,",","),", ",",")," ","_")
varf_SetFlag = Trim(Ucase(Obj_Dict_Conf("SetFlag")))
varf_Testing_Type = Trim(Ucase(Obj_Dict_Conf("Testing_Type")))
varf_Comparison_Format =
Trim(Ucase(Obj_Dict_Conf("Comparison_Format")))
varf_Actual_FileLocation_DBName = Trim(Obj_Dict_Conf("Actual_FileLocation /
Actual_DB"))
varf_Base_FileLocation_DBName = Trim(Obj_Dict_Conf("Baseline_FileLocation /
Baseline_DB"))
varf_ActEnviConf = Trim(Obj_Dict_Conf("Actual Environment") )
varf_ActFileName = Trim(Obj_Dict_Conf("Actual File/Query/Table
Name"))
varf_BaseEnviConf = Trim(Obj_Dict_Conf("Baseline Environment"))
varf_BaseFileName = Trim(Obj_Dict_Conf("Baseline
File/Query/Table Name"))
varf_Filter_Type = Trim(Ucase(Obj_Dict_Conf("Filter_Type")))
varf_Static_Filter = Trim(Obj_Dict_Conf("Static_Filter"))
varf_Dynamic_Filter_set1 =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Dynamic_Filter_set1"))," ,
",",")," ,",","),", ",",")," ","_")
varf_Dynamic_Filter_set2 =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Dynamic_Filter_set2"))," ,
",",")," ,",","),", ",",")," "," ")
varf_Derived_Filter = Trim(Obj_Dict_Conf("Derived_Filter"))
varf_Logical_columns =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Logical_columns"))," , ",","),"
,",","),", ",",")," ","_")
varf_Ignore_columns =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Ignore_columns"))," ,
",",")," ,",","),", ",",")," ","_")
varf_Sorting_columns =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Sorting_columns"))," , ",","),"
,",","),", ",",")," ","_")
varf_PC_trigger_Flag =
Trim(Ucase(Obj_Dict_Conf("PC_trigger_Flag")))
varf_Parent_table_Name = Trim(Obj_Dict_Conf("Parent_table_Name"))
varf_Parenttable_columns =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Parenttable_columns"))," ,
",",")," ,",","),", ",",")," ","_")
varf_Childtable_columns =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Childtable_columns"))," ,
",",")," ,",","),", ",",")," ","_")
varf_ReqColumns_Parent =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("ReqColumns_Parent"))," ,
",",")," ,",","),", ",",")," ","_")
varf_Max_No_Differences = Trim(Obj_Dict_Conf("Max_NoOfDifferences"))
varf_Column_Tolerance = Trim(Obj_Dict_Conf("Column_Tolerance"))
varf_Record_Grouping = Trim(Obj_Dict_Conf("Record_Grouping"))
varf_FixedWidth_Schema = Trim(Obj_Dict_Conf("FixedWidth_Schema"))
varf_Column_validation = Trim(Obj_Dict_Conf("Column_validation"))
varf_Result_Format = Trim(Ucase(Obj_Dict_Conf("Result_Format")))
varf_Extra_Fields =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Extra_Fields"))," ,
",",")," ,",","),", ",",")," ","_")
varf_Result_Location = Trim(Obj_Dict_Conf("Result_Location"))
vSybIQ_JProcLocation = vProjectFdr_Path &
"pTools\DbToFileDataExtract.jar"
varf_CompoLogicalKeys_alias = "vConcLogicalKey"
varf_dummydttype = "DummyDTValue"
varf_CmpTimer_Start = Timer

' initialisation of varialble whose values are constant


varf_TempDB_FdrPath = vComparisonFilesFdr & "temp\"
varf_DiffCnt = 0

' Define the database objects

Set Obj_AdodbConnection = CreateObject("ADODB.Connection")


Set Obj_AdodbConnActual = CreateObject("ADODB.Connection")
Set Obj_AdodbConnBaseline = CreateObject("ADODB.Connection")
Set Obj_RSActual = CreateObject("ADODB.RecordSet")
Set Obj_RSBaseline = CreateObject("ADODB.RecordSet")
Set Obj_RSGeneric = CreateObject("ADODB.RecordSet")
If Obj_AdodbConnection.State = 1 Then Obj_AdodbConnection.close

'==================================================================================
================================
' Extract the Db details from DB_Credentail sheet
If vComparisonType = "TABLE" Then
' Check the db credential sheet exist
' Find the type of environment file to be created - Actual or Baseline
If Instr(1, Ucase(varf_Comparison_Format)," VS ") <= 0 Then
vDBFile_Remarks = " Improper comparison format , no Vs key
available"
vStatus = "FAIL"
Exit Function
End If
If Func_Worksheet_Exist(vTD_DbCrdnSheet, ObjWB_Result) = 1 Then
varf_Actual_Trigger =
Split(Ucase(varf_Comparison_Format),"VS")(0)
varf_Baseline_Trigger =
Split(Ucase(varf_Comparison_Format),"VS")(1)
If Instr(1,varf_Actual_Trigger,"FILE") <= 0 Then
' Establish the Actual DB connection
Call f_GetDBConnectionString(ObjWB_Result,
vTD_DbCrdnSheet, varf_Actual_FileLocation_DBName, varf_ActEnviConf,
varf_ConnString, _

varf_ConnString_Status, varf_ConnString_Remarks )
If Instr(1,varf_ConnString,"SYBASEIQ") <= 0 Then
If varf_ConnString_Status = "PASS" Then
Obj_AdodbConnActual.Open
varf_ConnString
Obj_AdodbConnActual.CommandTimeOut =
3000
Else
' <Issue with connection details of
actual >
' <varf_ConnString_Remarks -
mention the comments in result and log file>
' Execute "End Function"
End if
End If
' Create actual database table into Pipeline delimited
file
If Obj_AdodbConnActual.State = 1 or
Instr(1,varf_ConnString,"SYBASEIQ") > 0 then
vDBFileName = Mid(varf_ScenarioName,1,10) &
"_Actual_" & vStaticTimestamp_DDMMHHMM & ".DAT"
' vComparisonFilesFdr_tmp =
vComparisonFilesFdr
' vComparisonFilesFdr =
"P:\VMDR_Archival_HIVE\"
Call f_CreateDB_to_PipeLineFile
(Obj_AdodbConnActual, Obj_RSGeneric, varf_Actual_Trigger,
varf_Actual_FileLocation_DBName, varf_ActFileName, varf_ConnString,_

varf_Static_Filter, varf_Derived_Filter, Obj_FSO, vComparisonFilesFdr,


vSybIQ_JProcLocation, vDBFileName, vDbFile_Status,vDBFile_Remarks)
If vDbFile_Status = "PASS" Then
varf_ActFileName = vDBFileName
varf_Actual_FileLocation_DBName =
vComparisonFilesFdr
varf_Comparison_Format = "PIPE"
Else
' Unable to generate the file use the
variable vDBFile_Remarks for details
' Exit Function
End If
' vComparisonFilesFdr =
vComparisonFilesFdr_tmp
End if
End If

If Instr(1,varf_Baseline_Trigger,"FILE") <= 0 Then


' Establish the Baseline DB connection
Call f_GetDBConnectionString(ObjWB_Result,
vTD_DbCrdnSheet, varf_Base_FileLocation_DBName, varf_BaseEnviConf, varf_ConnString,
_

varf_ConnString_Status, varf_ConnString_Remarks )
If Instr(1,varf_ConnString,"SYBASEIQ") <= 0 Then
If varf_ConnString_Status = "PASS" Then
Obj_AdodbConnBaseline.Open
varf_ConnString
Obj_AdodbConnBaseline.CommandTimeOut =
3000
Else
' <Issue with connection details of
actual >
' <varf_ConnString_Remarks -
mention the comments in result and log file>
' Execute "End Function"
End if
End If
' Create Baseline database table into Pipeline
delimited file
If Obj_AdodbConnBaseline.State = 1 or
Instr(1,varf_ConnString,"SYBASEIQ") > 0 then
vDBFileName = Mid(varf_ScenarioName,1,10) &
"_Baseline_" & vStaticTimestamp_DDMMHHMM & ".DAT"
' vComparisonFilesFdr_tmp =
vComparisonFilesFdr
' vComparisonFilesFdr =
"P:\VMDR_Archival_HIVE\"
Call f_CreateDB_to_PipeLineFile
(Obj_AdodbConnBaseline,Obj_RSGeneric, varf_Baseline_Trigger,
varf_Base_FileLocation_DBName, varf_BaseFileName, varf_ConnString,_

varf_Static_Filter, varf_Derived_Filter, Obj_FSO, vComparisonFilesFdr,


vSybIQ_JProcLocation, vDBFileName, vDbFile_Status,vDBFile_Remarks)
If vDbFile_Status = "PASS" Then
varf_BaseFileName = vDBFileName
varf_Base_FileLocation_DBName =
vComparisonFilesFdr
varf_Comparison_Format = "PIPE"
Else
' Unable to generate the file use
the variable vDBFile_Remarks for details
' Exit Function
End If
' vComparisonFilesFdr =
vComparisonFilesFdr_tmp
End if
End If
Else
' <if db credential sheet not exist then update the logs and
remarks in result file and terminate the comparison function>
' Execute "End Function"
End If
' All filters are applied while creating the db file
If varf_Filter_Type = "STATIC" and varf_Dynamic_Filter_set2 <> "" and
varf_Dynamic_Filter_set2 <> Empty Then varf_Static_Filter =
varf_Dynamic_Filter_set2
' If varf_Filter_Type = "COMBINED" Then varf_Filter_Type = "DYNAMIC"
' Else
'' <Based on comparison type value it is not FILE and TABLE, so not
able to execute the comparison>
'' Execute "End Function"
End If

'' Validate the actual file exist


If Not Obj_FSO.FileExists(varf_Actual_FileLocation_DBName &
varf_ActFileName ) Then
vStatus = "FAIL"
' <The file path provided in test data file for scenario not exist in the
location>
Exit Function
End If
' Validate the Baseline file exist
If Not Obj_FSO.FileExists(varf_Base_FileLocation_DBName & varf_BaseFileName )
Then
vStatus = "FAIL"
' <The file path provided in test data file for scenario not exist in the
location>
Exit Function
End If

'==================================================================================
===============================
' Change the format of the file if the extension is (.file) in the defined
configuration sheet
' Frame the temp File Names which are under in test
varf_ActFileFormat_Split = Split(varf_ActFileName, ".")
varf_BaseFileFormat_Split = Split(varf_BaseFileName, ".")

If Ubound(varf_ActFileFormat_Split) > 1 Then


If len(varf_ActFileFormat_Split(1)) > 3 or
len(varf_ActFileFormat_Split(1)) < 3 Then
varf_ActFileFormat = "DAT"
Else
varf_ActFileFormat = varf_ActFileFormat_Split(1)
End If
Else
varf_ActFileFormat = varf_ActFileFormat_Split(1)
End If

If Ubound(varf_BaseFileFormat_Split) > 1 Then


If len(varf_BaseFileFormat_Split(1)) > 3 or
len(varf_BaseFileFormat_Split(1)) < 3 Then
varf_BaseFileFormat = "DAT"
Else
varf_BaseFileFormat = varf_BaseFileFormat_Split(1)
End If
Else
varf_BaseFileFormat = varf_BaseFileFormat_Split(1)
End If

varf_ActFileName_Cpy2Local = "Actual_" &


Mid(Trim(varf_ActFileFormat_Split(0)),1,7) & "_Cpy2Loc" & Chr(46) &
Trim(varf_ActFileFormat)
varf_BaseFileName_Cpy2Local = "Baseline_" &
Mid(Trim(varf_BaseFileFormat_Split(0)),1,7) & "_Cpy2Loc" & Chr(46) &
Trim(varf_BaseFileFormat)

varf_ActFileName_DumLineDT = "Actual_" &


Mid(Trim(varf_ActFileFormat_Split(0)),1,7) & "_DumLineDT" & Chr(46) &
Trim(varf_ActFileFormat)
varf_BaseFileName_DumLineDT = "Baseline_" &
Mid(Trim(varf_BaseFileFormat_Split(0)),1,7) & "_DumLineDT" & Chr(46) &
Trim(varf_BaseFileFormat)

varf_ActFileName_FtrFinal = "Actual_" &


Mid(Trim(varf_ActFileFormat_Split(0)),1,7) & "_FtrFinal" & Chr(46) &
Trim(varf_ActFileFormat)
varf_BaseFileName_FtrFinal = "Baseline_" &
Mid(Trim(varf_BaseFileFormat_Split(0)),1,7) & "_FtrFinal" & Chr(46) &
Trim(varf_BaseFileFormat)

'==================================================================================
================================
' Clear the temp folder
Obj_FSO.DeleteFile varf_TempDB_FdrPath & "*", True

'==================================================================================
================================
'Copy the file into temp location -------------- check this required
Obj_FSO.copyFile varf_Actual_FileLocation_DBName & varf_ActFileName,
varf_TempDB_FdrPath & varf_ActFileName_Cpy2Local, True
Obj_FSO.copyFile varf_Base_FileLocation_DBName &
varf_BaseFileName,varf_TempDB_FdrPath & varf_BaseFileName_Cpy2Local, True

'==================================================================================
================================
' Update registry and create test connection string
' varf_Regedit_JetEngine_path =
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\"
varf_Regedit_JetEngine_path =
"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet\4.0\Engines\"

Select Case Trim(Ucase(varf_Comparison_Format))

Case "PIPE"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path & "Text\Format",
"DELIMITED(|)","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\Extensions", "txt,csv,tab,asc,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\DisabledExtensions", "!txt,csv,tab,asc,tmp,htm,html,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\MaxScanRows", 10, "REG_DWORD"
Obj_AdodbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & varf_TempDB_FdrPath & "; Extended Properties =""text;HDR =
YES;FMT=Delimited"""
varf_fileDelimiter = Chr(124)

Case "CAP"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path & "Text\Format",
"DELIMITED(^)","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\Extensions", "txt,csv,tab,asc,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\DisabledExtensions", "!txt,csv,tab,asc,tmp,htm,html,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\MaxScanRows", 10, "REG_DWORD"
Obj_AdodbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & varf_TempDB_FdrPath & "; Extended Properties =""text;HDR =
YES;FMT=Delimited"""
varf_fileDelimiter = Chr(94)

Case "CSV"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path & "Text\Format",
"CSVDelimited","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\Extensions", "txt,csv,tab,asc,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\DisabledExtensions", "!txt,csv,tab,asc,tmp,htm,html,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\MaxScanRows", 10, "REG_DWORD"
Obj_AdodbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & varf_TempDB_FdrPath & "; Extended Properties =""text;HDR =
YES;FMT=Delimited"""
varf_fileDelimiter = Chr(44)

Case "FIXEDWIDTH"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path & "Text\Format",
"FixedLength","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\Extensions", "txt,csv,tab,asc,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\DisabledExtensions", "!txt,csv,tab,asc,tmp,htm,html,dat,ppe","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\MaxScanRows", 10, "REG_DWORD"
Obj_AdodbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & varf_TempDB_FdrPath & "; Extended Properties =""text;HDR =
No;FMT=FixedLength"""
If varf_FixedWidth_Schema <> "" Or varf_FixedWidth_Schema <>
Empty Then
Call vFixedWidth_to_PIPE (varf_FixedWidth_Schema,
Obj_AdodbConnection, varf_ActFileName_Cpy2Local, varf_BaseFileName_Cpy2Local,_

Obj_RSActual,Obj_RSBaseline,varf_TempDB_FdrPath,ObjXL_Main,Obj_FSO,Obj_ExeLog,ObjWB
_Result,vFixedWidth2PIPE_Status)
If vFixedWidth2PIPE_Status = "Pass - PipeLine Created"
Then
If Obj_AdodbConnection.State = 1 Then
Obj_AdodbConnection.Close
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Text\Format", "DELIMITED(|)","REG_SZ"
Obj_AdodbConnection.Open
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & varf_TempDB_FdrPath & _
"; Extended
Properties =""text;HDR = YES;FMT=Delimited"""
varf_fileDelimiter = Chr(124)
Else
' <Exit Function>
' Unable to covert the fixed width file into PIPE line
delimited
End If
Else
' <Exit Function>
' < Format of the file is Fixed Width but schema file is
not available >
End If

Case "EXCEL"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Excel\DisabledExtensions", "!xls","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path &
"Excel\TypeGuessRows", 1000000, "REG_DWORD"
Obj_AdodbConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=" & varf_TempDB_FdrPath & vSourceFileName & _
"; Extended Properties=""Excel 12.0;HDR=YES;
IMEX=2;"""
Obj_AdodbConnection_XL.Open
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & varf_TempDB_FdrPath & "123" &
vSourceFileName & _
"; Extended Properties=""Excel 12.0;HDR=YES;
IMEX=2;"""
vSourceFileName = "[Sheet123$]"

Case Else
' <Terminate the execution if no proper format define in config
sheet>
' Exit Function
End Select

'==================================================================================
================================
' Validate the baseline and actual columns and report the missing columns
against the file
' Create new files with dummy records and relevant columns also adding line
number to the file
' Validate the column mapping sheet

Set ObjRead_ActCpy2Local = Obj_FSO.OpenTextFile( varf_TempDB_FdrPath &


varf_ActFileName_Cpy2Local, 1)
varf_ActColName_DumLineDT = ObjRead_ActCpy2Local.ReadLine
varf_ActColName_DumLineDT =
Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(varf_ActCol
Name_DumLineDT,"
","_"),"/","_Y_"),"#","_Z_"),"*","_W_"),"@","_V_"),Chr(34),""),"?","_U_"),"-","_P_"
),"+","_Q_")
' varf_ActColName_DumLineDT = Replace(varf_ActColName_DumLineDT,
varf_fileDelimiter, "1" & varf_fileDelimiter) & "1"
varf_ActColName_DumLineDT_Split =
Split(varf_ActColName_DumLineDT,varf_fileDelimiter)

Set ObjRead_BaseCpy2Local = Obj_FSO.OpenTextFile( varf_TempDB_FdrPath &


varf_BaseFileName_Cpy2Local, 1)
varf_BaseColName_DumLineDT = ObjRead_BaseCpy2Local.ReadLine
varf_BaseColName_DumLineDT =
Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(Replace(varf_BaseCo
lName_DumLineDT,"
","_"),"/","_Y_"),"#","_Z_"),"*","_W_"),"@","_V_"),Chr(34),""),"?","_U_"),"-","_P_"
),"+","_Q_")
' varf_BaseColName_DumLineDT =
Replace(varf_BaseColName_DumLineDT,varf_fileDelimiter,"1" & varf_fileDelimiter) &
"1"
varf_BaseColName_DumLineDT_Split =
Split(varf_BaseColName_DumLineDT,varf_fileDelimiter)

If varf_Column_validation <> "" Or varf_Column_validation <> Empty Then

Call vColumnValidation_MissDiffExpected
( varf_ActColName_DumLineDT,varf_BaseColName_DumLineDT,varf_Column_validation,ObjXL
_Main,Obj_FSO,Obj_ExeLog,ObjWB_Result,_
varf_diff,
varf_DiffCnt,varf_ActDumyRec_insert,varf_BaseDumyRec_insert, vBaseAttribute_Names,
vColumnVerf_Status)
' varf_ActDumyRec_insert
' varf_BaseDumyRec_insert
' vBaseAttribute_Names
'
Else
vColumnVerf_Status = "Not Found"
End If

' If Column Mapping is empty or if columnverfication is false that it didn't the


sheet the execute the below condition
If vColumnVerf_Status = "Not Found" Or vColumnVerf_Status = False Then
Actfield_Found = Empty
Basefield_Found = Empty
' Find the missing baseline columns
For each Actfields in varf_ActColName_DumLineDT_Split
For each Basefields in varf_BaseColName_DumLineDT_Split
If Ucase(Actfields) = Ucase(Basefields) Then
Actfield_Found = true
Exit For
End If
Next
If Actfield_Found <> true then
ReDim Preserve varf_diff(varf_DiffCnt)
varf_diff(varf_DiffCnt) = "Attribute is Missing" & "^$!"
& "-" & "^$!" & "-" & "^$!" & Actfields & "^$!" & " Present " & "^$!" & " Not
available (Missing) " & "^$!" & "" & "^$!" & ""
varf_DiffCnt = varf_DiffCnt + 1
End If
Actfield_Found = Empty
varf_ActDumyRec_insert = varf_ActDumyRec_insert &
varf_fileDelimiter & varf_dummydttype
Next

' Find the missing Actual columns


For each Basefields in varf_BaseColName_DumLineDT_Split
For each Actfields in varf_ActColName_DumLineDT_Split
If Ucase(Basefields) = Ucase(Actfields) Then
vBaseAttribute_Names = vBaseAttribute_Names &
varf_fileDelimiter & Basefields
Basefield_Found = true
Exit For
End If
Next
If Basefield_Found <> true then
ReDim Preserve varf_diff(varf_DiffCnt)
varf_diff(varf_DiffCnt) = "Attribute is Missing" &
"^$!" & "-" & "^$!" & "-" & "^$!" & Basefields & "^$!" & " Not available (Missing)
" & "^$!" & " Present " & "^$!" & "" & "^$!" & ""
varf_DiffCnt = varf_DiffCnt + 1
End If
Basefield_Found = Empty
varf_BaseDumyRec_insert = varf_BaseDumyRec_insert &
varf_fileDelimiter & varf_dummydttype
Next

varf_ActDumyRec_insert = Mid(varf_ActDumyRec_insert, 2)
varf_BaseDumyRec_insert = Mid(varf_BaseDumyRec_insert, 2)
vBaseAttribute_Names = Mid(vBaseAttribute_Names, 2)
vBaseAttribute_Names = vBaseAttribute_Names & varf_fileDelimiter &
"LineNo"

End If

' Ignore Columns - Remove the columns from Baseline attribute name variable
If varf_Ignore_columns <> "" Or varf_Ignore_columns <> Empty Then
varf_Ignore_columns_split = Split(varf_Ignore_columns,Chr(44))
For vIgnoreColCnt = 0 To Ubound(varf_Ignore_columns_split)
If Instr(1,
vBaseAttribute_Names,varf_Ignore_columns_split(vIgnoreColCnt)) > 0 Then
vBaseAttribute_Names_IGSplit =
Split(vBaseAttribute_Names,varf_fileDelimiter)
vBaseAttribute_Names_IGtemp = Empty
For vBaseAttriCnt = 0 To
Ubound(vBaseAttribute_Names_IGSplit)
If
Trim(varf_Ignore_columns_split(vIgnoreColCnt)) =
Trim(vBaseAttribute_Names_IGSplit(vBaseAttriCnt)) Then
' <The following column will be ignored
while comparison>
Else
vBaseAttribute_Names_IGtemp =
vBaseAttribute_Names_IGtemp & varf_fileDelimiter &
vBaseAttribute_Names_IGSplit(vBaseAttriCnt)
End If
Next
vBaseAttribute_Names =
Mid(vBaseAttribute_Names_IGtemp,Len(varf_fileDelimiter)+1)
End If
Next
vBaseAttribute_Names_IGSplit = Empty
varf_Ignore_columns_split = Empty
vBaseAttribute_Names_IGtemp = Empty
End If

'==================================================================================
================================
' Validate the logical, sorting, filter columns defined in TD configuration
sheet exist in both the tables/files under test
' <if any logical key not exist then exit the function>
' Check the ignored columns should not be part of logical, sorting, dynamic keys
' <Also check parent table/file parent table columns, child table columns and
required columns are exist>
'==================================================================================
================================
' Create the Actual file with dummy records & Line number
Set ObjWrt_ActDumLineDT = Obj_FSO.OpenTextFile( varf_TempDB_FdrPath &
varf_ActFileName_DumLineDT, 2, True)
ObjWrt_ActDumLineDT.WriteLine "LineNo" & varf_fileDelimiter &
varf_ActColName_DumLineDT

varf_ActLineNo = 0
For varf_ActDumInsrtCnt = 1 To 15
ObjWrt_ActDumLineDT.WriteLine ";;" & varf_ActLineNo &
varf_fileDelimiter & Replace(varf_ActDumyRec_insert, varf_dummydttype,
varf_dummydttype & varf_ActDumInsrtCnt)
Next

Do While Not ObjRead_ActCpy2Local.AtEndOfStream


varf_ActLineNo = varf_ActLineNo + 1
''/ start: inserting values column by column to handle issue
vFormated_line = Replace(Replace(Replace(Replace(Replace(";;" &
varf_ActLineNo & varf_fileDelimiter & ObjRead_ActCpy2Local.ReadLine, Chr(10),""),
Chr(13), "")," "," "),"<null>",""),"null","")
vFormated_line_split = Split(vFormated_line,varf_fileDelimiter)
vField_value = Empty
For vColcnt = 0 To ubound(vFormated_line_split)
vdynmic_val = Trim(vFormated_line_split(vColcnt))
If Isnumeric(replace(lcase(vdynmic_val) & "1","d","dd")) and
vdynmic_val <> "" and ucase(Right(vdynmic_val,1)) <> "E" and len(vdynmic_val) > 1
Then vdynmic_val = eval(replace(vdynmic_val,",",""))
vField_value = vField_value & varf_fileDelimiter & vdynmic_val
Next
ObjWrt_ActDumLineDT.writeline
Mid(vField_value,len(varf_fileDelimiter)+1)
'/ end: inserting values column by column to handle issue
' ObjWrt_ActDumLineDT.WriteLine Replace(Replace(Replace(Replace(";;" &
varf_ActLineNo & varf_fileDelimiter & ObjRead_ActCpy2Local.ReadLine, Chr(10),""),
Chr(13), "")," ",""),"null","")
Loop

ObjRead_ActCpy2Local.Close
ObjWrt_ActDumLineDT.Close

'Create the Actual file with dummy records & Line number
Set ObjWrt_BaseDumLineDT = Obj_FSO.OpenTextFile( varf_TempDB_FdrPath &
varf_BaseFileName_DumLineDT, 2, True)
ObjWrt_BaseDumLineDT.WriteLine "LineNo" & varf_fileDelimiter &
varf_BaseColName_DumLineDT

varf_baseLineNo = 0
For varf_BaseDumInsrtCnt = 1 To 15
ObjWrt_BaseDumLineDT.WriteLine ";;" & varf_baseLineNo &
varf_fileDelimiter & Replace(varf_BaseDumyRec_insert, varf_dummydttype,
varf_dummydttype & varf_BaseDumInsrtCnt)
Next

Do While Not ObjRead_BaseCpy2Local.AtEndOfStream


varf_baseLineNo = varf_baseLineNo + 1
''/ start: inserting values column by column to handle issue
vFormated_line = Replace(Replace(Replace(Replace(Replace(";;" &
varf_baseLineNo & varf_fileDelimiter & ObjRead_BaseCpy2Local.ReadLine, Chr(10),""),
Chr(13), "")," "," "),"<null>",""),"null","")
vFormated_line_split = Split(vFormated_line,varf_fileDelimiter)
vField_value = Empty
For vColcnt = 0 To ubound(vFormated_line_split)
vdynmic_val = Trim(vFormated_line_split(vColcnt))
If Isnumeric(replace(lcase(vdynmic_val) & "1","d","dd")) and
vdynmic_val <> "" and ucase(Right(vdynmic_val,1)) <> "E" and len(vdynmic_val) > 1
Then vdynmic_val = eval(replace(vdynmic_val,",",""))
vField_value = vField_value & varf_fileDelimiter & vdynmic_val
Next
ObjWrt_BaseDumLineDT.writeline
Mid(vField_value,len(varf_fileDelimiter)+1)
'/ end: inserting values column by column to handle issue
' ObjWrt_BaseDumLineDT.WriteLine Replace(Replace(Replace(Replace(";;" &
varf_baseLineNo & varf_fileDelimiter & ObjRead_BaseCpy2Local.ReadLine, Chr(10),""),
Chr(13), "")," ",""),"null","")
Loop

ObjRead_BaseCpy2Local.Close
ObjWrt_BaseDumLineDT.Close

'==================================================================================
================================
' Based on Parent join create normal or parent join query builder

If varf_PC_trigger_Flag = "JOIN REQUIRED" Then


If varf_Parent_table_Name <> "" And varf_Parenttable_columns <> ""
And varf_Childtable_columns <> "" And varf_ReqColumns_Parent <> "" Then
If varf_Logical_columns <> "" or varf_Logical_columns <> Empty
Then
varf_BaseAtrriNames_Split = Split(vBaseAttribute_Names,
varf_fileDelimiter)
For varf_BaseattriCnt = 0 To
ubound(varf_BaseAtrriNames_Split)
If Instr(1, Ucase(varf_Logical_columns),
Ucase(varf_BaseAtrriNames_Split(varf_BaseattriCnt))) <= 0 Then
varf_CmpAttriNames_query =
varf_CmpAttriNames_query & Chr(44) & varf_BaseAtrriNames_Split(varf_BaseattriCnt)
varf_CmpAttriNames = varf_CmpAttriNames &
varf_fileDelimiter & varf_BaseAtrriNames_Split(varf_BaseattriCnt)
varf_CmpAttriDummyDT = varf_CmpAttriDummyDT
& varf_fileDelimiter & varf_dummydttype
Else
varf_CompoConcat_LogicalKeys =
varf_CompoConcat_LogicalKeys & " & ';' & " &
varf_BaseAtrriNames_Split(varf_BaseattriCnt)
End If
Next

If varf_CmpAttriNames <> "" Then varf_CmpAttriNames =


Mid(varf_CmpAttriNames,len(varf_fileDelimiter)+1)
If varf_CmpAttriNames_query <> "" Then
varf_CmpAttriNames_query = Mid(varf_CmpAttriNames_query,len(varf_fileDelimiter)+1)
If varf_CmpAttriDummyDT <> "" Then varf_CmpAttriDummyDT
= Mid(varf_CmpAttriDummyDT,len(varf_fileDelimiter)+1)
varf_CmpAttriDummyDT = varf_dummydttype &
varf_fileDelimiter & varf_CmpAttriDummyDT ' including the concatinated
logical keys

varf_ReqColumns_Parent_Split =
Split(varf_ReqColumns_Parent,",")
For vJT_ReqColCnt = 0 to
Ubound(varf_ReqColumns_Parent_Split)
varf_CompoConcat_LogicalKeys =
varf_CompoConcat_LogicalKeys & " & ';' & " &
varf_ReqColumns_Parent_Split(vJT_ReqColCnt)
Next
If varf_CompoConcat_LogicalKeys <> "" Then
varf_CompoConcat_LogicalKeys = Mid(varf_CompoConcat_LogicalKeys,len(" & ';' & ")+1)

varf_FinalAttriNames_query =
varf_CompoConcat_LogicalKeys & " As " & varf_CompoLogicalKeys_alias & Chr(44) &
varf_CmpAttriNames_query
varf_FinalAttriNames = varf_CompoLogicalKeys_alias &
varf_fileDelimiter & varf_CmpAttriNames

varf_Parenttable_columns_Split =
Split(varf_Parenttable_columns,",")
varf_Childtable_columns_Split =
Split(varf_Childtable_columns,",")

For vPrntbl_ColCnt = 0 To
Ubound(varf_Parenttable_columns_Split)
vJoinCol_ParentChild = "parent." &
varf_Parenttable_columns_Split(vPrntbl_ColCnt) & "=child." &
varf_Childtable_columns_Split(vPrntbl_ColCnt)
Next

varf_ActNVL_JoinNormal_Query = "Select " &


varf_FinalAttriNames_query & " from " & varf_ActFileName_DumLineDT & " Child left
outer join" & _

varf_Parent_table_Name & " parent On " & vJoinCol_ParentChild


varf_BaseNVL_JoinNormal_Query = "Select " &
varf_FinalAttriNames_query & " from " & varf_BaseFileName_DumLineDT & " Child left
outer join" & _

varf_Parent_table_Name & " parent On " & vJoinCol_ParentChild

Else
' <Logical Key is empty only required columns as to be
used>

End If
Else
' <Join trigger is selected but >
End If

ElseIf varf_Logical_columns <> "" or varf_Logical_columns <> Empty Then


varf_BaseAtrriNames_Split = Split(vBaseAttribute_Names,
varf_fileDelimiter)
For varf_BaseattriCnt = 0 To ubound(varf_BaseAtrriNames_Split)
If Instr(1, Chr(44) & Replace(Ucase(varf_Logical_columns),"
","") & Chr(44), Chr(44) &
Replace(Ucase(varf_BaseAtrriNames_Split(varf_BaseattriCnt))," ","") & Chr(44)) <= 0
Then
varf_CmpAttriNames_query = varf_CmpAttriNames_query &
Chr(44) & varf_BaseAtrriNames_Split(varf_BaseattriCnt)
varf_CmpAttriNames = varf_CmpAttriNames &
varf_fileDelimiter & varf_BaseAtrriNames_Split(varf_BaseattriCnt)
varf_CmpAttriDummyDT = varf_CmpAttriDummyDT &
varf_fileDelimiter & varf_dummydttype
Else
varf_CompoConcat_LogicalKeys =
varf_CompoConcat_LogicalKeys & " & ';' & " &
varf_BaseAtrriNames_Split(varf_BaseattriCnt)
End If
Next

If varf_CmpAttriNames <> "" Then varf_CmpAttriNames =


Mid(varf_CmpAttriNames,len(varf_fileDelimiter)+1)
If varf_CmpAttriNames_query <> "" Then varf_CmpAttriNames_query =
Mid(varf_CmpAttriNames_query,len(varf_fileDelimiter)+1)
If varf_CompoConcat_LogicalKeys <> "" Then
varf_CompoConcat_LogicalKeys = Mid(varf_CompoConcat_LogicalKeys,len(" & ';' & ")+1)
If varf_CmpAttriDummyDT <> "" Then varf_CmpAttriDummyDT =
Mid(varf_CmpAttriDummyDT,len(varf_fileDelimiter)+1)
varf_CmpAttriDummyDT = varf_dummydttype & varf_fileDelimiter &
varf_CmpAttriDummyDT ' including the concatinated logical
keys

varf_FinalAttriNames_query = varf_CompoConcat_LogicalKeys & " As " &


varf_CompoLogicalKeys_alias & Chr(44) & varf_CmpAttriNames_query
varf_FinalAttriNames = varf_CompoLogicalKeys_alias &
varf_fileDelimiter & varf_CmpAttriNames

varf_ActNVL_JoinNormal_Query = "Select " & varf_FinalAttriNames_query


& " from " & varf_ActFileName_DumLineDT
varf_BaseNVL_JoinNormal_Query = "Select " & varf_FinalAttriNames_query
& " from " & varf_BaseFileName_DumLineDT

Else
varf_FinalAttriNames = vBaseAttribute_Names
varf_FinalAttriNames_query =
Replace(vBaseAttribute_Names,varf_fileDelimiter,Chr(44))
varf_ActNVL_JoinNormal_Query = "Select " & varf_FinalAttriNames_query
& " from " & varf_ActFileName_DumLineDT
varf_BaseNVL_JoinNormal_Query = "Select " & varf_FinalAttriNames_query
& " from " & varf_BaseFileName_DumLineDT
' <Logic has to be implemented for no logical keys, how to handle inner
join, record missing queries and execution>

End If

varf_PrimaryJoin_Mismatch = " Where vMisActual." &


varf_CompoLogicalKeys_alias & " = vMisBaseline." & varf_CompoLogicalKeys_alias
varf_PrimaryJoin_ActRecMissing = " On vMisActual." &
varf_CompoLogicalKeys_alias & " = vMisBaseline." & varf_CompoLogicalKeys_alias & _
" where vMisActual." &
varf_CompoLogicalKeys_alias & " is Null"
varf_PrimaryJoin_BaseRecMissing = " On vMisActual." &
varf_CompoLogicalKeys_alias & " = vMisBaseline." & varf_CompoLogicalKeys_alias & _
" where vMisBaseline." &
varf_CompoLogicalKeys_alias & " is Null"

'==================================================================================
================================================
' Define sort keys for main join query other than logical keys
varf_CmpSortingColumns = Empty
If varf_Logical_columns <> "" or varf_Logical_columns <> Empty Then
If varf_Sorting_columns <> "" or varf_Sorting_columns <> Empty Then
varf_SortCol_Split = Split(varf_Sorting_columns,Chr(44))
For varf_SortCnt = 0 To ubound(varf_SortCol_Split)
If Instr(1, Ucase(varf_Logical_columns),
Ucase(varf_SortCol_Split(varf_SortCnt))) <= 0 Then
varf_CmpSortingColumns = varf_CmpSortingColumns
& Chr(44) & "vMisBaseline." & varf_SortCol_Split(varf_SortCnt)
End If
Next
varf_CmpSortingColumns = " Order By vMisBaseline." &
varf_CompoLogicalKeys_alias & varf_CmpSortingColumns
Else
varf_CmpSortingColumns = " Order By vMisBaseline." &
varf_CompoLogicalKeys_alias
End If
ElseIf varf_Sorting_columns <> "" or varf_Sorting_columns <> Empty Then
varf_SortCol_Split = Split(varf_Sorting_columns,Chr(44))
For varf_SortCnt = 0 To ubound(varf_SortCol_Split)
varf_CmpSortingColumns = varf_CmpSortingColumns & Chr(44) &
"vMisBaseline." & varf_SortCol_Split(varf_SortCnt)
Next
varf_CmpSortingColumns = " Order By " &
Mid(varf_CmpSortingColumns,2)
Else
varf_CmpSortingColumns = " Order By 1,2,3"
End If

'==================================================================================
================================
'3 Define dynamic filters - STATIC / DYNAMIC / COMBINED

If (varf_Filter_Type <> "" Or varf_Filter_Type <> Empty Or varf_Filter_Type <>


"NA" ) And (Not Obj_FSO.FileExists(varf_FilterFile_path)) Then
varf_DynamicFilterCnt = 0
Select Case varf_Filter_Type
Case "STATIC"
ReDim Preserve varrFilters(0)
varrFilters(0) = varf_Static_Filter
Case "DYNAMIC"
If varf_Dynamic_Filter_set1 <> "" Or
varf_Dynamic_Filter_set1 <> Empty Then
varf_DynamicFilterCnt =
f_GetDynamicFilters(Obj_Dict_Conf,Obj_AdodbConnection,varf_ActFileName_DumLineDT,
varf_BaseFileName_DumLineDT, _

varrFilters,vFilter_OutOfRange,vNoOfRec_PerDynFilter,varf_dummydttype)

If varf_DynamicFilterCnt = 0 Then
ReDim Preserve
varrFilters(varf_DynamicFilterCnt)
varrFilters(varf_DynamicFilterCnt) = ""
End If
Else
' <Warning:= Filter is Dynamic but no attribute is
defined in the field and so no filter is used>
ReDim Preserve varrFilters(0)
varrFilters(0) =""
varf_DataFilterValue = ""
End If
Case "COMBINED"
If varf_Dynamic_Filter_set1 <> "" Or
varf_Dynamic_Filter_set1 <> Empty Then
varf_DynamicFilterCnt =
f_GetDynamicFilters(Obj_Dict_Conf,Obj_AdodbConnection,varf_ActFileName_DumLineDT,
varf_BaseFileName_DumLineDT, _

varrFilters,vFilter_OutOfRange,vNoOfRec_PerDynFilter,varf_dummydttype)
End If
If varf_DynamicFilterCnt = 0 Then
ReDim Preserve varrFilters(varf_DynamicFilterCnt)
varrFilters(varf_DynamicFilterCnt) = ""
End If
For vCtr =0 To Ubound(varrFilters)
If Cbool(varf_Static_Filter & "!@#$" <> "!@#$" ) =
True Then
If Cbool(varrFilters(vCtr) & "!@#$" <> "!
@#$" ) = True Then
varrFilters(vCtr) =
varrFilters(vCtr) & " And " & varf_Static_Filter
Else
varrFilters(vCtr) =
varf_Static_Filter
End If
End If
Next
Case Else
ReDim Preserve varrFilters(0)
varrFilters(0) =""
varf_DataFilterValue = ""
End Select

Else
ReDim Preserve varrFilters(0)
varrFilters(0) =""
varf_DataFilterValue = ""
End If

' Create filter.txt file

If Not Obj_FSO.FileExists(varf_FilterFile_path) Then


Set ObjWrite_FilterFile =
Obj_Fso.OpenTextFile(varf_FilterFile_path,2,True)
For varf_VarrFilterCnt = 0 To Ubound(varrFilters)
ObjWrite_FilterFile.WriteLine (varf_VarrFilterCnt & "|!#" &
varrFilters(varf_VarrFilterCnt))
Next
ObjWrite_FilterFile.Close
End If

Set ObjRead_FilterFile = Obj_Fso.OpenTextFile(varf_FilterFile_path,1)


Do Until ObjRead_FilterFile.AtEndOfStream
vCmpFilterValue_Split = Split(ObjRead_FilterFile.ReadLine,"|!#")

If vCmpFilterValue_Split(0) <> "" or vCmpFilterValue_Split(0) <> Empty


Then
If vCmpFilterValue_Split(1) <> "" Or vCmpFilterValue_Split(1) <>
Empty Then
varf_FilterintoQuery = " where " &
vCmpFilterValue_Split(1)
Else
varf_FilterintoQuery = ""
End If
Else
varf_FilterintoQuery = ""
End If

'==================================================================================
================================================
' Create new file with filter data and composite logical key
' Also extract the total number of records baseline and actual

varf_ActFilterNVL_Query = varf_ActNVL_JoinNormal_Query &


varf_FilterintoQuery
Set ObjWrt_ActFilterNVL = Obj_FSO.OpenTextFile(varf_TempDB_FdrPath &
varf_ActFileName_FtrFinal, 2, True)
Obj_RSActual.Open varf_ActFilterNVL_Query, Obj_AdodbConnection,1,3
ObjWrt_ActFilterNVL.Writeline varf_FinalAttriNames
varf_Actual_TotalNumberRec = 0
If varf_FilterintoQuery <> "" Or varf_FilterintoQuery <> Empty Then
For varf_dummyctr = 0 To 15
ObjWrt_ActFilterNVL.Writeline
Replace(varf_CmpAttriDummyDT,varf_dummydttype, varf_dummydttype & varf_dummyctr)
Next
End If
Do until Obj_RSActual.EOF
ObjWrt_ActFilterNVL.writeline
Replace(Obj_RSActual.GetString(2,1,varf_fileDelimiter,""),Chr(13),"")
varf_Actual_TotalNumberRec = varf_Actual_TotalNumberRec + 1
Loop
If varf_Actual_TotalNumberRec <> 0 and varf_FilterintoQuery="" then
varf_Actual_TotalNumberRec = varf_Actual_TotalNumberRec - 15
If Obj_RSActual.State = 1 Then Obj_RSActual.Close
ObjWrt_ActFilterNVL.close

varf_BaseFilterNVL_Query = varf_BaseNVL_JoinNormal_Query &


varf_FilterintoQuery
Set ObjWrt_BaseFilterNVL = Obj_FSO.OpenTextFile(varf_TempDB_FdrPath &
varf_BaseFileName_FtrFinal, 2, True)
Obj_RSBaseline.Open varf_BaseFilterNVL_Query, Obj_AdodbConnection,1,3
ObjWrt_BaseFilterNVL.Writeline varf_FinalAttriNames
varf_Baseline_TotalNumberRec = 0
If varf_FilterintoQuery <> "" Or varf_FilterintoQuery <> Empty Then
For varf_dummyctr = 0 To 15
ObjWrt_BaseFilterNVL.Writeline
Replace(varf_CmpAttriDummyDT,varf_dummydttype, varf_dummydttype & varf_dummyctr)
Next
End If
Do until Obj_RSBaseline.EOF
ObjWrt_BaseFilterNVL.writeline
Replace(Obj_RSBaseline.GetString(2,1,varf_fileDelimiter,""),Chr(13),"")
varf_Baseline_TotalNumberRec = varf_Baseline_TotalNumberRec + 1
Loop
If varf_Baseline_TotalNumberRec <> 0 and varf_FilterintoQuery="" then
varf_Baseline_TotalNumberRec = varf_Baseline_TotalNumberRec - 15
If Obj_RSBaseline.State = 1 Then Obj_RSBaseline.Close
ObjWrt_BaseFilterNVL.Close

'==================================================================================
================================================
' Define a command for maximum no of differences
Varf_CmdCond_MaxNoDiff = ""
If varf_Max_No_Differences <> "" Then Varf_CmdCond_MaxNoDiff = "If
Cint(varf_DiffCnt) >= Cint(varf_Max_No_Differences) Then varf_MaxNoDiff_trigger =
True"

'==================================================================================
================================================
' Inner join to find the mismatch in field values

varf_MismatchQuery_Actual = "Select vMisActual.* from " &


varf_BaseFileName_FtrFinal & " vMisBaseline, " & varf_ActFileName_FtrFinal & _
" vMisActual " &
varf_PrimaryJoin_Mismatch & varf_CmpSortingColumns
Obj_RSActual.Open varf_MismatchQuery_Actual, Obj_AdodbConnection,1,3

varf_MismatchQuery_Baseline = "Select vMisbaseline.* from " &


varf_BaseFileName_FtrFinal & " vMisBaseline, " & varf_ActFileName_FtrFinal & _
" vMisActual " &
varf_PrimaryJoin_Mismatch & varf_CmpSortingColumns
Obj_RSBaseline.Open varf_MismatchQuery_Baseline,
Obj_AdodbConnection,1,3

' Obj_RSActual.RecordCount
' Obj_RSActual.AbsolutePosition

varf_CmpAttriNames_Split =
Split(Replace(varf_CmpAttriNames,varf_fileDelimiter & "LineNo",
""),varf_fileDelimiter)

varf_DistinctFieldsMismatch = ""
varf_tempvalue = "!@$&"
varf_DistinctRecordsMismatch = 0
varf_MaxNoDiff_trigger = False
vExtraFields_Baseline_value = ""
vExtraFields_Actual_value = ""
vExtraFields_Baseline_query = ""
vExtraFields_Actual_query = ""
vExtraFields_Baseline_Execute = ""
vExtraFields_Actual_Execute = ""

If varf_Extra_Fields <> Empty Or varf_Extra_Fields <> "" Then


varf_Extra_Fields_split = Split(varf_Extra_Fields,Chr(44))
For ExFlds_Cnt = 0 to
Ubound(varf_Extra_Fields_split)
vExecute = "v" &
varf_Extra_Fields_split(ExFlds_Cnt) & " = " & Chr(34) &
varf_Extra_Fields_split(ExFlds_Cnt) & Chr(34)
Execute vExecute
vExtraFields_Baseline_query =
vExtraFields_Baseline_query & Chr(34) & ";" & Chr(34) & " &
Obj_RSBaseline.Fields(" & "v" & varf_Extra_Fields_split(ExFlds_Cnt) & ").Value & "
vExtraFields_Actual_query =
vExtraFields_Actual_query & Chr(34) & ";" & Chr(34) & " & Obj_RSActual.Fields(" &
"v" & varf_Extra_Fields_split(ExFlds_Cnt) & ").Value & "
Next
vExtraFields_Baseline_query = Mid
(vExtraFields_Baseline_query,7,len(vExtraFields_Baseline_query)-8)
vExtraFields_Actual_query = Mid
(vExtraFields_Actual_query,7, len(vExtraFields_Actual_query)-8)
vExtraFields_Baseline_Execute = "vExtraFields_Baseline_value
= " & vExtraFields_Baseline_query
vExtraFields_Actual_Execute = "vExtraFields_Actual_value = "
& vExtraFields_Actual_query
End If

Do Until Obj_RSActual.EOF Or Obj_RSBaseline.EOF Or


varf_MaxNoDiff_trigger
varf_ActualRowValue =
Split(Replace(Obj_RSActual.GetString(2,1,varf_fileDelimiter,""),Chr(13),""),varf_fi
leDelimiter & ";;")(0)
varf_BaselineRowValue =
Split(Replace(Obj_RSBaseline.GetString(2,1,varf_fileDelimiter,""),Chr(13),""),varf_
fileDelimiter & ";;")(0)
If StrComp(varf_ActualRowValue, varf_BaselineRowValue,1) <> 0
Then
Obj_RSActual.MovePrevious
Obj_RSBaseline.MovePrevious
varf_PrimaryKeyValue =
Obj_RSBaseline.Fields(varf_CompoLogicalKeys_alias).Value
For varf_RSFieldCnt = 0 To
Ubound(varf_CmpAttriNames_Split)
varf_ActualFieldValue =
Obj_RSActual.Fields(Trim(varf_CmpAttriNames_Split(varf_RSFieldCnt))).Value
varf_BaselineFieldValue =
Obj_RSBaseline.Fields(Trim(varf_CmpAttriNames_Split(varf_RSFieldCnt))).Value
If StrComp("1" & varf_ActualFieldValue, "1" &
varf_BaselineFieldValue, 1) <> 0 Then
' If
ISNumeric(varf_ActualFieldValue) and IsNumeric(varf_BaselineFieldValue) Then
' If StrComp("1" &
EVAL(varf_ActualFieldValue), "1" & EVAL(varf_BaselineFieldValue), 1) <> 0 Then
'
varf_FieldName = Trim(varf_CmpAttriNames_Split(varf_RSFieldCnt))
' ReDim
Preserve varf_diff(varf_DiffCnt)
' Execute
vExtraFields_Baseline_Execute
'
varf_diff(varf_DiffCnt) = varf_PrimaryKeyValue & "^$!" &
Replace(Obj_RSActual.Fields("LineNo").Value,";;","") & "^$!" &
Replace(Obj_RSBaseline.Fields("LineNo").Value,";;","") & _
'
"^$!" & varf_FieldName & "^$!" & varf_ActualFieldValue & "^$!" &
varf_BaselineFieldValue & "^$!" & "" & "^$!" & vExtraFields_Baseline_value
' varf_DiffCnt
= varf_DiffCnt + 1
' If Instr(1,
varf_DistinctFieldsMismatch, varf_FieldName)<=0 Then varf_DistinctFieldsMismatch =
varf_DistinctFieldsMismatch & varf_FieldName & "|"
' End
If
' Else
varf_FieldName =
Trim(varf_CmpAttriNames_Split(varf_RSFieldCnt))
ReDim Preserve
varf_diff(varf_DiffCnt)
Execute
vExtraFields_Baseline_Execute
varf_diff(varf_DiffCnt) =
varf_PrimaryKeyValue & "^$!" & Replace(Obj_RSActual.Fields("LineNo").Value,";;","")
& "^$!" & Replace(Obj_RSBaseline.Fields("LineNo").Value,";;","") & _

"^$!" &
Replace(Replace(Replace(Replace(Replace(Replace(Replace(varf_FieldName,"_Y_","/"),"
_Z_","#"),"_W_","*"),"_V_","@"),"_U_","?"),"_P_","-"),"_Q_","+") & _

"^$!" & varf_ActualFieldValue & "^$!" & varf_BaselineFieldValue & "^$!" & "" &
"^$!" & vExtraFields_Baseline_value
varf_DiffCnt = varf_DiffCnt + 1
If Instr(1,
varf_DistinctFieldsMismatch, varf_FieldName)<=0 Then varf_DistinctFieldsMismatch =
varf_DistinctFieldsMismatch & varf_FieldName & "|"
' End If
End If
Next
varf_DistinctRecordsMismatch =
varf_DistinctRecordsMismatch + 1
vExtraFields_Baseline_value = empty
Obj_RSActual.MoveNext
Obj_RSBaseline.MoveNext
End If
Execute Varf_CmdCond_MaxNoDiff
Loop
If varf_DistinctFieldsMismatch <> "" Then varf_DistinctFieldsMismatch
= Mid (varf_DistinctFieldsMismatch, 1, len(varf_DistinctFieldsMismatch)-1)
If Obj_RSActual.State = 1 Then Obj_RSActual.Close
If Obj_RSBaseline.State = 1 Then Obj_RSBaseline.Close

'==================================================================================
================================================
' Record missing in ACTUAL
varf_RecordMissingQuery_Actual = "Select vMisBaseline.* from " &
varf_BaseFileName_FtrFinal & " vMisBaseline Left Outer Join " & _
varf_ActFileName_FtrFinal & "
vMisActual " & varf_PrimaryJoin_ActRecMissing
Obj_RSActual.Open varf_RecordMissingQuery_Actual,
Obj_AdodbConnection,1,3
If Obj_RSActual.EOF <> True Then
varf_MissRecord_Actual = Obj_RSActual.RecordCount
Do Until Obj_RSActual.EOF Or varf_MaxNoDiff_trigger
varf_PrimaryKeyValue =
Obj_RSActual.Fields(varf_CompoLogicalKeys_alias).Value
Execute vExtraFields_Actual_Execute
ReDim Preserve varf_diff(varf_DiffCnt)
varf_diff(varf_DiffCnt) = varf_PrimaryKeyValue & "^$!" &
" - " & "^$!" & Replace(Obj_RSActual.Fields("LineNo").Value,";;","") & _
"^$!" & "Record Missing" & "^$!" & "Not Found" & "^$!" & "Found" & "^$!" &
varf_FilterintoQuery & "^$!" & vExtraFields_Baseline_value
varf_DiffCnt = varf_DiffCnt + 1
Obj_RSActual.MoveNext
vExtraFields_Actual_value = Empty
Execute Varf_CmdCond_MaxNoDiff
Loop
Else
varf_MissRecord_Actual = 0
End If
If Obj_RSActual.State = 1 Then Obj_RSActual.Close

'==================================================================================
================================================
'9 Record missing in BASELINE
varf_RecordMissingQuery_Baseline = "Select vMisActual.* from " &
varf_BaseFileName_FtrFinal & " vMisBaseline Right Outer Join " & _
varf_ActFileName_FtrFinal &
" vMisActual " & varf_PrimaryJoin_BaseRecMissing
Obj_RSBaseline.Open varf_RecordMissingQuery_Baseline,
Obj_AdodbConnection,1,3
If Obj_RSBaseline.EOF <> True Then
varf_MissRecord_Baseline = Obj_RSBaseline.RecordCount
Do Until Obj_RSBaseline.EOF Or varf_MaxNoDiff_trigger
varf_PrimaryKeyValue =
Obj_RSBaseline.Fields(varf_CompoLogicalKeys_alias).Value
Execute vExtraFields_Baseline_Execute
ReDim Preserve varf_diff(varf_DiffCnt)
varf_diff(varf_DiffCnt) = varf_PrimaryKeyValue & "^$!" &
Replace(Obj_RSBaseline.Fields("LineNo").Value,";;","") & "^$!" & " - " & _

"^$!" & "Record Missing" & "^$!" & "Found" & "^$!" & "Not Found" & "^$!" &
varf_FilterintoQuery & "^$!" & vExtraFields_Baseline_value
varf_DiffCnt = varf_DiffCnt + 1
Obj_RSBaseline.MoveNext
Execute Varf_CmdCond_MaxNoDiff
Loop
Else
varf_MissRecord_Baseline = 0
End If
If Obj_RSBaseline.State = 1 Then Obj_RSBaseline.Close

'==================================================================================
================================================
' Report the difference report into temp

If varf_DiffCnt > 0 Then


Select Case varf_Result_Format
Case "EXCEL","EMAIL, EXCEL"

Call
f_DifferenceReporting_Excel(varf_Extra_Fields, varf_Logical_columns, varf_diff,
varf_ScenarioName,vDiffSheetName, Obj_ExeLog, ObjWB_Result,
vDiffReportExcel_Status)
varf_ResultFileName_SummaryReport = vResultFdr &
vTDResult_FileName
Case "CSV","EMAIL, CSV"

Call f_DifferenceReporting_CSV(varf_Extra_Fields,
varf_Logical_columns, varf_diff, vDiffSheetName, Obj_FSO, Obj_ExeLog, ObjWB_Result,
_

varf_CompoConcat_LogicalKeys, vResultFdr, vTDResult_FileName,


vDiffReportExcel_Status)
varf_ResultFileName_SummaryReport = vResultFdr &
Replace(vTDResult_FileName,".xlsx",".csv")

Case "HTML","EMAIL, HTML"


Call
f_DifferenceReporting_HTML(varf_Logical_columns, varf_diff, vDiffSheetName,
Obj_FSO, Obj_ExeLog, ObjWB_Result, vDiffReportExcel_Status)

Case "XML","EMAIL, XML"


Call
f_DifferenceReporting_XML(varf_Logical_columns, varf_diff, vDiffSheetName,
Obj_ExeLog, ObjWB_Result, vDiffReportExcel_Status)

Case Else
Call
f_DifferenceReporting_Excel(varf_Extra_Fields, varf_Logical_columns, varf_diff,
varf_ScenarioName,vDiffSheetName, Obj_ExeLog, ObjWB_Result,
vDiffReportExcel_Status)

End Select
vStatus = "FAIL"
End If
If vStatus = "" Then vStatus = "PASS"
varf_Final_Actual_TotalNumberRec =
varf_Final_Actual_TotalNumberRec + varf_Actual_TotalNumberRec
varf_Final_Baseline_TotalNumberRec =
varf_Final_Baseline_TotalNumberRec + varf_Baseline_TotalNumberRec
varf_Final_MissRecord_Actual = varf_Final_MissRecord_Actual +
varf_MissRecord_Actual
varf_Final_MissRecord_Baseline = varf_Final_MissRecord_Baseline
+ varf_MissRecord_Baseline
varf_Final_DistinctRecordsMismatch =
varf_Final_DistinctRecordsMismatch + varf_DistinctRecordsMismatch
If varf_DistinctFieldsMismatch <> "" Then
varf_DistinctFieldsMismatch_split =
Split(varf_DistinctFieldsMismatch,"|")
For VDisntFldCnt = 0 To
Ubound(varf_DistinctFieldsMismatch_split)
If Instr(1, varf_Final_DistinctFieldsMismatch,
Trim(varf_DistinctFieldsMismatch_split(VDisntFldCnt)))<=0 Then
varf_Final_DistinctFieldsMismatch =
varf_Final_DistinctFieldsMismatch & "|" & _

Trim(varf_DistinctFieldsMismatch_split(VDisntFldCnt)) & "|"


End If
Next
End If
varf_TotalDiffCnt = varf_TotalDiffCnt + varf_DiffCnt
Redim varf_diff(0)
varf_DiffCnt = 0
varf_Actual_TotalNumberRec = 0
varf_Baseline_TotalNumberRec = 0
varf_MissRecord_Actual = 0
varf_MissRecord_Baseline = 0
varf_DistinctRecordsMismatch = 0
varf_DistinctFieldsMismatch = ""
Loop

ObjRead_FilterFile.Close
If vStatus <> "FAIL" Then vStatus = "PASS"
If Obj_FSO.FileExists(varf_FilterFile_path) Then Obj_FSO.DeleteFile
varf_FilterFile_path
'==================================================================================
================================================
' Final difference report adding temp results

vRowNo_ResSum = 1
If Not Obj_FSO.FileExists(vResultFdr & vResSummary_FileName & ".xlsx") Then
Obj_FSO.CopyFile vSmplResSumry_Path, vResultFdr & vResSummary_FileName & ".xlsx",
True
Set ObjWB_ResultSummary = ObjXL_Main.WorkBooks.Open(vResultFdr &
vResSummary_FileName & ".xlsx")
Set ObjWS_ResultSummary =
ObjWB_ResultSummary.WorkSheets(vResSummary_SheetName)
vTotRow_ResultSummary = Cint(ObjWS_ResultSummary.UsedRange.Rows.Count)
vTotCol_ResultSummary = Cint(ObjWS_ResultSummary.UsedRange.Columns.Count)
vResSummary_ScenarioName_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("ScenarioName").Column
vResSummary_BaselineName_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Baseline_FileName / Baseline_TableName").Column
vResSummary_Status_ColNo = ObjWS_ResultSummary.Range("A" & vRowNo_ResSum &
":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Status").Column
vResSummary_TotNoRecords_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Total No. of Records Actual / Baseline").Column


vResSummary_TotRecMissing_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Total No. of Rec Missing in Actl/Bslne").Column


vResSummary_TotRecMissmatches_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Total No. of Distinct Records Mismatch").Column


vResSummary_TotColumnsmatches_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Distinct Unmatch Fields").Column


vResSummary_CmpTime_ColNo = ObjWS_ResultSummary.Range("A" & vRowNo_ResSum &
":" & Chr(vTotCol_ResultSummary +64 ) & _

vRowNo_ResSum).Find("Comparison_Time").Column
vResSummary_DetailedDiffLoc_ColNo = ObjWS_ResultSummary.Range("A" &
vRowNo_ResSum & ":" & Chr(vTotCol_ResultSummary +64 ) & _
vRowNo_ResSum).Find("Detailed difference location").Column

ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_ScenarioName_ColNo ) = varf_ScenarioName
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_BaselineName_ColNo ) = varf_BaseFileName
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1, vResSummary_Status_ColNo )
= vStatus
If StrComp(UCase(vStatus), "PASS",1) = 0 Then
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_Status_ColNo ).Interior.ColorIndex = 50
ElseIf StrComp(UCase(vStatus), "FAIL",1) = 0 Then
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_Status_ColNo ).Interior.ColorIndex = 3
End If
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_TotNoRecords_ColNo ) = varf_Final_Actual_TotalNumberRec & " / "
&varf_Final_Baseline_TotalNumberRec
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_TotRecMissing_ColNo ) = varf_Final_MissRecord_Actual & " / " &
varf_Final_MissRecord_Baseline
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_TotRecMissmatches_ColNo ) = varf_Final_DistinctRecordsMismatch
If varf_Final_DistinctFieldsMismatch = "" then
varf_Final_DistinctFieldsMismatch = " --- "
Else
varf_Final_DistinctFieldsMismatch =
Replace(Mid(varf_Final_DistinctFieldsMismatch,1,1),"|","") &
Mid(varf_Final_DistinctFieldsMismatch,2)
varf_length_FDFM = len(varf_Final_DistinctFieldsMismatch)
varf_Final_DistinctFieldsMismatch =
Mid(varf_Final_DistinctFieldsMismatch,1,varf_length_FDFM-1) &
Replace(Mid(varf_Final_DistinctFieldsMismatch,varf_length_FDFM),"|","")
End If
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1,
vResSummary_TotColumnsmatches_ColNo ) =
Replace(varf_Final_DistinctFieldsMismatch,"||","|")
varf_CmpTimer_End = Round((Timer - varf_CmpTimer_Start),0)
If varf_CmpTimer_End>= 3600 Then
varf_CmpTimer_End = (varf_CmpTimer_End\3600) & "hr " &
((varf_CmpTimer_End mod 3600)\60) & "min"
ElseIf varf_CmpTimer_End>=60 Then
varf_CmpTimer_End = (varf_CmpTimer_End\60) & "min " &
(varf_CmpTimer_End mod 60) & "sec"
Else
varf_CmpTimer_End = varf_CmpTimer_End & " sec"
End If
ObjWS_ResultSummary.Cells(vTotRow_ResultSummary+1, vResSummary_CmpTime_ColNo )
= varf_CmpTimer_End
If varf_TotalDiffCnt > 0 then
ObjWS_ResultSummary.Hyperlinks.add
ObjWS_ResultSummary.Range(Chr(vTotCol_ResultSummary + 64) & vTotRow_ResultSummary +
1), _

varf_ResultFileName_SummaryReport,,,vTDResult_FileName
End If
ObjWS_ResultSummary.Range("A1:" & Chr(vTotCol_ResultSummary +64 ) &
vTotRow_ResultSummary+1).Borders.LineStyle = xlContinuous
ObjWS_ResultSummary.Range("A1:" & Chr(vTotCol_ResultSummary +64 ) &
vTotRow_ResultSummary+1).Borders.color = vbBlack

ObjWB_ResultSummary.Save
ObjWB_ResultSummary.Close

'==================================================================================
================================================

If Obj_AdodbConnection.State = 1 Then Obj_AdodbConnection.Close


If Obj_AdodbConnActual.State = 1 Then Obj_AdodbConnActual.Close
If Obj_AdodbConnBaseline.State = 1 Then Obj_AdodbConnBaseline.Close
If Obj_RSActual.State = 1 Then Obj_RSActual.Close
If Obj_RSBaseline.State = 1 Then Obj_RSBaseline.Close
If Obj_RSGeneric.State = 1 Then Obj_RSGeneric.Close

'==================================================================================
================================================
' Clear the temp folder
Obj_FSO.DeleteFile varf_TempDB_FdrPath & "*", True

'==================================================================================
================================================
Set Obj_AdodbConnection = Nothing
Set Obj_AdodbConnActual = Nothing
Set Obj_AdodbConnBaseline = Nothing
Set Obj_RSActual = Nothing
Set Obj_RSBaseline = Nothing
Set Obj_RSGeneric = Nothing

End Function
'==================================== End Function
==========================================

Public Function f_GetDBConnectionString(ObjWB_Result, vTD_DbCrdnSheet, varf_DBName,


varf_EnviConf, varf_ConnString, varf_ConnString_Status, varf_ConnString_Remarks )

' Initialisation of variables


vDBCred_Header = 1
varf_ConnString = Empty
varf_ConnString_Status = Empty
varf_ConnString_Remarks = Empty

Set ObjWS_DBCredentials = ObjWB_Result.Worksheets(vTD_DbCrdnSheet)


vTotRow_DBCred = CInt(ObjWS_DBCredentials.UsedRange.Rows.count)
vTotCol_DBCred = CInt(ObjWS_DBCredentials.UsedRange.Columns.count)

varf_Environment_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &


":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("Environment").Column
varf_Database_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("Database").Column
varf_DBMS_Type_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("DBMS_Type").Column
varf_Provider_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("Provider").Column
varf_Host_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("Host").Column
varf_Port_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("Port").Column
varf_DataSource_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("DataSource").Column
varf_Schema_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("Schema").Column
varf_DB_UserName_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("DB_UserName").Column
varf_DB_Password_ColNo = ObjWS_DBCredentials.Range("A" & vDBCred_Header &
":" & Chr(64+vTotCol_DBCred) & vDBCred_Header).Find("DB_Password").Column

For varf_DBRowCnt = 3 To vTotRow_DBCred

varf_Cred_Environment =
Ucase(Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_Environment_ColNo)))
varf_Cred_DBName =
Ucase(Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_Database_ColNo)))

If varf_Cred_DBName = Ucase(varf_DBName) AND varf_Cred_Environment =


Ucase(varf_EnviConf) Then

varf_DBMS_Type =
Ucase(Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_DBMS_Type_ColNo)))
varf_DBCred_Provider =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_Provider_ColNo))
varf_Host =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_Host_ColNo))
varf_port =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_Port_ColNo))
varf_DataSource =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_DataSource_ColNo))
varf_Schema =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_Schema_ColNo))
varf_DB_UserName =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_DB_UserName_ColNo))
varf_DB_Password =
Trim(ObjWS_DBCredentials.Cells(varf_DBRowCnt, varf_DB_Password_ColNo))

Select Case varf_DBMS_Type


Case "MYSQL"
varf_ConnString = "Provider=" & varf_DBCred_Provider
& ";Data Source=" & varf_DataSource & ";User ID=" & varf_DB_UserName & ";Password="
& varf_DB_Password & ";"
Case "SYBASEIQ"
varf_ConnString = "SYBASEIQ :: " & varf_Host &
Chr(32) & varf_port & Chr(32) & varf_DB_UserName & Chr(32) & varf_DB_Password
Case "SYBASEASE"
varf_ConnString = "Provider=" & varf_DBCred_Provider
& ";Data Source=" & varf_DataSource & ";User ID=" & varf_DB_UserName & ";Password="
& varf_DB_Password & ";"
Case "ORACLE"
varf_ConnString = "Provider=" & varf_DBCred_Provider
& ";Data Source=" & varf_DataSource & ";User ID=" & varf_DB_UserName & ";Password="
& varf_DB_Password & ";"
Case "MSACCESS"
varf_ConnString = "Provider=" & varf_DBCred_Provider
& ";Data Source=" & varf_DataSource & ";User ID=" & varf_DB_UserName & ";Password="
& varf_DB_Password & ";"
Case Else
varf_ConnString_Remarks = "DBMS type is not
available execution can't proceed"
Exit For
End Select

varf_ConnString_Status = "PASS"
Exit For

End If
Next

If varf_ConnString_Status <> "PASS" Then varf_ConnString_Remarks =


varf_ConnString_Remarks & Chr(10) & " The details in DB credential sheet not match
with the main sheet "

End Function
'==================================== End Function
==========================================

Public Function f_CreateDB_to_PipeLineFile(Obj_AdodbConnGen, Obj_RSGeneric,


varf_Type_Trigger, varf_GenFileLocation_DBName, varf_GenFileName, varf_ConnString,_

varf_Static_Filter, varf_Derived_Filter, Obj_FSO, vComparisonFilesFdr,


vSybIQ_JProcLocation, vDBFileName, vDbFile_Status,vDBFile_Remarks)
' Initialisation of variables
vDbFile_Status = Empty
vDBFile_Remarks = Empty

'Defining the class objects FSO, Wscript, Excel, Dictionary


Set ObjWsh_SybaseQuery = CreateObject("Wscript.Shell")
' Set Obj_RSGeneric = CreateObject("ADODB.RecordSet")
' Set Obj_FSO = CreateObject("Scripting.FileSystemObject")

' Determine the type of trigger for creating the file Query or table or already
file is available
If Instr(1,Ucase(varf_Type_Trigger),"QUERY") > 0 Then
If Obj_FSO.FileExists (varf_GenFileName) Then
Set Obj_QueryRead = Obj_FSO.OpenTextFile(varf_GenFileName,1)
varf_QuerytoExtract =
Replace(Replace(Trim(Replace(Obj_QueryRead.ReadAll," "," ")),Chr(10),"
"),Chr(13)," ")
Obj_QueryRead.Close
Else
vDBFile_Remarks = " Script unable to find the file in the
location - " & varf_GenFile_DB_Query_Location & varf_GenFileName
vDbFile_Status = "FAIL"
Exit Function
End If
ElseIf Instr(1,Ucase(varf_Type_Trigger),"TABLE") > 0 Then
'If varf_Static_Filter <> Empty Or varf_Static_Filter <> "" Then
varf_Static_Filter_Query = " Where " & varf_Static_Filter
varf_QuerytoExtract = "Select * from " & varf_GenFileLocation_DBName
& "." & varf_GenFileName '& varf_Static_Filter_Query
Else
vDBFile_Remarks = " Improper comparison format , not file/query/table
found in the key"
vDbFile_Status = "FAIL"
Exit Function
End If

' Create the Pipe line delimited file from the query available or from direct table
If varf_QuerytoExtract <> Empty Or varf_QuerytoExtract <> "" Then
If varf_Static_Filter <> "" or varf_Static_Filter <> Empty
Then
varf_QuerytoExtract =
Replace(Split(Split(Split(Split(varf_QuerytoExtract,"order by")(0),"ORDER BY")
(0),"Order by")(0),"Order By")(0),";","")
If Instr(1, Ucase(varf_QuerytoExtract), "WHERE") > 0
Then
varf_QuerytoExtract = varf_QuerytoExtract &
" and " & varf_Static_Filter
Else
varf_QuerytoExtract = varf_QuerytoExtract &
" where " & varf_Static_Filter
End If
End If

If varf_Derived_Filter <> "" Then


varf_Derived_Filter =
Replace(Replace(varf_Derived_Filter,Chr(13),""),Chr(10),"")
varf_Derived_Filter_Split =
Split(varf_Derived_Filter,"||")
For vDrvFld_Cnt = 0 to
Ubound(varf_Derived_Filter_Split)
vDrvFld_Value =
varf_Derived_Filter_Split(vDrvFld_Cnt)
If Instr(1,vDrvFld_Value,"=") > 0 Then
varf_QuerytoExtract =
Replace(varf_QuerytoExtract,"{" & Trim(Split(vDrvFld_Value,"=")(0)) &
"}",Trim(Split(vDrvFld_Value,"=")(1)))
varf_QuerytoExtract =
Replace(varf_QuerytoExtract,"{ " & Trim(Split(vDrvFld_Value,"=")(0)) &
" }",Trim(Split(vDrvFld_Value,"=")(1)))
varf_QuerytoExtract =
Replace(varf_QuerytoExtract,"{ " & Trim(Split(vDrvFld_Value,"=")(0)) &
"}",Trim(Split(vDrvFld_Value,"=")(1)))
varf_QuerytoExtract =
Replace(varf_QuerytoExtract,"{" & Trim(Split(vDrvFld_Value,"=")(0)) &
" }",Trim(Split(vDrvFld_Value,"=")(1)))
End If
Next
End If

If Instr(1,varf_ConnString,"SYBASEIQ") >0 Then


If Obj_FSO.FileExists (vSybIQ_JProcLocation) Then
varf_ConnString_details =
Replace(Trim(Split(varf_ConnString,"::")(1)),Chr(44),Chr(32))
' vComparisonFilesFdr_tmp =
vComparisonFilesFdr
vSybaseIQ_JavaCMD_DataExtract = "java
-jar " & vSybIQ_JProcLocation & " " & Trim(varf_ConnString_details) & " " & Chr(34)
& varf_QuerytoExtract & Chr(34) &_

" " & Replace(vComparisonFilesFdr,"\","\\") & " " & vDBFileName & " " & Chr(34) &
"|" & Chr(34)
vJavaBinLocation = "set
Path=C:\temp\jdk1.7.0_11\bin;C:\temp\jdk1.7.0_09\bin; &"
vJavaBinLocation = ""
vSybaseIQ_JavaCMD_Process = "cmd /c " &
vJavaBinLocation & vSybaseIQ_JavaCMD_DataExtract
ObjWsh_SybaseQuery.Run
vSybaseIQ_JavaCMD_Process
' Wait until the extracted and trigger
file is genrated
vSybIQ_DataExtracted_Triggger = Empty
vFilePull_Timer = Timer
vFileExtract_TimeExceed = Empty
Do Until vSybIQ_DataExtracted_Triggger =
"Found" Or vFileExtract_TimeExceed = True
If Obj_FSO.FileExists
(vComparisonFilesFdr & vDBFileName & ".txt") Then vSybIQ_DataExtracted_Triggger =
"Found"
' ObjWsh_SybaseQuery.Sleep 1000
Wait 1
If (Timer - vFilePull_Timer) >
300 Then vFileExtract_TimeExceed = True
Loop
Else
vDBFile_Remarks = " Java Process not
exist in the location - " & vSybIQ_JProcLocation
vDbFile_Status = "FAIL"
Exit Function
End If
Else
Obj_RSGeneric.Open
varf_QuerytoExtract,Obj_AdodbConnGen,3,3
If Obj_RSGeneric.EOF <> True Then
If Obj_RSGeneric.BOF <> True Then
Obj_RSGeneric.MoveFirst
vFieldNames_Extraction = Empty
For Each vColName in Obj_RSGeneric.Fields
vFieldNames_Extraction =
vFieldNames_Extraction & Chr(124) & vColName.Name
Next
vFieldNames_Extraction =
Mid(vFieldNames_Extraction,2)
Set ObjPipeFile_Extract =
Obj_FSO.OpenTextFile(vComparisonFilesFdr & vDBFileName,2,True)
ObjPipeFile_Extract.WriteLine
vFieldNames_Extraction
vRecCount_Extraction = 0

Do Until Obj_RSGeneric.EOF
ObjPipeFile_Extract.writeline
Replace(Obj_RSGeneric.GetString(2,1,"|",""),Chr(13),"")
vRecCount_Extraction =
vRecCount_Extraction + 1
Loop
ObjPipeFile_Extract.Close
Else
vDBFile_Remarks = " No Records are available
from query output"
vDbFile_Status = "FAIL"
End If
End If

If Obj_FSO.FileExists (vComparisonFilesFdr & vDBFileName)


Then
vDBFile_Remarks = "Extracted File is available"
vDbFile_Status = "PASS"
Else
vDBFile_Remarks = "Extracted File is not available,
unable to generate the file"
vDbFile_Status = "FAIL"
End If
Else
vDBFile_Remarks = "Query for extraction is empty"
vDbFile_Status = "FAIL"
Exit Function
End If

If Obj_RSGeneric.State = 1 Then Obj_RSGeneric.Close


If vDbFile_Status <> "PASS" Then vDBFile_Remarks = vDBFile_Remarks & Chr(10) &
"unable to create the pipeline file from DB"

End Function

Public Function vFixedWidth_to_PIPE(varf_FixedWidth_Schema, Obj_AdodbConnection,


varf_ActFileName_Cpy2Local, varf_BaseFileName_Cpy2Local,_

Obj_RSActual,Obj_RSBaseline,varf_TempDB_FdrPath,ObjXL_Main,Obj_FSO,Obj_ExeLog,ObjWB
_Result,vFixedWidth2PIPE_Status)

If Instr(1, varf_FixedWidth_Schema, "$FixedWidth_FilePath") > 0 And


Instr(1,varf_FixedWidth_Schema,"@FixedWidth_SchemaSheet") > 0 Then
varf_FixedWidth_FilePath =
Trim(Replace(Replace(Split(Replace(varf_FixedWidth_Schema,"$FixedWidth_FilePath",""
),"@FixedWidth_SchemaSheet")(0),"=",""),Chr(10),""))
varf_FixedWidth_SchemaSheet =
Trim(Replace(Replace(Split(Replace(varf_FixedWidth_Schema,"$FixedWidth_FilePath",""
),"@FixedWidth_SchemaSheet")(1),"=",""),Chr(10),""))
If Obj_FSO.FileExists(varf_FixedWidth_FilePath) Then
Set ObjWB_FixedWidth_Schema =
ObjXL_Main.WorkBooks.Open(varf_FixedWidth_FilePath)
If Func_Worksheet_Exist(varf_FixedWidth_SchemaSheet,
ObjWB_FixedWidth_Schema) =1 Then
Set ObjWS_FixedWidth_Schema =
ObjWB_FixedWidth_Schema.WorkSheets(varf_FixedWidth_SchemaSheet)
Else
' < Fixed Width Sheet not exist >
' Exit Function
End If

Else
' < Fixed Width Xlsx file not exist >
' Exit Function
End If

ElseIf
Func_Worksheet_Exist(Trim(Replace(Replace(Replace(varf_FixedWidth_Schema,"@FixedWid
th_Sheet",""),"-",""),Chr(10),"")), ObjWB_Result) =1 Then
Set ObjWS_FixedWidth_Schema =
ObjWB_Result.WorkSheets(Trim(Replace(Replace(Replace(varf_FixedWidth_Schema,"@Fixed
Width_Sheet",""),"-",""),Chr(10),"")))
Else
' < Fixed Width Sheet not exist >
' Exit Function
End If

' ObjWS_FixedWidth_Schema

vFixedWidth_UsedColCnt =
Cint(ObjWS_FixedWidth_Schema.UsedRange.Columns.Count)
vFixedWidth_UsedRowCnt =
Cint(ObjWS_FixedWidth_Schema.UsedRange.Rows.Count)
vRowNoFW = 1

vFW_ColAtrrNames_ColNo = ObjWS_FixedWidth_Schema.Range("A" & vRowNoFW & ":" &


Chr(vFixedWidth_UsedColCnt + 64) & vRowNoFW).Find("Column_Attr_Name").Column
vFW_DataType_ColNo = ObjWS_FixedWidth_Schema.Range("A" & vRowNoFW & ":" &
Chr(vFixedWidth_UsedColCnt + 64) & vRowNoFW).Find("Data_Type").Column
vFW_DataConvertx_ColNo = ObjWS_FixedWidth_Schema.Range("A" & vRowNoFW & ":" &
Chr(vFixedWidth_UsedColCnt + 64) & vRowNoFW).Find("Data_Conversation").Column
vFW_StartPosition_ColNo = ObjWS_FixedWidth_Schema.Range("A" & vRowNoFW & ":" &
Chr(vFixedWidth_UsedColCnt + 64) & vRowNoFW).Find("Start_Position").Column
vFW_Width_ColNo = ObjWS_FixedWidth_Schema.Range("A" & vRowNoFW & ":" &
Chr(vFixedWidth_UsedColCnt + 64) & vRowNoFW).Find("Width").Column

Set ObjWrt_FWSchema_INI = Obj_FSO.OpenTextFile (varf_TempDB_FdrPath &


"Schema.ini",2,True)

ObjWrt_FWSchema_INI.WriteLine "[" & varf_ActFileName_Cpy2Local & "]"


ObjWrt_FWSchema_INI.WriteLine "Format = FixedLength"
For vFWSchema_RowCnt=2 To vFixedWidth_UsedRowCnt
vFW_ColAtrrName_Value = ObjWS_FixedWidth_Schema.Cells(vFWSchema_RowCnt,
vFW_ColAtrrNames_ColNo).Value
If vFW_ColAtrrName_Value <> "" Or vFW_ColAtrrName_Value <> Empty Then
vFW_ColDataType = ObjWS_FixedWidth_Schema.Cells(vFWSchema_RowCnt,
vFW_DataType_ColNo).Value
vFW_ColWidth = ObjWS_FixedWidth_Schema.Cells(vFWSchema_RowCnt,
vFW_Width_ColNo).Value
ObjWrt_FWSchema_INI.WriteLine "Col" & vFWSchema_RowCnt-1 & "=" &
Chr(34) & vFW_ColAtrrName_Value & Chr(34) & " " & vFW_ColDataType & " Width " &
vFW_ColWidth
End If
Next

ObjWrt_FWSchema_INI.WriteLine "[" & varf_BaseFileName_Cpy2Local & "]"


ObjWrt_FWSchema_INI.WriteLine "Format = FixedLength"
For vFWSchema_RowCnt=2 To vFixedWidth_UsedRowCnt
vFW_ColAtrrName_Value = ObjWS_FixedWidth_Schema.Cells(vFWSchema_RowCnt,
vFW_ColAtrrNames_ColNo).Value
If vFW_ColAtrrName_Value <> "" Or vFW_ColAtrrName_Value <> Empty Then
vFW_ColumnNames_Pipe = vFW_ColumnNames_Pipe & Chr(124) &
vFW_ColAtrrName_Value
vFW_ColDataType = ObjWS_FixedWidth_Schema.Cells(vFWSchema_RowCnt,
vFW_DataType_ColNo).Value
vFW_ColWidth = ObjWS_FixedWidth_Schema.Cells(vFWSchema_RowCnt,
vFW_Width_ColNo).Value
ObjWrt_FWSchema_INI.WriteLine "Col" & vFWSchema_RowCnt-1 & "=" &
Chr(34) & vFW_ColAtrrName_Value & Chr(34) & " " & vFW_ColDataType & " Width " &
vFW_ColWidth
End If
Next
ObjWrt_FWSchema_INI.Close
vFW_ColumnNames_Pipe = Mid(vFW_ColumnNames_Pipe,2)

varf_ActFileName_Cpy2Local_FW = Split(varf_ActFileName_Cpy2Local,".")(0) &


"_CFWP.DAT"
varf_BaseFileName_Cpy2Local_FW = Split(varf_BaseFileName_Cpy2Local,".")(0) &
"_CFWP.DAT"

Set ObjWrt_ActualFile_Pipe = Obj_FSO.OpenTextFile (varf_TempDB_FdrPath &


varf_ActFileName_Cpy2Local_FW,2,True)
Set ObjWrt_BaselineFile_Pipe = Obj_FSO.OpenTextFile (varf_TempDB_FdrPath &
varf_BaseFileName_Cpy2Local_FW,2,True)

vFW_ActualFile_Query = "Select " &


Replace(vFW_ColumnNames_Pipe,Chr(124),Chr(44)) & " From " &
varf_ActFileName_Cpy2Local
Obj_RSActual.Open vFW_ActualFile_Query, Obj_AdodbConnection,1,3
ObjWrt_ActualFile_Pipe.WriteLine vFW_ColumnNames_Pipe
Do Until Obj_RSActual.EOF
ObjWrt_ActualFile_Pipe.WriteLine
Replace(Obj_RSActual.GetString(2,1,CHr(124),""),Chr(13),"")
Loop
If Obj_RSActual.State = 1 Then Obj_RSActual.Close
ObjWrt_ActualFile_Pipe.Close

vFW_BaselineFile_Query = "Select " &


Replace(vFW_ColumnNames_Pipe,Chr(124),Chr(44)) & " From " &
varf_BaseFileName_Cpy2Local
Obj_RSBaseline.Open vFW_BaselineFile_Query, Obj_AdodbConnection,1,3
ObjWrt_BaselineFile_Pipe.WriteLine vFW_ColumnNames_Pipe
Do Until Obj_RSBaseline.EOF
ObjWrt_BaselineFile_Pipe.WriteLine
Replace(Obj_RSBaseline.GetString(2,1,CHr(124),""),Chr(13),"")
Loop
If Obj_RSBaseline.State = 1 Then Obj_RSBaseline.Close
ObjWrt_BaselineFile_Pipe.Close

varf_ActFileName_Cpy2Local = varf_ActFileName_Cpy2Local_FW
varf_BaseFileName_Cpy2Local = varf_BaseFileName_Cpy2Local_FW

On Error Resume Next


ObjWB_FixedWidth_Schema.Close
On Error Goto 0

vFixedWidth2PIPE_Status = "Pass - PipeLine Created"

End Function
'==================================== End Function
==========================================

Public Function vColumnValidation_MissDiffExpected


( varf_ActColName_DumLineDT,varf_BaseColName_DumLineDT,varf_Column_validation,ObjXL
_Main,Obj_FSO,Obj_ExeLog,ObjWB_Result,_
varf_diff,
varf_DiffCnt,varf_ActDumyRec_insert,varf_BaseDumyRec_insert, vBaseAttribute_Names,
vColumnVerf_Status)
If Instr(1, varf_Column_validation, "$ColumnMapping_FilePath") > 0 And
Instr(1,varf_Column_validation,"@ColumnMapping_SchemaSheet") Then
varf_ColumnMapping_FilePath =
Trim(Replace(Replace(Split(Replace(varf_Column_validation,"$ColumnMapping_FilePath"
,""),"@ColumnMapping_SchemaSheet")(0)_
,"=",""),Chr(10),
""))
varf_ColumnMapping_SchemaSheet =
Trim(Replace(Replace(Split(Replace(varf_Column_validation,"$ColumnMapping_FilePath"
,""),"@ColumnMapping_SchemaSheet")(1)_
,"=",""),Chr(10),
""))
If Obj_FSO.FileExists(varf_ColumnMapping_FilePath) Then
Set ObjWB_ColumnMapping_Schema =
ObjXL_Main.WorkBooks.Open(varf_ColumnMapping_FilePath)
If Func_Worksheet_Exist(varf_ColumnMapping_SchemaSheet,
ObjWB_ColumnMapping_Schema) =1 Then
Set ObjWS_ColumnMapping_Schema =
ObjWB_ColumnMapping.WorkSheets(varf_ColumnMapping_SchemaSheet)
Else
' < Column Mapping Sheet not exist >
' Exit Function
End If

Else
' < Column Mapping Xlsx file not exist >
' Exit Function
End If

ElseIf
Func_Worksheet_Exist(Trim(Replace(Replace(Replace(varf_Column_validation,"@ColumnMa
pping_Sheet",""),"-",""),Chr(10),"")), ObjWB_Result) =1 Then
Set ObjWS_ColumnMapping_Schema =
ObjWB_Result.WorkSheets(Trim(Replace(Replace(Replace(varf_Column_validation,"@Colum
nMapping_SchemaSheet",""),"=",""),Chr(10),"")))
Else
' < Column Mapping Sheet not exist >
' Exit Function
End If

' ObjWS_ColumnMapping_Schema
' varf_dummydttype

' varf_ActDumyRec_insert = Mid(varf_ActDumyRec_insert, 2)


' varf_BaseDumyRec_insert = Mid(varf_BaseDumyRec_insert, 2)
' vBaseAttribute_Names = "LineNo" & varf_fileDelimiter & vBaseAttribute_Names

' < The above three attributes should be send to main comparison function>
' < complete the function for 3 validation, differnece in files -- Missing
columns and adding to list ---- validate the expected columns >

End Function

'==================================== End Function


==========================================
Public Function f_DifferenceReporting_CSV(varf_Extra_Fields, varf_Logical_columns,
varf_diff, vDiffSheetName, Obj_FSO, Obj_ExeLog, ObjWB_Result, _
varf_CompoConcat_LogicalKeys,
vResultFdr, vTDResult_FileName, vDiffReportExcel_Status)
If Func_Worksheet_Exist(vDiffSheetName, ObjWB_Result) = 1 Then
ObjWB_Result.Worksheets(vDiffSheetName).Visible = False
vDiffReport_FileName = Replace(vTDResult_FileName,".xlsx",".csv")
If Obj_FSO.FileExists(vResultFdr & vDiffReport_FileName) Then
Set ObjWrt_DiffReportCSV = Obj_FSO.OpenTextFile(vResultFdr &
vDiffReport_FileName , 8 ,True)
Else
Set ObjWrt_DiffReportCSV = Obj_FSO.OpenTextFile(vResultFdr &
vDiffReport_FileName , 2 ,True)
' ObjWrt_DiffReportCSV.WriteBlankLines 4
varf_CompoConcat_LogicalKeys =
Replace(Replace(varf_CompoConcat_LogicalKeys,"&",""),"'|'","|")

vDelimiter = Chr(124)

If varf_Extra_Fields <> Empty Or varf_Extra_Fields <> "" Then


ObjWrt_DiffReportCSV.WriteLine "LOGICAL_KEY (" &
varf_CompoConcat_LogicalKeys & ")" & vDelimiter & "LINENO_ACTUAL" & vDelimiter &
"LINENO_BASELINE" & vDelimiter & "FIELD NAME" & vDelimiter & _
"ACTUAL VALUE" & vDelimiter
& "BASELINE VALUE" & vDelimiter & "Filter Condition" & vDelimiter &
"ExtraFields(" & Replace(varf_Extra_Fields,Chr(44)," ; ") & ")"
Else
ObjWrt_DiffReportCSV.WriteLine "LOGICAL_KEY (" &
varf_CompoConcat_LogicalKeys & ")" & vDelimiter & "LINENO_ACTUAL" & vDelimiter &
"LINENO_BASELINE" & vDelimiter & "FIELD NAME" & vDelimiter & _
"ACTUAL VALUE" & vDelimiter
& "BASELINE VALUE" & vDelimiter & "Filter Condition"
End If
End If

If varf_Extra_Fields <> Empty Or varf_Extra_Fields <> "" Then


For vDiffReportCnt = 0 To Ubound(varf_diff)
vStartingRowNo_DiffReport =
vStartingRowNo_DiffReport + 1
ObjWrt_DiffReportCSV.WriteLine
Replace(Replace(varf_diff(vDiffReportCnt), Chr(44), "`"),"^$!",vDelimiter)
Next
Else
For vDiffReportCnt = 0 To Ubound(varf_diff)
vStartingRowNo_DiffReport =
vStartingRowNo_DiffReport + 1
ObjWrt_DiffReportCSV.WriteLine
Replace(Replace(varf_diff(vDiffReportCnt),"^$!",vDelimiter), Chr(44), "`")
Next
End If
End Function

Public Function f_DifferenceReporting_Excel (varf_Extra_Fields,


varf_Logical_columns, varf_diff, varf_ScenarioName,vDiffSheetName, Obj_ExeLog,
ObjWB_Result, vDiffReportExcel_Status)
' Declaration Of Variable

' Initialisation Of variables

'vDiffSheetName
'ObjWB_Result

vLogicalKey_DiffReport_ColNo = 1
vLineNoActual_DiffReport_ColNo = 2
vLineNoBase_DiffReport_ColNo = 3
vFieldName_DiffReport_ColNo = 4
vActFieldValue_DiffReport_ColNo = 5
vBaseFieldvalue_DiffReport_ColNo = 6
vStartingRowNo_DiffReport = 3
vTotalNoColUsed_DiffReport = 8

If Func_Worksheet_Exist(vDiffSheetName, ObjWB_Result) = 1 Then


Set ObjWS_DiffReport = ObjWB_Result.Worksheets(vDiffSheetName)
vTotRow_DiffReport =
Cint(ObjWS_DiffReport.UsedRange.Rows.Count)
If vTotRow_DiffReport < 3 Then

' Defining the Header (First Row) in differnce sheet

ObjWS_DiffReport.Cells(vStartingRowNo_DiffReport-1,
vLogicalKey_DiffReport_ColNo).Value = " Logical Keys (" &
varf_Logical_columns & ")"
ObjWS_DiffReport.Cells(vStartingRowNo_DiffReport-1,
vLineNoActual_DiffReport_ColNo).Value = "LineNo_Actual"
ObjWS_DiffReport.Cells(vStartingRowNo_DiffReport-1,
vLineNoBase_DiffReport_ColNo).Value = "LineNo_Baseline"
ObjWS_DiffReport.Cells(vStartingRowNo_DiffReport-1,
vFieldName_DiffReport_ColNo).Value = "Attribute Name"
ObjWS_DiffReport.Cells(vStartingRowNo_DiffReport-1,
vActFieldValue_DiffReport_ColNo).Value = "ActualField_Value"
ObjWS_DiffReport.Cells(vStartingRowNo_DiffReport-1,
vBaseFieldvalue_DiffReport_ColNo).Value = "BaselineField_Value"

Else
vStartingRowNo_DiffReport = vTotRow_DiffReport + 1
End If

For vDiffReportCnt = 0 To Ubound(varf_diff)


vDiffReport_RecSplit = Split(varf_diff(vDiffReportCnt),"^$!")
ObjWS_DiffReport.Range("A" & vStartingRowNo_DiffReport & ":" &
Chr(vTotalNoColUsed_DiffReport + 64) & vStartingRowNo_DiffReport).Value =
vDiffReport_RecSplit
vStartingRowNo_DiffReport = vStartingRowNo_DiffReport + 1
Next

If varf_Extra_Fields <> Empty Or varf_Extra_Fields <> "" Then


ObjWS_DiffReport.Range("H:H").Cut
ObjWS_DiffReport.Range("B:B").Insert
ObjWS_DiffReport.Cells(2, 2).Value = "ExtraFields(" &
Replace(varf_Extra_Fields,Chr(44),Chr(124)) & ")"
ObjWS_DiffReport.Range("A1:G" & vStartingRowNo_DiffReport-
1).Borders.LineStyle = xlContinuous
ObjWS_DiffReport.Range("A1:G" & vStartingRowNo_DiffReport-
1).Borders.color = vbBlack
Else
ObjWS_DiffReport.Range("A1:F" & vStartingRowNo_DiffReport-
1).Borders.LineStyle = xlContinuous
ObjWS_DiffReport.Range("A1:F" & vStartingRowNo_DiffReport-
1).Borders.color = vbBlack
End If

If varf_Extra_Fields <> Empty Or varf_Extra_Fields <> "" Then


vTotalNoColUsed_DiffReport = 7

' Defining the Header (First Row) in differnce sheet


ObjWS_DiffReport.Cells(1,1).Value = " Differences for scenario -
" & Chr(34) & varf_ScenarioName & Chr(34)
ObjWS_DiffReport.Range("A1:" & Chr(vTotalNoColUsed_DiffReport +
64) & "1").MergeCells = True
ObjWS_DiffReport.Range("A1:" & Chr(vTotalNoColUsed_DiffReport +
64) & "1").Interior.ColorIndex = 40
ObjWS_DiffReport.Range("A1:" & Chr(vTotalNoColUsed_DiffReport +
64) & "1").HorizontalAlignment = -4108
ObjWS_DiffReport.Range("A1:" & Chr(vTotalNoColUsed_DiffReport +
64) & "1").Font.Bold = True

ObjWS_DiffReport.Range("A2" & ":" & Chr(vTotalNoColUsed_DiffReport


+ 64) & "2").Font.Bold = True
ObjWS_DiffReport.Range("A2" & ":" & Chr(vTotalNoColUsed_DiffReport
+ 64) & "2").Font.Size = 12
ObjWS_DiffReport.Range("A2" & ":" & Chr(vTotalNoColUsed_DiffReport
+ 64) & "2").Interior.Colorindex = 37
ObjWS_DiffReport.Range("A2" & ":" & Chr(vTotalNoColUsed_DiffReport
+ 64) & "2").HorizontalAlignment = -4108

ObjWS_DiffReport.Activate
vDiffReportExcel_Status = "PASS"
ObjWB_Result.Worksheets(vDiffSheetName).Visible = True
ObjWB_Result.Save

Else
' <Temporary result difference sheet not available in the result report
excel file>
End If

End Function

Public Function
f_GetDynamicFilters(Obj_Dict_Conf,Obj_AdodbConnection,varf_ActFileName_DumLineDT,
varf_BaseFileName_DumLineDT, _

varrDynamicFilters,vFilter_OutOfRange,vNoOfRec_PerDynFilter,varf_dummydttype)

' Variable Declaration

vDynamicFilter_Set1 =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Dynamic_Filter_set1"))," ,
",",")," ,",","),", ",",")," ","_")
vDynamicFilter_Set2 =
Replace(Replace(Replace(Replace(Trim(Obj_Dict_Conf("Dynamic_Filter_set2"))," ,
",",")," ,",","),", ",",")," ","_")
vStaticFilter = Trim(Obj_Dict_Conf("Static_Filter"))
vTableName = Trim(Obj_Dict_Conf("Baseline_File_Name /
Baseline_table_Name"))
vDataBaseName = Trim(Obj_Dict_Conf("Folder_Name / Database_Name"))
vJoinTrigger = Trim(Obj_Dict_Conf("PC_trigger_Flag"))
vJoinTableName = Trim(Obj_Dict_Conf("ParentTable_Name"))
vJoinTableJoinColumns = Trim(Obj_Dict_Conf("ParentTable_columns"))
vMainTableJoinColumns = Trim(Obj_Dict_Conf("ChildTable_columns"))
vNoOfRecords_SetFilters = vNoOfRec_PerDynFilter
vNoOfRec_SetFilters_P1 = vNoOfRecords_SetFilters + 1

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++
' Dynamic Filter ------ Set 1 and less than 400,000 Records
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++

' Identify the data tyep of the filters which will help to define kind of
statement

varrDyn_Filter_Split = Split(vDynamicFilter_Set1,",")

' Define the static Filter

If vStaticFilter & "!@#$" <> "!@#$" Then


vStaticFilter = " Where " & vStaticFilter
Else
vStaticFilter = ""
End If

' Define the basic query

If vJoinTrigger & "!@#$" <> "!@#$" And Ucase(vJoinTrigger) = "Y" Then


vFilterColumns = ""
If Instr(1, vDynamicFilter_Set1, ",") > 0 Then
varrDyn_Filter_Split = Split(vDynamicFilter_Set1, ",")
For vCtr = Lbound(varrDyn_Filter_Split) To
Ubound(varrDyn_Filter_Split)-1
vFilterColumns = vFilterColumns & vTableName & "." &
varrDyn_Filter_Split(vCtr) & ","
Next
vFilterColumns = vFilterColumns & vTableName & "." &
varrDyn_Filter_Split(vCtr)
Else
vFilterColumns = vFilterColumns & vTableName & "." &
varrDyn_Filter_Split(vCtr)
End If

vQueyJoin = ""
If Instr(1, vJoinTableJoinColumns,",") Then
varrJoinTableJoinColumns = Split(vJoinTableJoinColumns,",")
varrMainTableJoinColumns = Split(vMainTableJoinColumns,",")
For VCtr = 0 To Ubound(varrJoinTableJoinColumns)-1
vQueyJoin = vQueyJoin & vTableName & "." &
varrMainTableJoinColumns(vCtr) & " = " & vJoinTableName & "." &
varrJoinTableJoinColumns(vCtr) & " And "
Next
vQueyJoin = vQueyJoin & vTableName & "." &
varrMainTableJoinColumns(vCtr) & " = " & vJoinTableName & "." &
varrJoinTableJoinColumns(vCtr)
Else
vQueyJoin = vQueyJoin & vTableName & "." &
varrMainTableJoinColumns(vCtr) & " = " & vJoinTableName & "." &
varrJoinTableJoinColumns(vCtr)
End If

vFilterQuery = "Select " & vFilterColumns & ", Count(*) Filter_Cnt From "
& vEnvSpecificDatabaseName & "." & vTableName & " " & vTableName
vFilterQuery = vFilterQuery & "Left Outer Join " &
vEnvSpecificDatabaseName & "." & vJoinTableName & " " & vJoinTableName
vFilterQuery = vFilterQuery & "On " & vQueyJoin & vStaticFilter & " Group
By " & vFilterColumns & " having count(*) < " & _
vNoOfRec_SetFilters_P1 & "Order by count(*) desc"
Else
vFilterQuery = "Select " & vDynamicFilter_Set1 & ", max(BaseCnt) as
finalgrpcnt from (" & _
"select " & vDynamicFilter_Set1 & ", count(*) as BaseCnt
from " & varf_BaseFileName_DumLineDT & vStaticFilter & " group by " & _
vDynamicFilter_Set1 & " having count(*) <= "
& vNoOfRec_PerDynFilter & " union " & _
"select " & vDynamicFilter_Set1 & ", count(*) as ActCnt
from " & varf_ActFileName_DumLineDT & vStaticFilter & " group by " & _
vDynamicFilter_Set1 & " having count(*) <= "
& vNoOfRec_PerDynFilter & _
") group by " & vDynamicFilter_Set1 & " order
by max(BaseCnt) desc"
End If

' Executing the basic query

Set RS_GetFilters = CreateObject("Adodb.RecordSet")


RS_GetFilters.Open vFilterQuery, Obj_AdodbConnection,1,3
vFilterCtr = 0
vTempFilterStoreValue = ""
vTotal_Filter_cnt = 0
vNoFilters_into_Query = 0
ReDim Preserve varrDynamicFilters(vFilterCtr)

Do While RS_GetFilters.EOF <> True


For vCtr = 0 to Ubound(varrDyn_Filter_Split)
varrDyn_Filter_Split(vCtr) =
Ucase(Trim(Cstr(varrDyn_Filter_Split(vCtr))))
vFilterValue =
RS_GetFilters.Fields(varrDyn_Filter_Split(vCtr)).Value
If Cbool(vFilterValue & "!@#$" = "!@#$") = True Then
vFiltervalue_final = " IS Null "
ElseIf Instr(1, varrDyn_Filter_Split(vCtr), "DATE") > 0 Then
' vFiltervalue = Year(Cdate(vFiltervalue)) & "-" &
Left(Monthname(month(Cdate(vFiltervalue))),3) & "-" & Day(CDate(vFiltervalue))
vFiltervalue = Year(Cdate(vFiltervalue)) & "-" &
month(Cdate(vFiltervalue)) & "-" & Day(CDate(vFiltervalue))
vFiltervalue_final = " = '" & vFiltervalue & "' "
Else
vFiltervalue_final = " = '" & vFiltervalue & "' "
End If
vTempFilterStoreValue = vTempFilterStoreValue & " And " &
varrDyn_Filter_Split(vCtr) & vFiltervalue_final
Next
vTempFilterStoreValue = Mid(vTempFilterStoreValue, 5)
vTotal_Filter_cnt = vTotal_Filter_cnt +
CDBL(RS_GetFilters.Fields("finalgrpcnt").Value)

If Instr(1, lcase(vTempFilterStoreValue), lcase(varf_dummydttype)) <= 0


Then
If vTotal_Filter_cnt > vNoOfRecords_SetFilters Or
vNoFilters_into_Query > 999 Then
varrDynamicFilters(vFilterCtr) = "(" &
Mid(varrDynamicFilters(vFilterCtr),5) & ")"
vFilterCtr = vFilterCtr + 1
ReDim Preserve varrDynamicFilters(vFilterCtr)
vTotal_Filter_cnt =
CDBL(RS_GetFilters.Fields("finalgrpcnt").Value)
vNoFilters_into_Query = 1
varrDynamicFilters(vFilterCtr) =
varrDynamicFilters(vFilterCtr) & " Or ( " & vTempFilterStoreValue & ")"
Else
varrDynamicFilters(vFilterCtr) =
varrDynamicFilters(vFilterCtr) & " Or ( " & vTempFilterStoreValue & ")"
vNoFilters_into_Query = vNoFilters_into_Query + 1
End If
End If
vTempFilterStoreValue = ""
RS_GetFilters.MoveNext
Loop

If vNoFilters_into_Query <> 0 Then


varrDynamicFilters(vFilterCtr) = "(" &
Mid(varrDynamicFilters(vFilterCtr),5) & ")"
End If

RS_GetFilters.Close
Set RS_GetFilters = Nothing

'++++++++++++++++++++++++++
' Dynamic Filter ------ Set 2 and more than 400,000 Records
'++++++++++++++++++++++++++

If vStaticFilter & "!@#$" <> "!@#$" Then


vStaticFilter_and = vStaticFilter & " AND "
Else
vStaticFilter_and = " Where "
End If

'Identify the data_type of the filter which will help to define kind of statement

vDynamicFilter_Conct_Set1 = ""
vDynamicFilter_Set1_Split = Split(vDynamicFilter_Set1,",")
For vDynamicFtrSet1_Ctr = 0 to Ubound(vDynamicFilter_Set1_Split)
vDynamicFilter_Conct_Set1 = vDynamicFilter_Conct_Set1 & "||" &
Ucase(Trim(vDynamicFilter_Set1_Split(vDynamicFtrSet1_Ctr)))
Next
vDynamicFilter_Conct_Set1 = Mid(vDynamicFilter_Conct_Set1,3)

If vDynamicFilter_Set2 <> Empty Or vDynamicFilter_Set2 <> "" Then


vDynamicFilter_Set12 = Ucase(Trim(vDynamicFilter_Set1 & "," &
vDynamicFilter_Set2))
Else
vDynamicFilter_Set12 = Ucase(Trim(vDynamicFilter_Set1))
End If
varrDyn_Filter_Split = Split(vDynamicFilter_Set12,",")

' Defining the basic query

If vJoinTrigger & "!@#$" <> "!@#$" And Ucase(vJoinTrigger) = "Y" Then


vFilterColumns_set1 = ""
vFilterColumns_Conc_set1 = ""
vFilterColumns = ""

If Instr(1, vFilter_set1, ",") > 0 Then


varrDyn_Filter_Split = Split(vFilter_set1, ",")
For vCtr = Lbound(varrDyn_Filter_Split) To
Ubound(varrDyn_Filter_Split)-1
vFilterColumns_set1 = vFilterColumns_set1 & vTableName &
"." & varrDyn_Filter_Split(vCtr) & " , "
vFilterColumns_Conc_set1 = vFilterColumns_Conc_set1 &
vTableName & "." & varrDyn_Filter_Split(vCtr) & " || "
Next
vFilterColumns_set1 = vFilterColumns_set1 & vTableName & "."
& varrDyn_Filter_Split(vCtr)
vFilterColumns_Conc_set1 = vFilterColumns_Conc_set1 & vTableName
& "." & varrDyn_Filter_Split(vCtr)
Else
vFilterColumns_set1 = vFilterColumns_set1 & vTableName & "."
& varrDyn_Filter_Split(vCtr)
vFilterColumns_Conc_set1 = vFilterColumns_Conc_set1 & vTableName
& "." & varrDyn_Filter_Split(vCtr)
End If

If Instr(1, vDynamicFilter_Set1, ",") > 0 Then


varrDyn_Filter_Split = Split(vDynamicFilter_Set1, ",")
For vCtr = Lbound(varrDyn_Filter_Split) To
Ubound(varrDyn_Filter_Split)-1
vFilterColumns = vFilterColumns & vTableName & "." &
varrDyn_Filter_Split(vCtr) & ","
Next
vFilterColumns = vFilterColumns & vTableName & "." &
varrDyn_Filter_Split(vCtr)
Else
vFilterColumns = vFilterColumns & vTableName & "." &
varrDyn_Filter_Split(vCtr)

End If

vQueyJoin = ""
If Instr(1, vJoinTableJoinColumns,",") Then
varrJoinTableJoinColumns = Split(vJoinTableJoinColumns,",")
varrMainTableJoinColumns = Split(vMainTableJoinColumns,",")
For VCtr = 0 To Ubound(varrJoinTableJoinColumns)-1
vQueyJoin = vQueyJoin & vTableName & "." &
varrMainTableJoinColumns(vCtr) & " = " & vJoinTableName & "." &
varrJoinTableJoinColumns(vCtr) & " And "
Next
vQueyJoin = vQueyJoin & vTableName & "." &
varrMainTableJoinColumns(vCtr) & " = " & vJoinTableName & "." &
varrJoinTableJoinColumns(vCtr)
Else
vQueyJoin = vQueyJoin & vTableName & "." &
varrMainTableJoinColumns(vCtr) & " = " & vJoinTableName & "." &
varrJoinTableJoinColumns(vCtr)
End If

vFilterQuery = "Select " & vFilterColumns_Conc_set1 & " vFtrConc_set1,


Count(*) Filter_Cnt From " & vEnvSpecificDatabaseName & "." & vTableName & " " &
vTableName
vFilterQuery = vFilterQuery & "Left Outer Join " &
vEnvSpecificDatabaseName & "." & vJoinTableName & " " & vJoinTableName
vFilterQuery = vFilterQuery & "On " & vQueyJoin & vStaticFilter & "
Group By " & vFilterColumns_Conc_set1 & " having count(*) >= " &
vNoOfRec_SetFilters_P1 &_
"Order by count(*) desc"
vFilterQuery = "(Select vFtrConc_set1 ||'x' from (" & vFilterQuery &
"))"

vFilterQuery = "Select " & vFilterColumns & ", Count(*) Filter_Cnt


From " & vEnvSpecificDatabaseName & "." & vTableName & " " & vTableName _
& "Left Outer Join " & vEnvSpecificDatabaseName & "." &
vJoinTableName & " " & vJoinTableName & "On " & vQueyJoin & " And " & _
vFilterColumns_conc_set1 & "||'x' in " & vFilterQuery &
vStaticFilter & " Group By " & vFilterColumns & " Order by count(*) desc"
Else

vFilterQuery = "Select " & vDynamicFilter_Set12 & ",max(BaseCnt) as


finalgrpcnt from (" & _
"Select " & vDynamicFilter_Set12 & ",count(*) as BaseCnt
from " & varf_BaseFileName_DumLineDT & _
vStaticFilter_and & vDynamicFilter_Conct_Set1 & "&'x' not
in (select Distinct(" & vDynamicFilter_Set1 & ") &'x' from (" &_
"select " & vDynamicFilter_Set1 & ", count(*) from " &
varf_BaseFileName_DumLineDT & vStaticFilter & " group by " & _
vDynamicFilter_Set1 & " having count(*) <= "
& vNoOfRec_PerDynFilter & " union " & _
"select " & vDynamicFilter_Set1 & ", count(*) from " &
varf_ActFileName_DumLineDT & vStaticFilter & " group by " & _
vDynamicFilter_Set1 & " having count(*) <= "
& vNoOfRec_PerDynFilter & "))" & _
" group by " & vDynamicFilter_Set12 & " union " & _
"Select " & vDynamicFilter_Set12 & ",count(*) as ActCnt
from " & varf_ActFileName_DumLineDT & _
vStaticFilter_and & vDynamicFilter_Conct_Set1 & "&'x' not
in (select Distinct(" & vDynamicFilter_Set1 & ") &'x' from (" &_
"select " & vDynamicFilter_Set1 & ", count(*) from " &
varf_BaseFileName_DumLineDT & vStaticFilter & " group by " & _
vDynamicFilter_Set1 & " having count(*) <= "
& vNoOfRec_PerDynFilter & " union " & _
"select " & vDynamicFilter_Set1 & ", count(*) from " &
varf_ActFileName_DumLineDT & vStaticFilter & " group by " & _
vDynamicFilter_Set1 & " having count(*) <= "
& vNoOfRec_PerDynFilter & "))" & _
" group by " & vDynamicFilter_Set12 & _
") group by " & vDynamicFilter_Set12 & " order by
max(BaseCnt) desc"

End If

' Executing the basic query

Set RS_GetFilters = CreateObject("Adodb.RecordSet")


RS_GetFilters.Open vFilterQuery, Obj_AdodbConnection,1,3
If vFilterCtr <> 0 Or ( vFilterCtr = 0 And vNoFilters_into_Query <> 0 ) then
vFilterCtr = vFilterCtr + 1

If RS_GetFilters.EOF = True Then


If vFilterCtr <> 0 then vFilterCtr = vFilterCtr + 1
Else
ReDim Preserve varrDynamicFilters(vFilterCtr)
End If

vTempFilterStoreValue = ""
vTotal_Filter_cnt = 0
vNoFilters_into_Query = 0

Dim vFilter_OutOfRange_temp()
vFilter_OOR_Cnt = 0

Do While RS_GetFilters.EOF <> True


For vCtr = 0 to Ubound(varrDyn_Filter_Split)
varrDyn_Filter_Split(vCtr) =
Ucase(Trim(Cstr(varrDyn_Filter_Split(vCtr))))
vFilterValue =
RS_GetFilters.Fields(varrDyn_Filter_Split(vCtr)).Value
If Cbool(vFilterValue & "!@#$" = "!@#$") = True Then
vFiltervalue_final = " IS Null "
ElseIf Instr(1, varrDyn_Filter_Split(vCtr), "DATE") > 0 Then
' vFiltervalue = Year(Cdate(vFiltervalue)) & "-" &
Left(Monthname(month(Cdate(vFiltervalue))),3) & "-" & Day(CDate(vFiltervalue))
vFiltervalue = Year(Cdate(vFiltervalue)) & "-" &
month(Cdate(vFiltervalue)) & "-" & Day(CDate(vFiltervalue))
vFiltervalue_final = " = '" & vFiltervalue & "' "
Else
vFiltervalue_final = " = '" & vFiltervalue & "' "
End If
vTempFilterStoreValue = vTempFilterStoreValue & " And " &
varrDyn_Filter_Split(vCtr) & vFiltervalue_final
Next
vTempFilterStoreValue = Mid(vTempFilterStoreValue, 5)
vTotal_Filter_cnt = vTotal_Filter_cnt +
CDBL(RS_GetFilters.Fields("finalgrpcnt").Value)

Do
If Instr(1, lcase(vTempFilterStoreValue),
lcase(varf_dummydttype)) > 0 Then Exit Do
If vTotal_Filter_cnt > vNoOfRecords_SetFilters Or
vNoFilters_into_Query > 999 Then
If vNoFilters_into_Query = 0 Then
ReDim Preserve
vFilter_OutOfRange_temp(vFilter_OOR_Cnt)
vFilter_OutOfRange_temp(vFilter_OOR_Cnt) = "("
& vTempFilterStoreValue & ")" & "@# " & vTotal_Filter_cnt
vFilter_OOR_Cnt = vFilter_OOR_Cnt + 1
vTotal_Filter_cnt = 0
Exit Do
End If
varrDynamicFilters(vFilterCtr) = "(" &
Mid(varrDynamicFilters(vFilterCtr),5) & ")"
vFilterCtr = vFilterCtr + 1
vTotal_Filter_cnt =
CDBL(RS_GetFilters.Fields("finalgrpcnt").Value)
vNoFilters_into_Query = 1
ReDim Preserve varrDynamicFilters(vFilterCtr)
varrDynamicFilters(vFilterCtr) =
varrDynamicFilters(vFilterCtr) & " Or ( " & vTempFilterStoreValue & ")"
Else
varrDynamicFilters(vFilterCtr) =
varrDynamicFilters(vFilterCtr) & " Or ( " & vTempFilterStoreValue & ")"
vNoFilters_into_Query = vNoFilters_into_Query + 1
End If
Exit Do
Loop
vTempFilterStoreValue = ""
RS_GetFilters.MoveNext
Loop

If vNoFilters_into_Query <> 0 Then


varrDynamicFilters(vFilterCtr) = "(" &
Mid(varrDynamicFilters(vFilterCtr),5) & ")"
End If

vFilter_OutOfRange = vFilter_OutOfRange_temp
RS_GetFilters.Close
Set RS_GetFilters = Nothing

If vFilterCtr = 0 and (varrDynamicFilters(vFilterCtr) <> "" Or


varrDynamicFilters(vFilterCtr) <> Empty) Then
f_GetDynamicFilters = vFilterCtr + 1
Else
f_GetDynamicFilters = vFilterCtr
End If

End Function

'**********************************************************************************
**************************
' TC Regression Specific Functions
'**********************************************************************************
**************************

Public Function f_AutosysJobProcess_Validation(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)

vStatus ="PASS"

End Function

Public Function f_HiveTableStructure_Validation(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_HiveDatabase_Name, varf_TC_HiveTable_Name,
varf_TC_HiveReferenceSheet, varf_TC_HiveOutput_Location
Dim vHC_Source_ColumnNames_ColNo, vHC_Source_DataTypes_ColNo,
vHC_Primary_Key_ColNo, vHC_Not_Null_ColNo, vHC_HiveTable_ColumnNames_ColNo
Dim vHC_HiveTable_DataType_ColNo, vHC_Status_ColNo, vHC_Remarks_ColNo,
vHC_Actual_HiveOutput_DataType_ColNo

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_HiveDatabase_Name = Trim(Obj_Dict_RegTC("Hive_Database"))
varf_TC_HiveTable_Name = Trim(Obj_Dict_RegTC("Hive_table"))
varf_TC_HiveReferenceSheet = Trim(Obj_Dict_RegTC("Reference_ColumnSheet"))
varf_TC_HiveOutput_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))
varf_TC_AVRO_Location = Replace(Trim(Obj_Dict_RegTC("AVRO_Location")),"
","")

If Mid(Trim(varf_TC_HiveOutput_Location),
len(Trim(varf_TC_HiveOutput_Location)),1) <> "\" Then varf_TC_HiveOutput_Location =
Trim(varf_TC_HiveOutput_Location) & "\"

'Create the objects


Set ObjDict_SourceColumns_DataTypes = CreateObject("Scripting.Dictionary")
Set ObjDict_HiveColumns_DataTypes = CreateObject("Scripting.Dictionary")
Set ObjDict_AVROColumns_DataTypes = CreateObject("Scripting.Dictionary")
Set ObjDict_SourceColumns_DataTypes_rep = CreateObject("Scripting.Dictionary")
Set ObjDict_HiveColumns_DataTypes_rep = CreateObject("Scripting.Dictionary")
Set ObjDict_AVROColumns_DataTypes_rep = CreateObject("Scripting.Dictionary")
Set Wshell = CreateObject("Wscript.Shell")

' Extract the Hive column - file path and sheet name from variable
varf_TC_HiveReferenceSheet. Also copy the hive column sheet to result xl
' Establish the worksheet object for hive column available in result xl
If Instr(1, varf_TC_HiveReferenceSheet, "$HiveColumn_FilePath") > 0 And
Instr(1,varf_TC_HiveReferenceSheet,"@HiveColumn_SchemaSheet") > 0 Then
varf_HiveColumn_FilePath =
Trim(Replace(Replace(Split(Replace(varf_TC_HiveReferenceSheet,"$HiveColumn_FilePath
",""),"@HiveColumn_SchemaSheet")(0),"=",""),Chr(10),""))
varf_HiveColumn_SchemaSheet =
Ucase(Trim(Replace(Replace(Split(Replace(varf_TC_HiveReferenceSheet,"$HiveColumn_Fi
lePath",""),"@HiveColumn_SchemaSheet")(1),"=",""),Chr(10),"")))
If Func_Worksheet_Exist(varf_HiveColumn_SchemaSheet, ObjWB_Result) =1 Then
Set ObjWS_HiveColumn_Schema =
ObjWB_Result.Worksheets(varf_HiveColumn_SchemaSheet)
ElseIf Obj_FSO.FileExists(varf_HiveColumn_FilePath) Then
Set ObjWB_HiveColumn_Schema =
ObjXL_Main.WorkBooks.Open(varf_HiveColumn_FilePath)
If Func_Worksheet_Exist(varf_HiveColumn_SchemaSheet,
ObjWB_HiveColumn_Schema) =1 Then
Set ObjFSO_Getfile =
Obj_FSO.GetFile(varf_HiveColumn_FilePath)
vHiveResult_FileNameLocation = varf_TC_HiveOutput_Location
& Replace(Split(ObjFSO_Getfile.name,".")(0),"Tables_ColName","TabColNames_") &
vStaticTimestamp_DDMMHHMM & "." &
Obj_FSO.GetExtensionName(varf_HiveColumn_FilePath)
If Not Obj_FSO.FileExists(vHiveResult_FileNameLocation) Then

Set ObjWB_Result_HiveCol = ObjXL_Main.WorkBooks.Add


ObjWB_Result_HiveCol.Saveas
vHiveResult_FileNameLocation

ObjWB_HiveColumn_Schema.WorkSheets(varf_HiveColumn_SchemaSheet).Copy
,ObjWB_Result_HiveCol.Worksheets(1) ' copy hive column sheet to result report
For Each vSheet_New In ObjWB_Result_HiveCol.Sheets
If Ucase(vSheet_New.name) = "SHEET1" or
Ucase(vSheet_New.name) = "SHEET2" or Ucase(vSheet_New.name) = "SHEET3" Then
vSheet_New.Delete
Next
Else
Set ObjWB_Result_HiveCol =
ObjXL_Main.WorkBooks.open(vHiveResult_FileNameLocation)

ObjWB_HiveColumn_Schema.WorkSheets(varf_HiveColumn_SchemaSheet).Copy
,ObjWB_Result_HiveCol.Worksheets(1) ' copy hive column sheet to result report
End If
Set ObjWS_HiveColumn_Schema =
ObjWB_Result_HiveCol.Worksheets(varf_HiveColumn_SchemaSheet)
Else
vRemarksTC = "The sheet "& varf_HiveColumn_SchemaSheet & "
mentioned in Refcolumn is not exist in the file" & varf_HiveColumn_FilePath

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
ObjWB_HiveColumn_Schema.Close
Else
vRemarksTC = "The excel file mentioned in Refcolumn is not exist -
- " & varf_HiveColumn_FilePath

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

ElseIf
Func_Worksheet_Exist(Trim(Replace(Replace(Replace(varf_TC_HiveReferenceSheet,"@Hive
Column_SchemaSheet",""),"-",""),Chr(10),"")), ObjWB_Result) =1 Then
Set ObjWS_HiveColumn_Schema =
ObjWB_Result.WorkSheets(Trim(Replace(Replace(Replace(varf_TC_HiveReferenceSheet,"@H
iveColumn_SchemaSheet",""),"-",""),Chr(10),"")))
Else
vRemarksTC = "Ref column sheet variable may be empty or expected keywords
are missing like $HiveColumn_FilePath and @HiveColumn_SchemaSheet"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

ObjWS_ResultTC.Hyperlinks.add ObjWS_ResultTC.Range(Chr(vFuncTC_Remarks_ColNo +
64) & vTC_FuncRowNo_Value), vHiveResult_FileNameLocation,_
Chr(39) & varf_HiveColumn_SchemaSheet &
Chr(39)&"!A1", , varf_HiveColumn_SchemaSheet

' Create the column number variables to fetch the hive column values from sheet
vHiveColumn_UsedColCnt =
Cint(ObjWS_HiveColumn_Schema.UsedRange.Columns.Count)
vHiveColumn_UsedRowCnt =
Cint(ObjWS_HiveColumn_Schema.UsedRange.Rows.Count)
vRowNoHC = 1

vHC_FSD_Columns_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &


":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("FSD_Columns").Column
vHC_FSD_Data_Type_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("FSD_Data_Type").Column
vHC_Modified_ColumnNames_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("Modified_ColumnNames").Column
vHC_Modified_DataTypes_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("Modified_DataTypes").Column
vHC_HiveTable_ColumnNames_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("HiveTable_ColumnNames").Column
vHC_HiveTable_DataType_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("HiveTable_DataType").Column
vHC_AVRO_ColumnNames_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("AVRO_ColumnNames").Column
vHC_AVRO_DataType_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("AVRO_DataType").Column
vHC_Status_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Status").Column
vHC_Remarks_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Remarks").Column

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet
If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then
Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)
vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = varf_TC_UnixBox_HostName Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

' Output file name with time stamp(static time stamp from function parameter)
vHiveOutput_FileNameLocation = varf_TC_HiveOutput_Location & "HiveCol_" &
varf_TC_HiveTable_Name & "_" & vStaticTimestamp_DDMMHHMM & ".txt"
vHiveOutput_CommandFileLocation = varf_TC_HiveOutput_Location & "HiveCmdStruc_"
& varf_TC_HiveTable_Name & "_" & vStaticTimestamp_DDMMHHMM & ".txt"

' Write a script to dynamicaly create a hive command file and each line should have
output file
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vHiveOutput_CommandFileLocation,2,True)
vObj_HiveCmd_File_Dynamic.WriteLine "su - cdhqa " & Chr(34) & "hive --service
beeline -u
'jdbc:hive2://wupra97a0033.mylocal.com:10001/default;auth=maprsasl;saslQop=auth-
conf;ssl=true' -e '" &_
"describe " & varf_TC_HiveDatabase_Name &
"." & varf_TC_HiveTable_Name & "'" & Chr(34)
vObj_HiveCmd_File_Dynamic.Close

Obj_ExeLog.WriteLine "Below batch command will be executed through file, command


describes the hive table"
Obj_ExeLog.WriteLine "su - cdhqa " & Chr(34) & "hive --service beeline -u
'jdbc:hive2://wupra97a0033.mylocal.com:10001/default;auth=maprsasl;saslQop=auth-
conf;ssl=true' -e '" &_
"describe " & varf_TC_HiveDatabase_Name & "." &
varf_TC_HiveTable_Name & "'" & Chr(34)
Obj_ExeLog.WriteLine "The batch command is stored in location -- " &
vHiveOutput_CommandFileLocation
Obj_ExeLog.WriteBlankLines 1

' Create and Execute the Plink command file into Unix

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \
&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN & "
-pw " & vUnixConn_Server_PWD & " -m " & vHiveOutput_CommandFileLocation
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vHiveOutput_FileNameLocation & " &exit"

Obj_ExeLog.WriteLine " Below command will be executed into unix box"


Obj_ExeLog.WriteLine vExecute_CMD_Prompt
Obj_ExeLog.WriteBlankLines 1

Wshell.Run vExecute_CMD_Prompt,0,True

' Extract the output file and create dictionary object


Obj_Dict_HiveColumns_DataTypes
If Obj_FSO.FileExists(vHiveOutput_FileNameLocation) Then
Set Obj_ReadProp_File = Obj_FSO.GetFile(vHiveOutput_FileNameLocation)
If Obj_ReadProp_File.Size > 0 Then
Set ObjRead_HiveOutputFile =
Obj_FSO.OpenTextfile(vHiveOutput_FileNameLocation,1)
Do Until ObjRead_HiveOutputFile.AtEndOfStream
vReadColumnDT = ObjRead_HiveOutputFile.ReadLine
If Instr(1, vReadColumnDT, "|")>= 1 and Instr(1,
Ucase(vReadColumnDT), "COL_NAME")<= 0 and Instr(1, Ucase(vReadColumnDT),
"DATA_TYPE")<=0 and Instr(1, Ucase(vReadColumnDT), "COMMENT")<=0 Then
vReadColumnDT_Split = Split(vReadColumnDT,"|")
vReadColumnName_Value =
Ucase(Trim(vReadColumnDT_Split(1)))
vReadDataType_Value=
Ucase(Trim(vReadColumnDT_Split(2)))
If vReadColumnName_Value="" And
vReadDataType_Value="NULL" Then Exit Do
ObjDict_HiveColumns_DataTypes.Add
vReadColumnName_Value, vReadDataType_Value
On Error Resume Next ' "This key is already
associated with an element of this collection" and Error Number -- 457
ObjDict_HiveColumns_DataTypes_rep.Add
Replace(vReadColumnName_Value,"_",""), vReadDataType_Value & "|" &
vReadColumnName_Value
On error Goto 0
End If
Loop
ObjRead_HiveOutputFile.Close
Else
vRemarksTC = "The unix command output file is 0KB, no data into
file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

Else
' Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
' Match All the FSD column Names & FSD datatypes present in sheet with Hive Output
Column Names and Data Types
For vSColDT_RowCnt = 2 To vHiveColumn_UsedRowCnt
vHC_FSD_ColumnNames =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_FSD_Columns_ColNo).Value))
vHC_FSD_DataTypes =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_FSD_Data_Type_ColNo).Value))

vHC_Source_ColumnNames = Replace(vHC_FSD_ColumnNames,"-"," ")


vHC_Source_DataTypes = vHC_FSD_DataTypes

'Modify the Column names to match with standard Hive and AVRO column Names
Do While Instr(1,vHC_Source_ColumnNames,Chr(32)) > 0
vspace_pos = Instr(1,vHC_Source_ColumnNames,Chr(32))
'Multiple consecutive space will be replace by single underscore
If Mid(vHC_Source_ColumnNames,vspace_pos+1,1) = Chr(32) Then
vHC_Source_ColumnNames =
Replace(Mid(vHC_Source_ColumnNames,1,vspace_pos),Chr(32),"") &
Mid(vHC_Source_ColumnNames,vspace_pos+1)
Else
vHC_Source_ColumnNames =
Replace(Mid(vHC_Source_ColumnNames,1,vspace_pos),Chr(32),"_") &
Mid(vHC_Source_ColumnNames,vspace_pos+1)
End If
Loop

vHC_Source_ColumnNames =
Replace(Replace(Replace(Replace(Replace(Replace(vHC_Source_ColumnNames,"$","_DOLLAR
_"),"%","_PCT_"),"(",""),")",""),"/","_"),"P&L","PNL")

'Modify the Data types to match with standard Hive and AVRO column Names
Select Case True
Case Instr(1,Ucase(vHC_Source_DataTypes),"DOUBLE") > 0 or
Instr(1,Ucase(vHC_Source_DataTypes),"DECIM") > 0 or
Instr(1,Ucase(vHC_Source_DataTypes),"NUMBER")
vHC_Source_DataTypes = "DOUBLE"
Case Instr(1,Ucase(vHC_Source_DataTypes),"TIME") > 0 or
Instr(1,Ucase(vHC_Source_DataTypes),"STAMP") > 0 or
Instr(1,Ucase(vHC_Source_DataTypes),"DATE") > 0
vHC_Source_DataTypes = "STRING"
Case Instr(1,Ucase(vHC_Source_DataTypes),"CHAR") > 0 or
Instr(1,Ucase(vHC_Source_DataTypes),"VAR") > 0
vHC_Source_DataTypes = "STRING"
Case Instr(1,Ucase(vHC_Source_DataTypes),"BOOL") > 0
vHC_Source_DataTypes = "BOOLEAN"
Case Trim(vHC_Source_DataTypes) = ""
vHC_Source_DataTypes = "STRING"
Case Instr(1,Ucase(vHC_Source_DataTypes),"INT") > 0
vHC_Source_DataTypes = "INT"
Case Instr(1,Ucase(vHC_Source_DataTypes),"FLOAT") > 0
vHC_Source_DataTypes = "FLOAT"
Case Else
vHC_Source_DataTypes = "STRING"
End Select

ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_ColumnNames_ColNo).Value = vHC_Source_ColumnNames
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Value = vHC_Source_DataTypes

If ObjDict_HiveColumns_DataTypes.Exists(vHC_Source_ColumnNames) Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_ColumnNames_ColNo) = vHC_Source_ColumnNames
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_DataType_ColNo) =
ObjDict_HiveColumns_DataTypes(vHC_Source_ColumnNames)
If ObjDict_HiveColumns_DataTypes(vHC_Source_ColumnNames) =
vHC_Source_DataTypes Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "PASS"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 50
Else
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Data Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_DataType_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
vStatus = "FAIL"
End If
ElseIf
ObjDict_HiveColumns_DataTypes_rep.Exists(Replace(vHC_Source_ColumnNames,"_",""))
Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_ColumnNames_ColNo) =
Split(ObjDict_HiveColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(1)
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_DataType_ColNo) =
Split(ObjDict_HiveColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(0)
If
Split(ObjDict_HiveColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(0) = vHC_Source_DataTypes Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "WARN"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Column match by replacing underscore by blank"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 15
Else
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Data Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_DataType_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
vStatus = "FAIL"
End If
Else
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_ColumnNames_ColNo) = " Not Found "
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt, vHC_Status_ColNo) =
"FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt, vHC_Remarks_ColNo) =
"FSD Column Not Exist in Hive Table"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_ColumnNames_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_ColumnNames_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
vStatus = "FAIL"
End If
Next

' Match All the Hive Output Column Names with FSD column Names present in sheet
( to find extra columns in hive )
For vSColDT_RowCnt = 2 To vHiveColumn_UsedRowCnt
vHC_Source_ColumnNames =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_ColumnNames_ColNo).Value))
vHC_Source_DataTypes =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Value))
ObjDict_SourceColumns_DataTypes.Add vHC_Source_ColumnNames,
vHC_Source_DataTypes
On Error Resume Next ' "This key is already associated with an element of
this collection" and Error Number -- 457
ObjDict_SourceColumns_DataTypes_rep.Add
Replace(vHC_Source_ColumnNames,"_",""), vHC_Source_DataTypes
On Error Goto 0
Next

For Each vHiveColCnt in ObjDict_HiveColumns_DataTypes


If Not ObjDict_SourceColumns_DataTypes.Exists(vHiveColCnt) and
vHiveColCnt <> "BZ_DATE" and vHiveColCnt <> "BUSINESSDATE" and Not
ObjDict_SourceColumns_DataTypes_rep.Exists(Replace(vHiveColCnt,"_","")) Then
vHiveColumn_UsedRowCnt = vHiveColumn_UsedRowCnt + 1
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_HiveTable_ColumnNames_ColNo) = vHiveColCnt
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_HiveTable_DataType_ColNo) = ObjDict_HiveColumns_DataTypes(vHiveColCnt)
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_HiveTable_ColumnNames_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_HiveTable_DataType_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_Remarks_ColNo) = "Extra Column Found in Hive Table"
vStatus = "FAIL"
End If
Next
'AVRO Validation
If varf_TC_AVRO_Location <> Empty Or varf_TC_AVRO_Location <> "" Then

' Output AVRO file name with time stamp(static time stamp from function
parameter)
If Mid(Trim(varf_TC_HiveOutput_Location),
len(Trim(varf_TC_HiveOutput_Location)),1) <> "\" Then varf_TC_HiveOutput_Location =
Trim(varf_TC_HiveOutput_Location) & "\"
vAVROutput_FileNameLocation = varf_TC_HiveOutput_Location &
"AVROColCMP_" & varf_TC_HiveTable_Name & "_" & vStaticTimestamp_DDMMHHMM & ".txt"

' Create and Execute the Plink command file into Unix

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &
"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " su - cdhqa 'cat " &
varf_TC_AVRO_Location & "'"
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vAVROutput_FileNameLocation & " &exit"

Obj_ExeLog.WriteLine " Below AVRO command will be executed into unix box"
Obj_ExeLog.WriteLine vExecute_CMD_Prompt
Obj_ExeLog.WriteBlankLines 1

Wshell.Run vExecute_CMD_Prompt,0,True

' Extract the output file and create dictionary object


Obj_Dict_HiveColumns_DataTypes
If Obj_FSO.FileExists(vAVROutput_FileNameLocation) Then
Set Obj_ReadProp_File =
Obj_FSO.GetFile(vAVROutput_FileNameLocation)
If Obj_ReadProp_File.Size > 0 Then
Set ObjRead_HiveOutputFile =
Obj_FSO.OpenTextfile(vAVROutput_FileNameLocation,1)
vCompleteAVRO = ObjRead_HiveOutputFile.ReadAll
ObjRead_HiveOutputFile.Close
Set ObjRead_HiveOutputFile =
Obj_FSO.OpenTextfile(vAVROutput_FileNameLocation,2,True)
vCompleteAVRO =
Replace(Replace(Replace(Replace(Replace(vCompleteAVRO,Chr(10),""),Chr(13),"")," ",
""),"},","}," & Chr(10)),Chr(34) & "fields" & Chr(34) & ":", Chr(10) & Chr(34) &
"fields" & Chr(34) & ":")
ObjRead_HiveOutputFile.Write vCompleteAVRO
ObjRead_HiveOutputFile.Close
Set ObjRead_HiveOutputFile =
Obj_FSO.OpenTextfile(vAVROutput_FileNameLocation,1)
Do Until ObjRead_HiveOutputFile.AtEndOfStream
vReadColumnDT =
Ucase(ObjRead_HiveOutputFile.ReadLine)
vReadColumnDT =
Replace(Replace(Replace(Replace(Replace(Replace(vReadColumnDT,Chr(34),""),"FIELDS:"
,""),"NAME:",""),"TYPE:",""),"[",""),"]","")
If Instr(1, vReadColumnDT, "{")>= 1 and Instr(1,
vReadColumnDT, "}")>= 1 Then
vReadColumnDT_Split =
Split(vReadColumnDT,",")
vReadColumnName_Value =
Ucase(Trim(Replace(Replace(Replace(Replace(vReadColumnDT_Split(0),"{",""),Chr(9),""
),Chr(10),""),Chr(13),"")))
vReadDataType_Value =
Ucase(Trim(Replace(Replace(Replace(Split(vReadColumnDT_Split(1),"}")
(0),Chr(9),""),Chr(10),""),Chr(13),"")))
ObjDict_AVROColumns_DataTypes.Add
vReadColumnName_Value, vReadDataType_Value
On Error Resume Next ' "This key is already
associated with an element of this collection" and Error Number -- 457
ObjDict_AVROColumns_DataTypes_rep.Add
Replace(vReadColumnName_Value,"_",""), vReadDataType_Value & "|" &
vReadColumnName_Value
On Error Goto 0
End If
Loop
ObjRead_HiveOutputFile.Close
Else
vRemarksTC = "The AVRO output file is 0KB, no data into
file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

Else
' Hive Ouput didn't create a file
vRemarksTC = "The AVRO output file is not created, there may
be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

For vSColDT_RowCnt = 2 To vHiveColumn_UsedRowCnt


vHC_Source_ColumnNames =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_ColumnNames_ColNo).Value))
vHC_Source_DataTypes =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Value))

If ObjDict_AVROColumns_DataTypes.Exists(vHC_Source_ColumnNames)
Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo) = vHC_Source_ColumnNames
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo) = ObjDict_AVROColumns_DataTypes(vHC_Source_ColumnNames)
If ObjDict_AVROColumns_DataTypes(vHC_Source_ColumnNames) <>
vHC_Source_DataTypes and ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "PASS" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "AVRO Data Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
vStatus = "FAIL"
ElseIf ObjDict_AVROColumns_DataTypes(vHC_Source_ColumnNames)
<> vHC_Source_DataTypes and ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Data Type didn't match with FSD" & Chr(10) & "AVRO Data
Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo).Font.ColorIndex = 3
vStatus = "FAIL"
End If
ElseIf
ObjDict_AVROColumns_DataTypes_rep.Exists(Replace(vHC_Source_ColumnNames,"_",""))
Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo) =
Split(ObjDict_AVROColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(1)
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo) =
Split(ObjDict_AVROColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(0)
If
Split(ObjDict_AVROColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(0) <> vHC_Source_DataTypes and ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "PASS" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "AVRO Data Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_DataTypes_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
vStatus = "FAIL"
ElseIf
Split(ObjDict_AVROColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(0) <> vHC_Source_DataTypes and ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Data Type didn't match with FSD" & Chr(10) & "AVRO Data
Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo).Font.ColorIndex = 3
vStatus = "FAIL"
ElseIF
Split(ObjDict_AVROColumns_DataTypes_rep(Replace(vHC_Source_ColumnNames,"_","")),"|"
)(0) <> vHC_Source_DataTypes and ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "WARN" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Column match by replacing underscore by blank" & Chr(10)
& "And also AVRO Data Type didn't match with FSD"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_DataType_ColNo).Font.ColorIndex = 3
vStatus = "FAIL"
End If
ElseIf ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "PASS" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo) = " Not Found "
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "FSD Column Not Exist in AVRO File"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Modified_ColumnNames_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
vStatus = "FAIL"
ElseIf vHC_Source_ColumnNames = "" and
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_HiveTable_ColumnNames_ColNo).Value <> "" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Extra Column Found in Hive Table" & Chr(10) & "Extra Column
Found in AVRO File"
Else
If ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "WARN" Then
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo) = " Not Found "
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "Hive Column match by replacing underscore by blank" &
Chr(10) & "FSD Column Not Exist in AVRO File"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo).Font.ColorIndex = 3
vStatus = "FAIL"
Else
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo) = " Not Found "
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Remarks_ColNo) = "FSD Column Not Exist in Hive Table" & Chr(10) & "FSD Column
Not Exist in AVRO File"
ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_AVRO_ColumnNames_ColNo).Font.ColorIndex = 3
vStatus = "FAIL"
End If
End If
Next
' Match All the Hive Output Column Names with FSD column Names present in sheet
( to find extra columns in hive )
For Each vHiveColCnt in ObjDict_AVROColumns_DataTypes
If Not ObjDict_SourceColumns_DataTypes.Exists(vHiveColCnt) and
vHiveColCnt <> "BZ_DATE" and vHiveColCnt <> "BUSINESSDATE" and Not
ObjDict_HiveColumns_DataTypes.Exists(vHiveColCnt) Then
vHiveColumn_UsedRowCnt = vHiveColumn_UsedRowCnt + 1
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_AVRO_ColumnNames_ColNo) = vHiveColCnt
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_AVRO_DataType_ColNo) = ObjDict_AVROColumns_DataTypes(vHiveColCnt)
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_AVRO_ColumnNames_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_AVRO_DataType_ColNo).Font.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_Status_ColNo) = "FAIL"
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_Status_ColNo).Interior.ColorIndex = 3
ObjWS_HiveColumn_Schema.Cells(vHiveColumn_UsedRowCnt,
vHC_Remarks_ColNo) = "Extra Column Found in AVRO FILE"
vStatus = "FAIL"
End If
Next
End If

'Draw borders in the result report dynwmically


ObjWS_HiveColumn_Schema.Range("A1:" & Chr(vHiveColumn_UsedColCnt +64 ) &
vHiveColumn_UsedRowCnt).Borders.LineStyle = xlContinuous
ObjWS_HiveColumn_Schema.Range("A1:" & Chr(vHiveColumn_UsedColCnt +64 ) &
vHiveColumn_UsedRowCnt).Borders.color = vbBlack

If vStatus <> "FAIL" Then vStatus = "PASS" ' Overall status of the function

ObjWB_Result_HiveCol.Save
ObjWB_Result_HiveCol.close

Set ObjDict_SourceColumns_DataTypes = Nothing


Set ObjDict_HiveColumns_DataTypes = Nothing
Set ObjDict_AVROColumns_DataTypes = Nothing
Set Wshell = Nothing
Set ObjWB_HiveColumn_Schema = Nothing
Set ObjWS_HiveColumn_Schema = Nothing
Set ObjWS_UnixConnection_Sheet = Nothing
Set Obj_ReadProp_File = Nothing
Set vObj_HiveCmd_File_Dynamic = Nothing
Set ObjRead_HiveOutputFile = Nothing

End Function

Public Function f_Unix_Environment_Validation(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,
ObjWB_Master_Data, _

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

Set Wshell = CreateObject("Wscript.Shell")


' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If Mid(Trim(varf_TC_Evidence_Location),
len(Trim(varf_TC_Evidence_Location)),1) <> "\" Then varf_TC_Evidence_Location =
Trim(varf_TC_Evidence_Location) & "\"
vUnix_TestUnixCommand = varf_TC_Evidence_Location &
"vUnix_TestUnixCommand" & vStaticTimestamp_DDMMHHMM & ".txt"
vUnix_TestUnixCommand_Output = varf_TC_Evidence_Location &
"vUnix_TestUnixCommand_Output" & vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_TestUnixCommand,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_TestUnixCommand,2,True)
Redim preserve command(0)
command(0) = "echo hostname"
' Write a test command to a input file
call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) &


":" & "&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t "
& varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " &
vUnix_TestUnixCommand
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_TestUnixCommand_Output & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True

If Obj_FSO.FileExists(vUnix_TestUnixCommand_Output) Then
Set Obj_ReadOutput_File =
Obj_FSO.GetFile(vUnix_TestUnixCommand_Output)
If Obj_ReadOutput_File.Size > 0 Then
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_TestUnixCommand_Output,1)
vFlag ="NotFound"
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
If Instr(vReadColumnDT,
lcase(varf_TC_SystemName)&"hostname") Then
vFlag = "Found"
Exit Do
End If
Loop

If vFlag = "Found" Then


vRemarksTC = "Able to establish the unix connection
successfully"
vStatus = "PASS"
Obj_ExeLog.WriteLine vRemarksTC
Else
vRemarksTC = "Unix connection failed, Check the
command output file for error"
vStatus = "FAIL"
Obj_ExeLog.WriteLine vRemarksTC
End If

End If
End If
vFlag=""
End Function

Public Function f_Hive_Environment_Validation(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))
varf_TC_Hive_Url_Location = Trim(Obj_Dict_RegTC("HIVE_URL_Location"))
varf_TC_Hive_Url = Trim(Obj_Dict_RegTC("HIVE_URL"))
varf_RC_Hive_Query =Trim(Obj_Dict_RegTC("HIVE_QUERY"))

Set Wshell = CreateObject("Wscript.Shell") ' Extract the unix details -USN, PWD,
Plink location, PSFTP location from Unix Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1
vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column
vHiveURL_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A"
& vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Hive_URL").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vHiveURL_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vHiveURL_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If Mid(Trim(varf_TC_Evidence_Location),
len(Trim(varf_TC_Evidence_Location)),1) <> "\" Then varf_TC_Evidence_Location =
Trim(varf_TC_Evidence_Location) & "\"
vHive_Command = varf_TC_Evidence_Location & "vHiveCommand" &
vStaticTimestamp_DDMMHHMM & ".txt"
vHive_CommandOutput = varf_TC_Evidence_Location & "vHive_CommandOutput"
& vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vHive_Command,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vHive_Command,2,True)
Redim preserve command(0)
command(0) = "hive --service beeline -u " & chr(34) &
vHiveURL_Location & chr(34) & " -e " & chr(34) & varf_RC_Hive_Query & ";" &
chr(34)
call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &


"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " & vHive_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vHive_CommandOutput
Wshell.Run vExecute_CMD_Prompt,0,True

Set vReadFile = Obj_FSO.OpenTextfile(vHive_CommandOutput,1)


strLine = vReadFile.ReadAll

If Instr(strline,"ERROR") > 0 Then


vStatus = "FAIL"
Obj_ExeLog.WriteLine "There is some problem in executing Hive
Queries and " & "Test case is Failed "
Obj_ExeLog.WriteBlankLines 1
Else If Instr(strline,"qa_") > 0 Then
vStatus = "PASS"
Obj_ExeLog.WriteLine "Hive Query is working fine and the" & "Test Case
is Passed "
Obj_ExeLog.WriteBlankLines 1
End If
End if

End Function

Public Function f_SprXD_Environment_Validation(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vUnixConn_SpringXD_Version_ColNo =
ObjWS_UnixConnection_Sheet.Range("A" & vRowNoUC & ":" &
Chr(vUnixConnection_UsedColCnt + 64) & vRowNoUC).Find("SpringXD_Version").Column

vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column
For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt
If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vSpringXD_Version =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_SpringXD_Version_ColNo)
.Value)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

'OutPut file where command has to be written to execute

If Mid(Trim(varf_TC_Evidence_Location),
len(Trim(varf_TC_Evidence_Location)),1) <> "\" Then varf_TC_Evidence_Location =
Trim(varf_TC_Evidence_Location) & "\"
vUnix_TestSpringXD_Command = varf_TC_Evidence_Location &
"vUnix_TestSpingXD_Command" & vStaticTimestamp_DDMMHHMM & ".txt"
vUnix_TestSpringXD_Command_Output = varf_TC_Evidence_Location &
"vUnix_TestSpingXD_Command_Output" & vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_TestSpringXD_Command,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_TestSpringXD_Command,2,True)

' Write command to launch the spring XD


Redim preserve command(0)
command(0) = "cd /opt/cdhqa/ ;/opt/cdhqa/utilities/spring-xd/spring-xd-" &
vSpringXD_Version & ".RELEASE/shell/bin/xd-shell module list; echo ExitCode - $?"
call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command

' Create and Execute the Plink command file into Unix

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN & "
-pw " & vUnixConn_Server_PWD & " -m " & vUnix_TestSpringXD_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_TestSpringXD_Command_Output & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True

If Obj_FSO.FileExists(vUnix_TestSpringXD_Command_Output) Then
Set Obj_ReadOutput_File =
Obj_FSO.GetFile(vUnix_TestSpringXD_Command_Output)
vFlag ="NotFound"
If Obj_ReadOutput_File.Size > 0 Then
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_TestSpringXD_Command_Output,1)
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
If Instr(vReadColumnDT, "ExitCode") Then
vExitCodeVal = Split(vReadColumnDT,"-")
If trim(vExitCodeVal(1)) = "0" Then
vRemarksTC = "SpringXD is launched and the
connection is successful"
vStatus = "PASS"
Obj_ExeLog.WriteLine vRemarksTC
vFlag = "Found"
Exit do
End If
End If
Loop
ObjRead_OutputFile.Close

If vFlag = "NotFound" Then


vRemarksTC = "Launching SpringXD failed,some issue in
connecting"
vStatus = "FAIL"
Obj_ExeLog.WriteLine vRemarksTC
End If
Else
vRemarksTC = "The unix command output file is 0KB, no data
into file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
' When Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
vFlag = ""

End Function

Public Function f_clear_environment(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC,


ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main, ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))
varf_TC_HDFSLocation = Trim(Obj_Dict_RegTC("HDFS_FileName"))
varf_TC_BusinessDate = Trim(Obj_Dict_RegTC("BusinessDate"))
varf_TC_SourceSystem = Trim(Obj_Dict_RegTC("SourceSystem"))

Set Wshell = CreateObject("Wscript.Shell")


' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If Mid(Trim(varf_TC_Evidence_Location), len(Trim(varf_TC_Evidence_Location)),1)
<> "\" Then varf_TC_Evidence_Location = Trim(varf_TC_Evidence_Location) & "\"
vClear_Command = varf_TC_Evidence_Location & ucase(varf_TC_SourceSystem) &
"_vClearCommand" & vStaticTimestamp_DDMMHHMM & ".txt"
vClear_CommandOutput = varf_TC_Evidence_Location & ucase(varf_TC_SourceSystem)
& "_vClearCommandOutput" & vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vClear_Command,true
Set vObj_HiveCmd_File_Dynamic = Obj_FSO.OpenTextFile(vClear_Command,2,True)
Redim preserve command(0)
command(0) = "ls /opt/cdhqa/logs/" & varf_TC_SourceSystem & "/" &
varf_TC_BusinessDate & ".log" & ";" & "echo ExitCode = $?"
' Write a test command to a input file
call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN & "
-pw " & vUnixConn_Server_PWD & " -m " & vClear_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " & vClear_CommandOutput & "
&exit"

Wshell.Run vExecute_CMD_Prompt,0,True

Set vReadFile = Obj_FSO.OpenTextfile(vClear_CommandOutput,1)


strLine = vReadFile.ReadAll

If Instr(strline,"ExitCode = 0") > 0 Then


Obj_ExeLog.WriteLine "Log File Exists. Hence Removing the Log File"
vLog_ClearCommandrm = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vLog_ClearCommandrm" & vStaticTimestamp_DDMMHHMM &
".txt"
vLog_ClearCommandOutputrm = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vLog_ClearCommandOutputrm" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vLog_ClearCommandrm,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vLog_ClearCommandrm,2,True)
Redim preserve command(0)
command(0) = "rm -r /opt/cdhqa/logs/" & varf_TC_SourceSystem & "/" &
varf_TC_BusinessDate & ".log" & ";" & "echo ExitCode = $?"

call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &
"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN
& " -pw " & vUnixConn_Server_PWD & " -m " & vLog_ClearCommandrm
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vLog_ClearCommandOutputrm & " &exit"

Wshell.Run vExecute_CMD_Prompt,0,True

Set vReadFile = Obj_FSO.OpenTextfile(vLog_ClearCommandOutputrm,1)


strLine = vReadFile.ReadAll

If Instr(strline,"ExitCode = 0") > 0 Then

vStatus = "PASS"
Obj_ExeLog.WriteLine "Successfully removed the Log File for the
businessdate" & varf_TC_BusinessDate & " .Test case is passed "

Else
vStatus = "FAIL"
Obj_ExeLog.WriteLine "Failed in removing the Log File for the
businessdate " & varf_TC_BusinessDate & " .Test Case is Failed "

End if

Else
Obj_ExeLog.WriteLine "There is no Log File Exists for the businessdate
" & varf_TC_BusinessDate & " . Hence no need to perform any action"
vStatus = "PASS"

End if

vHDFS_ClearCommand = varf_TC_Evidence_Location &


ucase(varf_TC_SourceSystem) & "_vHDFS_ClearCommand" & vStaticTimestamp_DDMMHHMM &
".txt"
vHDFS_ClearCommandOutput = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vHDFS_ClearCommandOutput" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vHDFS_ClearCommand,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vHDFS_ClearCommand,2,True)
Redim preserve command(0)
command(0) = "hadoop fs -test -e " & varf_TC_HDFSLocation & "=" &
varf_TC_BusinessDate & ";" & "echo ExitCode = $?"
call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd


\ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN
& " -pw " & vUnixConn_Server_PWD & " -m " & vHDFS_ClearCommand
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vHDFS_ClearCommandOutput & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True

Set vReadFile = Obj_FSO.OpenTextfile(vHDFS_ClearCommandOutput,1)


strLine = vReadFile.ReadAll
If Instr(strline,"ExitCode = 0") > 0 Then
Obj_ExeLog.WriteLine "Hadoop location Exists"
vHDFS_ClearCommandrm = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vHDFS_ClearCommandrm" & vStaticTimestamp_DDMMHHMM &
".txt"
vHDFS_ClearCommandOutputrm = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vHDFS_ClearCommandOutputrm" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vHDFS_ClearCommandrm,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vHDFS_ClearCommandrm,2,True)
Redim preserve command(0)
command(0) = "hadoop fs -rm -r " & varf_TC_HDFSLocation & "=" &
varf_TC_BusinessDate & ";" & "echo ExitCode = $?"

call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &


"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " &
vHDFS_ClearCommandrm
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vHDFS_ClearCommandOutputrm & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True

Set vReadFile =
Obj_FSO.OpenTextfile(vHDFS_ClearCommandOutputrm,1)
strLine = vReadFile.ReadAll
If Instr(strline,"ExitCode = 0") > 0 Then
vStatus = "PASS"
Obj_ExeLog.WriteLine "Successfully removed the HDFS Folder
for the businessdate" & varf_TC_BusinessDate & " .Test case is passed "
Else
vStatus = "FAIL"
Obj_ExeLog.WriteLine vstatus & "Failed in removing the HDFS
folder for the businessdate " & varf_TC_BusinessDate & " .Test Case is Failed "
End if

Else
Obj_ExeLog.WriteLine "There is no HDFS Folder for the
businessdate " & varf_TC_BusinessDate & " . Hence no need to perform any action"
vstatus="PASS"
End if

Set ObjWS_UnixConnection_Sheet = Nothing


Set Wshell = Nothing

End Function

Public Function f_DataIngestion_Autosys(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC,


ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main, ObjWB_Master_Data, _
vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)

'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location
'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_SystemName = Trim(Obj_Dict_RegTC("SystemName"))
varf_TC_BusinessDate = Trim(Obj_Dict_RegTC("BusinessDate"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))
varf_AutosysBoxJob =
Trim(Obj_Dict_RegTC("Autosys_BoxJobName"))
varf_AutosysChildJob =
Trim(Obj_Dict_RegTC("Autosys_ChildJobName"))

Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)
vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1
vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
vChildJobsSplit = split(Trim(varf_AutosysChildJob),",")

If Mid(Trim(varf_TC_Evidence_Location), len(Trim(varf_TC_Evidence_Location)),1)
<> "\" Then varf_TC_Evidence_Location = Trim(varf_TC_Evidence_Location) & "\"
vAutosys_KillCommand = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosys_KillCommand" & vStaticTimestamp_DDMMHHMM & ".txt"
vAutosys_KillCommandOutput = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosys_KillCommandOutput" & vStaticTimestamp_DDMMHHMM &
".txt"
Obj_FSO.CreateTextFile vAutosys_KillCommand,true
Set vObj_Cmd_File_Dynamic =
Obj_FSO.OpenTextFile(vAutosys_KillCommand,2,True)
vObj_Cmd_File_Dynamic.Write "source ./.profile;"
For i = 0 To ubound(vChildJobsSplit)
vObj_Cmd_File_Dynamic.Write "sendevent -e KILLJOB -J " &
vChildJobsSplit(i) & ";"
Next
vObj_Cmd_File_Dynamic.Write "sendevent -e KILLJOB -J " &
Trim(varf_AutosysBoxJob) & ";" & "sleep 10" & ";" & "autorep -J " &
Trim(varf_AutosysBoxJob) & ";"
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &
"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " &
vAutosys_KillCommand
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vAutosys_KillCommandOutput
Wshell.Run vExecute_CMD_Prompt,0,True

'To check If any autosys Jobs are still in RU Status after killing them
For i = 0 To ubound(vChildJobsSplit)
Set vReadFile =
Obj_Fso.Opentextfile(vAutosys_KillCommandOutput,1)
Do until vReadFile.AtEndOfStream
vline = vReadFile.ReadLine
If Instr(replace(vline," ",""),vChildJobsSplit(i)) Then
'msgbox replace(vline," ","")
fileval = split(trim(vline)," ")
jobstatusval_su = fileval(ubound(fileval)-1)
If (Instr(split(vline,vChildJobsSplit(i))(1),"RU") >
0 and jobstatusval_ru=trim("RU")) Then
Obj_ExeLog.WriteLine split(trim(vline)," ")(0) & "
Job is Still Running"
JobsRunning = JobsRunning + 1
End If
End If
Loop
Next
If JobsRunning > 0 Then
Obj_ExeLog.WriteLine "One or more jobs are still not
Terminated. Hence stopping from trigerring the box job"
vStatus="FAIL"
Exit Function
else
Obj_ExeLog.WriteLine "The Child jobs and the Box job is Killed.
Hence trigerring the Box Job"
End If

'Trigerring the Box Job


vAutosysBox_Command = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosysBox_Command" & vStaticTimestamp_DDMMHHMM & ".txt"
vAutosysBox_CommandOutput = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosysBox_CommandOutput" & vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vAutosysBox_Command,true
Set vObj_Cmd_File_Dynamic =
Obj_FSO.OpenTextFile(vAutosysBox_Command,2,True)
vObj_Cmd_File_Dynamic.Write "source ./.profile;sendevent -e
FORCE_STARTJOB -J " & Trim(varf_AutosysBoxJob) & ";"
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &
"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " &
vAutosysBox_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vAutosysBox_CommandOutput
Wshell.Run vExecute_CMD_Prompt,0,True

'Checking the Autosys Job Status


vAutosysjobCheck_Command = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosysjobCheck_Command" & vStaticTimestamp_DDMMHHMM & ".txt"
vAutosysjobCheck_CommandOutput = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosysjobCheck_CommandOutput" & vStaticTimestamp_DDMMHHMM &
".txt"
Obj_FSO.CreateTextFile vAutosysjobCheck_Command,true

k=0
Do while (k<1)
' msgbox "Value of k is " & k
For i = 0 To ubound(vChildJobsSplit) Step 1
Set vObj_Cmd_File_Dynamic =
Obj_FSO.OpenTextFile(vAutosysjobCheck_Command,2,True)
vObj_Cmd_File_Dynamic.Write "source ./.profile;autorep -J
" & Trim(varf_AutosysBoxJob) & ";"
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " &
vPlinkExe_Location_Split(0) & ":" & "&cd \ &cd " & Chr(34) &
vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " & varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " &
vAutosysjobCheck_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vAutosysjobCheck_CommandOutput
Wshell.Run vExecute_CMD_Prompt,0,True

Set vReadFile =
Obj_FSO.OpenTextFile(vAutosysjobCheck_CommandOutput,1)
Do until vReadFile.AtEndOfStream
vline = vReadFile.ReadLine
If Instr(vline,vChildJobsSplit(i)) Then
'msgbox replace(vline," ","")
fileval = split(trim(vline)," ")
If cstr(fileval(0))=cstr(vChildJobsSplit(i)) Then

' msgbox fileval(0) & "," & vChildJobsSplit(i)


jobstatusval_su = fileval(ubound(fileval)-1)

'msgbox jobstatusval_su
If (Instr(vline,jobstatusval_su) > 0 and
jobstatusval_su=trim("SU")) Then
'msgbox vline & "," & vChildJobsSplit(i)
JobsSuccess = JobsSuccess + 1
'Obj_ExeLog.WriteLine fileval(0) & " Job is
Successfull"
else
jobstatusval_fa = fileval(ubound(fileval)-2)

If (Instr(vline,jobstatusval_fa) > 0 and


jobstatusval_fa=trim("FA")) Then
JobsFailure= JobsFailure + 1
Obj_ExeLog.WriteLine fileval(0) & " Job is Failed"
End If
End If
End If
End If
loop
vObj_Cmd_File_Dynamic.close
Next

'msgbox "Success counter is " & JobsSuccess


If (JobsSuccess-1 = ubound(vChildJobsSplit)) Then
Obj_ExeLog.WriteLine "All the Child and the Box Jobs are
Successfull and the status is SU"
k=1
'To put the Box Job ON_ICE
Obj_ExeLog.WriteLine varf_AutosysBoxJob & " Job status is
changed to ON_ICE"
vAutosys_OnICECommand = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosys_OnICECommand" & vStaticTimestamp_DDMMHHMM & ".txt"
vAutosys_OnICECommandOutput = varf_TC_Evidence_Location &
varf_TC_SystemName&"vAutosys_OnICECommandOutput" & vStaticTimestamp_DDMMHHMM &
".txt"
Obj_FSO.CreateTextFile vAutosys_OnICECommand,true
Set vObj_Cmd_File_Dynamic =
Obj_FSO.OpenTextFile(vAutosys_OnICECommand,2,True)
vObj_Cmd_File_Dynamic.Write "source ./.profile;"
vObj_Cmd_File_Dynamic.Write "sendevent -e JOB_ON_ICE -J " &
Trim(varf_AutosysBoxJob) & ";"
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) &
":" & "&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t "
& varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " &
vUnixConn_Server_USN & " -pw " & vUnixConn_Server_PWD & " -m " &
vAutosys_OnICECommand
Wshell.Run vExecute_CMD_Prompt,0,True
vStatus="PASS"
Exit Function
else
JobsSuccess=0
If JobsFailure > 0 Then
Obj_ExeLog.WriteLine "Above mentioned Autosys Job is Failed
and the status is FA."
k=1
vStatus="FAIL"
Exit Function
End If
End If
wait 50

loop

End function

Public Function f_Dataingestion_Process_Script(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,
ObjWB_Master_Data, _

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location

'Initialisation of variables
varf_TC_UnixBox_HostName =Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_SystemName = Trim(Obj_Dict_RegTC("SystemName"))
varf_TC_Syntax = Trim(Obj_Dict_RegTC("Syntax"))
varf_TC_BusinessDate = Trim(Obj_Dict_RegTC("BusinessDate"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If Func_Worksheet_Exist(lcase(varf_TC_SystemName), ObjWB_Master_Data) =1 Then


Set ObjWS_Master_Data_Sheet =
ObjWB_Master_Data.WorkSheets(lcase(varf_TC_SystemName))

vMasterData_UsedColCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Columns.Count)
vMasterData_UsedRowCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vSyntax_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC &


":" & Chr(vMasterData_UsedColCnt + 64) &
vRowNoUC).Find("Syntax_Trigger_Script").Column
Dim vSyntax_Val()
i=0
For vUnixCnt = 2 To vMasterData_UsedRowCnt Step 1
If
Trim(ObjWS_Master_Data_Sheet.Cells(vUnixCnt,vSyntax_ColNo).Value) <> "" Then
ReDim preserve vSyntax_Val(i)
vSyntax_Val(i) =
Trim(ObjWS_Master_Data_Sheet.Cells(vUnixCnt,vSyntax_ColNo).Value)
i=i+1
End If
Next
Else
Print "Not Found"
End If

If Mid(Trim(varf_TC_Evidence_Location), len(Trim(varf_TC_Evidence_Location)),1)
<> "\" Then varf_TC_Evidence_Location = Trim(varf_TC_Evidence_Location) & "\"
'Create a new file to write the command to trigger the data loading script
vUnix_DataIngest_ViaScript_Command = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_DataIngest_ViaScript_Command" &
vStaticTimestamp_DDMMHHMM & ".txt"
vUnix_DataIngest_ViaScript_CommandOutput = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_DataIngest_ViaScript_CommandOutput" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_DataIngest_ViaScript_Command,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_DataIngest_ViaScript_Command,2,True)

For iCount = 0 To Ubound(vSyntax_Val) Step 1


ReDim preserve command(iCount)
command(iCount) =
Replace(vSyntax_Val(iCount),"$BZDATE",trim(varf_TC_BusinessDate)) & "; echo
ExitCode - $?"
Next

Call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command
' Create and Execute the Plink command file into Unix
Obj_ExeLog.WriteLine "Triggering DataLoading through script for all tables of
system " & ucase(varf_TC_SystemName)
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN &
" -pw " & vUnixConn_Server_PWD & " -m " & vUnix_DataIngest_ViaScript_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_DataIngest_ViaScript_CommandOutput & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True
vExitcodePassCount = 0
vExitcodeFailCount = 0

If Obj_FSO.FileExists(vUnix_DataIngest_ViaScript_CommandOutput) Then
Set Obj_ReadOutput_File =
Obj_FSO.GetFile(vUnix_DataIngest_ViaScript_CommandOutput)
If Obj_ReadOutput_File.Size > 0 Then
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_DataIngest_ViaScript_CommandOutput,1)
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
If Instr(vReadColumnDT, "ExitCode -") Then
If Instr(vReadColumnDT, "0") Then
vExitcodePassCount = vExitcodePassCount + 1
else
vExitcodeFailCount = vExitcodeFailCount + 1
End If
End If
Loop
ObjRead_OutputFile.Close

If(vExitcodeFailCount > 0) then


vRemarksTC = "DataLoading for " & vExitcodeFailCount
& " file/s is/are failed"
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine "Test Case is Failed"
vStatus = "FAIL"
Else
Obj_ExeLog.WriteLine "DataLoading is successful for
all the files"
vStatus = "PASS"
End If

Else
vRemarksTC = "The unix command output file is 0KB, no data
into file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
' When Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

End function
Public Function f_Validate_Parquet_Validation(vTC_Name, Obj_Dict_Conf,
Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,
ObjWB_Master_Data, _

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_SystemName = Trim(Obj_Dict_RegTC("SystemName"))
varf_TC_Syntax = Trim(Obj_Dict_RegTC("Syntax"))
varf_TC_BusinessDate = Trim(Obj_Dict_RegTC("BusinessDate"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))
Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If Func_Worksheet_Exist(lcase(varf_TC_SystemName), ObjWB_Master_Data) =1 Then


Set ObjWS_Master_Data_Sheet =
ObjWB_Master_Data.WorkSheets(lcase(varf_TC_SystemName))

vMasterData_UsedColCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Columns.Count)
vMasterData_UsedRowCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vHdfsLoc_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC &


":" & Chr(vMasterData_UsedColCnt + 64) & vRowNoUC).Find("HDFS_Location").Column

Dim vSyntax_Val()
i=0
For vUnixCnt = 2 To vMasterData_UsedRowCnt Step 1
ReDim preserve vHdfsLoc_Val(i)
vHdfsLoc_Val(i) =
trim(ObjWS_Master_Data_Sheet.Cells(vUnixCnt,vHdfsLoc_ColNo).Value)
i=i+1
Next
Else
vRemarksTC = "Source system " & lcase(varf_TC_SystemName)
& "sheet does not exist in the Master Data workbook"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
If Mid(Trim(varf_TC_Evidence_Location), len(Trim(varf_TC_Evidence_Location)),1)
<> "\" Then varf_TC_Evidence_Location = Trim(varf_TC_Evidence_Location) & "\"
'Create a new file to write the command to trigger the data loading script
vUnix_ParquetValidation_Command = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vUnix_ParquetValidation_Command" &
vStaticTimestamp_DDMMHHMM & ".txt"
vUnix_ParquetValidation_CommandOutput = varf_TC_Evidence_Location &
ucase(varf_TC_SourceSystem) & "_vUnix_ParquetValidation_CommandOutput" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_ParquetValidation_Command,true

Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_ParquetValidation_Command,2,True)
For iCount = 0 To Ubound(vHdfsLoc_Val) Step 1
ReDim preserve command(iCount)
command(iCount) = "hadoop fs -ls " &
Replace(vHdfsLoc_Val(iCount),"$BZDATE",trim(varf_TC_BusinessDate))
Next

Call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command
' Create and Execute the Plink command file into Unix
Obj_ExeLog.WriteLine "Parquet Validation check for all tables of system " &
ucase(varf_TC_SystemName)
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN &
" -pw " & vUnixConn_Server_PWD & " -m " & vUnix_ParquetValidation_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_ParquetValidation_CommandOutput & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True
vExitcodePassCount = 0
vExitcodeFailCount = 0

If Obj_FSO.FileExists(vUnix_ParquetValidation_CommandOutput) Then
Set Obj_ReadOutput_File =
Obj_FSO.GetFile(vUnix_ParquetValidation_CommandOutput)
If Obj_ReadOutput_File.Size > 0 Then
vPresenceCount = 0
vAbsenceCount = 0
For iCount = 0 To Ubound(vHdfsLoc_Val) Step 1
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_ParquetValidation_CommandOutput,1)
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
vSearchStr =
Trim(Replace(vHdfsLoc_Val(iCount),"$BZDATE",trim(varf_TC_BusinessDate)))
If Instr(vReadColumnDT, vSearchStr) > 0 Then
If Instr(vReadColumnDT, "parquet") Then
Obj_ExeLog.WriteLine "INFO: Parquet
file is available in this location " &
Replace(vHdfsLoc_Val(iCount),"$BZDATE",trim(varf_TC_BusinessDate))
vPresenceCount = vPresenceCount + 1
Exit Do
Else
Obj_ExeLog.WriteLine "ERROR:
Parquet file is not available in this location " &
Replace(vHdfsLoc_Val(iCount),"$BZDATE",trim(varf_TC_BusinessDate))
vAbsenceCount = vAbsenceCount + 1
End If

End If
Loop
ObjRead_OutputFile.Close
Next

If vAbsenceCount>1 Then
Obj_ExeLog.WriteLine "Parquet files are not available
for " & vAbsenceCount & "file/s"
vStatus = "FAIL"
Else
Obj_ExeLog.WriteLine "Parquet files are available for
all file/s"
vStatus = "PASS"
End If

Else
vRemarksTC = "The unix command output file is 0KB, no data
into file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
' When Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

End function

Public Function f_RecordCount_Source_TOC_HIVE(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,
ObjWB_Master_Data, _

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location
'Initialisation of variables
varf_TC_UnixBox_HostName =Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_SystemName = Trim(Obj_Dict_RegTC("SystemName"))
varf_TC_BusinessDate = Trim(Obj_Dict_RegTC("BusinessDate"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vUnixConn_HiveURL_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Hive_URL").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vHiveURL =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HiveURL_ColNo).Value)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

Set Obj_Dict_Src_Hive = CreateObject("Scripting.Dictionary")


Set Obj_Dict_SrcTable_Count = CreateObject("Scripting.Dictionary")
Set Obj_Dict_Hive_Count = CreateObject("Scripting.Dictionary")
If Func_Worksheet_Exist(lcase(varf_TC_SystemName), ObjWB_Master_Data) =1 Then
Set ObjWS_Master_Data_Sheet =
ObjWB_Master_Data.WorkSheets(lcase(varf_TC_SystemName))

vMasterData_UsedColCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Columns.Count)
vMasterData_UsedRowCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1
vSrcFileLoc_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC
& ":" & Chr(vMasterData_UsedColCnt + 64) &
vRowNoUC).Find("SourceFile_Location").Column
vSrcFileName_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC
& ":" & Chr(vMasterData_UsedColCnt + 64) & vRowNoUC).Find("SourceFile_Name").Column

vFirstLine_Header_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC


& ":" & Chr(vMasterData_UsedColCnt + 64) &
vRowNoUC).Find("FirstLine_Header").Column
vHiveTable_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC
& ":" & Chr(vMasterData_UsedColCnt + 64) & vRowNoUC).Find("Hive_Table").Column
vHiveDB_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC
& ":" & Chr(vMasterData_UsedColCnt + 64) & vRowNoUC).Find("Hive_DB").Column

If Mid(Trim(varf_TC_Evidence_Location),
len(Trim(varf_TC_Evidence_Location)),1) <> "\" Then varf_TC_Evidence_Location =
Trim(varf_TC_Evidence_Location) & "\"
vUnix_SourceCount_Command = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_SourceCount_Command" & vStaticTimestamp_DDMMHHMM &
".txt"
vUnix_SourceCount_CommandOutput = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_SourceCount_CommandOutput" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_SourceCount_Command,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_SourceCount_Command,2,True)
iCount = 0

For vRowMastCnt = 2 To vMasterData_UsedRowCnt Step 1


vSrcFile_Loc_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vSrcFileLoc_ColNo).Value
vSrcFile_Name_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vSrcFileName_ColNo).Value
vFirstLineHeader_Val =
ObjWS_Master_Data_Sheet.Cells(vRowMastCnt, vFirstLine_Header_ColNo).Value
vHiveTable_Name_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vHiveTable_ColNo).Value
vHiveDB_Name_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vHiveDB_ColNo).Value
vFirstLineHeader = Trim(Ucase(vFirstLineHeader_Val))
If Mid(Trim(vSrcFile_Loc_Val), len(Trim(vSrcFile_Loc_Val)),1) <>
"/" Then vSrcFile_Loc_Val = Trim(vSrcFile_Loc_Val) & "/"
vSrcFile_Val = vSrcFile_Loc_Val & vSrcFile_Name_Val
vReplacedSrcFile_Val =
Replace(trim(vSrcFile_Val),"$BZDATE",trim(varf_TC_BusinessDate))
ReDim preserve command(iCount)
command(iCount) = "echo " & vReplacedSrcFile_Val & ": `sed -n
'$=' " & vReplacedSrcFile_Val & "`"
iCount = iCount + 1

Obj_Dict_Src_Hive.Add vHiveTable_Name_Val, vReplacedSrcFile_Val


Next

Call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command
' Create and Execute the Plink command file into Unix
'Obj_ExeLog.WriteLine "Parquet Validation check for all tables of system " &
ucase(varf_TC_SystemName)
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN &
" -pw " & vUnixConn_Server_PWD & " -m " & vUnix_SourceCount_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_SourceCount_CommandOutput & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True

If Obj_FSO.FileExists(vUnix_SourceCount_CommandOutput) Then
Set Obj_ReadOutput_File =
Obj_FSO.GetFile(vUnix_SourceCount_CommandOutput)
If Obj_ReadOutput_File.Size > 0 Then
Select Case lcase(varf_TC_SystemName)
Case galaxy

Case Else
For Each vHiveTable in Obj_Dict_Src_Hive.Keys
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_SourceCount_CommandOutput,1)
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
vSearchStr =
Replace(trim(Obj_Dict_Src_Hive(vHiveTable)),"$BZDATE",trim(varf_TC_BusinessDate))
If Instr(vReadColumnDT, vSearchStr) > 0 Then
If vFirstLineHeader = "Y" Then
Print vReadColumnDT
Print Split(vReadColumnDT,":")(1)
vSrcCount =
clng(trim(Split(vReadColumnDT,":")(1)))-1
Print vSrcCount
Obj_Dict_SrcTable_Count.Add
trim(vHiveTable), trim(vSrcCount)
Exit Do
Else
vSrcCount =
trim(Split(vReadColumnDT,":")(1))
Obj_Dict_SrcTable_Count.Add
trim(vHiveTable), trim(vSrcCount)
Exit Do
End If
End If
Loop
ObjRead_OutputFile.Close
Next
End Select

Else
vRemarksTC = "The unix command output file is 0KB, no data
into file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
' When Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
'Fetching the Hive count for the respective system tables
vUnix_HiveCount_Command = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_HiveCount_Command" & vStaticTimestamp_DDMMHHMM &
".txt"
vUnix_HiveCount_CommandOutput = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_HiveCount_CommandOutput" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_HiveCount_Command,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_HiveCount_Command,2,True)
iCount = 0

For vRowMastCnt = 2 To vMasterData_UsedRowCnt Step 1

vHiveTable_Name_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vHiveTable_ColNo).Value
vHiveDB_Name_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vHiveDB_ColNo).Value
vHiveCountQuery = "select count(*) as " &
trim(vHiveTable_Name_Val) & " from " & vHiveDB_Name_Val & "." &
trim(vHiveTable_Name_Val) & " where businessdate=" & trim(varf_TC_BusinessDate)
ReDim preserve command(iCount)
command(iCount) = "hive --service beeline -u " & chr(34) &
"jdbc:hive2://" & vHiveURL & "/default;auth=maprsasl;saslQop=auth-conf;ssl=true" &
chr(34) & " -e " & chr(34) & vHiveCountQuery & ";" & chr(34)
iCount = iCount + 1
Next

Call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command
' Create and Execute the Plink command file into Unix
'Obj_ExeLog.WriteLine "Parquet Validation check for all tables of system " &
ucase(varf_TC_SystemName)
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN &
" -pw " & vUnixConn_Server_PWD & " -m " & vUnix_HiveCount_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_HiveCount_CommandOutput & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True

If Obj_FSO.FileExists(vUnix_HiveCount_CommandOutput) Then
Set Obj_ReadOutput_File = Obj_FSO.GetFile(vUnix_HiveCount_CommandOutput)
If Obj_ReadOutput_File.Size > 0 Then
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_HiveCount_CommandOutput,1)
vTableIterator = 0
vCountIterator = 0
For Each vHiveTable in Obj_Dict_Src_Hive.Keys
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
If Instr(1,vReadColumnDT,"|") and
Instr(1,vReadColumnDT,vHiveTable) Then
Redim preserve vTable(vTableIterator)
vTable(vTableIterator) =
Split(vReadColumnDT,"|")(1)
Print "TableName: " &
vTable(vTableIterator)

ObjRead_OutputFile.skipline

vReadColumnDT =
ObjRead_OutputFile.ReadLine
Redim preserve vCount(vTableIterator)
vCount(vTableIterator) =
Split(vReadColumnDT, "|")(1)
Print "Count: " & vCount(vTableIterator)
vTableIterator = vTableIterator + 1
Exit Do
End If
' ElseIf Instr(1,vReadColumnDT,"|") and
Instr(1,vReadColumnDT,vHiveTable) = 0 Then
' Redim preserve vCount(vCountIterator)
' vCount(vCountIterator) =
Split(vReadColumnDT, "|")(1)
' Print "Count: " & vCount(vCountIterator)
' vCountIterator = vCountIterator + 1
' End if
Loop
Next
ObjRead_OutputFile.Close

If ubound(vTable) = ubound(vCount) Then


For i = 0 to ubound(vTable)
Obj_Dict_Hive_Count.Add
trim(vTable(i)),trim(vCount(i))
Next
Else
Obj_ExeLog.WriteLine "Counts of hive tables are not
retrieved properly. Seem to be data is not available for any table"
End If

If Obj_Dict_SrcTable_Count.Count <>
Obj_Dict_Hive_Count.Count Then
Obj_ExeLog.WriteLine "Mismatch in the number of
source files and hive table"
Else
arrKeys = Obj_Dict_SrcTable_Count.Keys
For i = 0 to ubound(arrKeys) step 1
Obj_ExeLog.WriteLine "INFO: Source File Count
for " & arrKeys(i) & " is " & Obj_Dict_SrcTable_Count(arrKeys(i))
Print "INFO: Source File Count for " &
arrKeys(i) & " is " & Obj_Dict_SrcTable_Count(arrKeys(i))
Obj_ExeLog.WriteLine "INFO:Hive Count for " &
arrKeys(i) & " is " & Obj_Dict_Hive_Count(arrKeys(i))
Print "INFO:Hive Count for " & arrKeys(i) & "
is " & Obj_Dict_Hive_Count(arrKeys(i))
If Not Obj_Dict_Hive_Count.Exists(arrKeys(i))
Then
Obj_ExeLog.WriteLine "ERROR: Hive Table "
& ucase(arrKeys(i)) & "is not present in the source file list"
Print "ERROR: Hive Table " &
ucase(arrKeys(i)) & "is not present in the source file list"
vStatus = "FAIL"
ElseIf Obj_Dict_SrcTable_Count(arrKeys(i)) =
Obj_Dict_Hive_Count(arrKeys(i)) Then
Obj_ExeLog.WriteLine "INFO: Source and
Hive Count is matching"
Print "INFO: Source and Hive Count is
matching"
vStatus = "PASS"
Else
Obj_ExeLog.WriteLine "ERROR: Source and
Hive Count is not matching"
vStatus = "FAIL"
End If
Next
End If

Else
vRemarksTC = "The unix command output file is 0KB, no data
into file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
' When Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

End If

End Function

Public Function f_Validate_Log_Files(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC,


ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main, ObjWB_Master_Data, _

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location

'Initialisation of variables
varf_TC_UnixBox_HostName =Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_SystemName = Trim(Obj_Dict_RegTC("SystemName"))
varf_TC_BusinessDate = Trim(Obj_Dict_RegTC("BusinessDate"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet

If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then


Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vUnixConn_HiveURL_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Hive_URL").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = Ucase(varf_TC_UnixBox_HostName) Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vHiveURL =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HiveURL_ColNo).Value)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If Func_Worksheet_Exist(lcase(varf_TC_SystemName), ObjWB_Master_Data) =1 Then


Set ObjWS_Master_Data_Sheet =
ObjWB_Master_Data.WorkSheets(lcase(varf_TC_SystemName))

vMasterData_UsedColCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Columns.Count)
vMasterData_UsedRowCnt =
Cint(ObjWS_Master_Data_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1
vLogFileLoc_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC
& ":" & Chr(vMasterData_UsedColCnt + 64) &
vRowNoUC).Find("LogFile_Location").Column
vLogMessage_ColNo = ObjWS_Master_Data_Sheet.Range("A" & vRowNoUC
& ":" & Chr(vMasterData_UsedColCnt + 64) & vRowNoUC).Find("Log_Message").Column

If Mid(Trim(varf_TC_Evidence_Location),
len(Trim(varf_TC_Evidence_Location)),1) <> "\" Then varf_TC_Evidence_Location =
Trim(varf_TC_Evidence_Location) & "\"
vUnix_LogFileErrorMsg_Command = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_LogFileErrorMsg_Command" & vStaticTimestamp_DDMMHHMM
& ".txt"
vUnix_LogFileErrorMsg_CommandOutput = varf_TC_Evidence_Location &
ucase(varf_TC_SystemName) & "_LogFileErrorMsg_CommandOutput" &
vStaticTimestamp_DDMMHHMM & ".txt"
Obj_FSO.CreateTextFile vUnix_LogFileErrorMsg_Command,true
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vUnix_LogFileErrorMsg_Command,2,True)
iCount = 0

For vRowMastCnt = 2 To vMasterData_UsedRowCnt Step 1


vLogFile_Loc_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vLogFileLoc_ColNo).Value
vLogMessage_Val = ObjWS_Master_Data_Sheet.Cells(vRowMastCnt,
vLogMessage_ColNo).Value

If Mid(Trim(vLogFile_Loc_Val), len(Trim(vLogFile_Loc_Val)),1) <>


"/" Then vLogFile_Loc_Val = Trim(vLogFile_Loc_Val) & "/"
vLogFile_Val = vLogFile_Loc_Val & varf_TC_BusinessDate & ".log"
'ReDim preserve command(0)
'command(0) = "cat " & vLogFile_Val & " > " & vLogFilesFdr &
ucase(varf_TC_SystemName) & "_" & varf_TC_BusinessDate & ".log"
ReDim preserve command(0)
command(0) = "cat " & vLogFile_Val & "|grep 'ERROR'"

Next

Call
f_WriteCommand_TextFile( vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
Erase command
' Create and Execute the Plink command file into Unix
Obj_ExeLog.WriteLine "Checking for ERROR message in the log file for system "
& ucase(varf_TC_SystemName)
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")

vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \


&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN &
" -pw " & vUnixConn_Server_PWD & " -m " & vUnix_LogFileErrorMsg_Command
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vUnix_LogFileErrorMsg_CommandOutput & " &exit"
Wshell.Run vExecute_CMD_Prompt,0,True
vErrorMsg = "NotFound"
If Obj_FSO.FileExists(vUnix_LogFileErrorMsg_CommandOutput) Then
Set Obj_ReadOutput_File =
Obj_FSO.GetFile(vUnix_LogFileErrorMsg_CommandOutput)
If Obj_ReadOutput_File.Size > 0 Then
Set ObjRead_OutputFile =
Obj_FSO.OpenTextfile(vUnix_LogFileErrorMsg_CommandOutput,1)
Do Until ObjRead_OutputFile.AtEndOfStream
vReadColumnDT = ObjRead_OutputFile.ReadLine
If Instr(1,vReadColumnDT,"ERROR") Then
Obj_ExeLog.WriteLine "Error message found
in log file - " & chr(34) & vReadColumnDT & chr(34)
vErrorMsg = "Found"
End IF
Loop
If vErrorMsg = "NotFound" Then
Obj_ExeLog.WriteLine "No Error message found in log
file "
End If

Else
vRemarksTC = "The unix command output file is 0KB, no data
into file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
' When Hive Ouput didn't create a file
vRemarksTC = "The unix command output file is not created, there
may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
End If

End Function
Public Function f_DataUpload_into_HiveTempTable(vTC_Name, Obj_Dict_Conf,
Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,
ObjWB_Master_Data, _

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Source_DBName, varf_TC_Source_TableName,
varf_TC_Source_ColumnSheet, varf_TC_Source_Partition_WC
Dim varf_TC_QA_DatabaseName, varf_TC_QA_TableName,
varf_TC_QA_Table_HDFS_Location,
varf_TC_QA_ColumnDelimiter,varf_TC_HiveOutput_Location

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_Source_DBName = Trim(Obj_Dict_RegTC("Source_DatabaseName"))
varf_TC_Source_TableName = Trim(Obj_Dict_RegTC("Source_TableName"))
varf_TC_Source_ColumnSheet = Trim(Obj_Dict_RegTC("Source_ColumnSheet"))
varf_TC_Source_Partition_WC =
Trim(Obj_Dict_RegTC("Source_Partition_WhereClause"))
varf_TC_QA_DatabaseName = Trim(Obj_Dict_RegTC("QA_DatabaseName"))
varf_TC_QA_TableName = Trim(Obj_Dict_RegTC("QA_TableName"))
varf_TC_QA_Table_HDFS_Location =
Trim(Obj_Dict_RegTC("QA_Table_HDFS_Location"))
varf_TC_QA_ColumnDelimiter = Trim(Obj_Dict_RegTC("ColumnDelimiter"))
varf_TC_HiveOutput_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))
'Create the objects
Set ObjDict_SourceCol_Status = CreateObject("Scripting.Dictionary")
Set Wshell = CreateObject("Wscript.Shell")

' Extract the Hive column - file path and sheet name from variable
varf_TC_Source_ColumnSheet. Also copy the hive column sheet to result xl
' Establish the worksheet object for hive column available in result xl
If Instr(1, varf_TC_Source_ColumnSheet, "$HiveColumn_FilePath") > 0 And
Instr(1,varf_TC_Source_ColumnSheet,"@HiveColumn_SchemaSheet") > 0 Then
varf_HiveColumn_FilePath =
Trim(Replace(Replace(Split(Replace(varf_TC_Source_ColumnSheet,"$HiveColumn_FilePath
",""),"@HiveColumn_SchemaSheet")(0),"=",""),Chr(10),""))
varf_HiveColumn_SchemaSheet =
Trim(Replace(Replace(Split(Replace(varf_TC_Source_ColumnSheet,"$HiveColumn_FilePath
",""),"@HiveColumn_SchemaSheet")(1),"=",""),Chr(10),""))
If Func_Worksheet_Exist(varf_HiveColumn_SchemaSheet, ObjWB_Result) =1 Then
Set ObjWS_HiveColumn_Schema =
ObjWB_Result.Worksheets(varf_HiveColumn_SchemaSheet)
ElseIf Obj_FSO.FileExists(varf_HiveColumn_FilePath) Then
Set ObjWB_HiveColumn_Schema =
ObjXL_Main.WorkBooks.Open(varf_HiveColumn_FilePath)
If Func_Worksheet_Exist(varf_HiveColumn_SchemaSheet,
ObjWB_HiveColumn_Schema) =1 Then

ObjWB_HiveColumn_Schema.WorkSheets(varf_HiveColumn_SchemaSheet).Copy
,ObjWB_Result.Worksheets(vTD_UnixCrdnSheet) ' copy hive column sheet to result
report
Set ObjWS_HiveColumn_Schema =
ObjWB_Result.Worksheets(varf_HiveColumn_SchemaSheet)
Else
vRemarksTC = "The sheet "& varf_HiveColumn_SchemaSheet & "
mentioned in Refcolumn is not exist in the file" & varf_HiveColumn_FilePath

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & "Test case is failed"
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
ObjWB_HiveColumn_Schema.Close
Else
vRemarksTC = "The excel file mentioned in Refcolumn is not exist -
- " & varf_HiveColumn_FilePath

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

ElseIf
Func_Worksheet_Exist(Trim(Replace(Replace(Replace(varf_TC_Source_ColumnSheet,"@Hive
Column_SchemaSheet",""),"-",""),Chr(10),"")), ObjWB_Result) =1 Then
Set ObjWS_HiveColumn_Schema =
ObjWB_Result.WorkSheets(Trim(Replace(Replace(Replace(varf_TC_Source_ColumnSheet,"@H
iveColumn_SchemaSheet",""),"-",""),Chr(10),"")))
Else
vRemarksTC = "Ref column sheet variable may be empty or expected keywords
are missing like $HiveColumn_FilePath and @HiveColumn_SchemaSheet"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

' Create the column number variables to fetch the hive column values from sheet
vHiveColumn_UsedColCnt =
Cint(ObjWS_HiveColumn_Schema.UsedRange.Columns.Count)
vHiveColumn_UsedRowCnt =
Cint(ObjWS_HiveColumn_Schema.UsedRange.Rows.Count)
vRowNoHC = 1

vHC_Source_ColumnNames_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &


":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("Source_ColumnNames").Column
vHC_Source_DataTypes_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Source_DataTypes").Column
vHC_Primary_Key_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Primary_Key").Column
vHC_Not_Null_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Not_Null").Column
vHC_HiveTable_ColumnNames_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("HiveTable_ColumnNames").Column
vHC_HiveTable_DataType_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("HiveTable_DataType").Column
vHC_Status_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Status").Column
vHC_Remarks_ColNo = ObjWS_HiveColumn_Schema.Range("A" & vRowNoHC &
":" & Chr(vHiveColumn_UsedColCnt + 64) & vRowNoHC).Find("Remarks").Column
vHC_Actual_HiveOutput_DataType_ColNo = ObjWS_HiveColumn_Schema.Range("A" &
vRowNoHC & ":" & Chr(vHiveColumn_UsedColCnt + 64) &
vRowNoHC).Find("Actual_HiveOutput_DataType").Column

' Fetch the column Names into a variable and that will be used in command to
create temp table
For vSColDT_RowCnt = 2 To vHiveColumn_UsedRowCnt
vHC_Source_ColumnNames =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt,
vHC_Source_ColumnNames_ColNo).Value))
vHC_HiveCol_MatchStatus =
Ucase(Trim(ObjWS_HiveColumn_Schema.Cells(vSColDT_RowCnt, vHC_Status_ColNo).Value))
If vHC_Source_ColumnNames<>"" Or vHC_HiveCol_MatchStatus<>"FAIL" then
ObjDict_SourceCol_Status.Add vHC_Source_ColumnNames, vHC_HiveCol_MatchStatus
Next

For Each vHiveColNameCnt in ObjDict_SourceCol_Status


If ObjDict_SourceCol_Status(vHiveColNameCnt)<>"FAIL" Then
vHiveTemptable_ColNames = vHiveTemptable_ColNames & Chr(44) & Trim(vHiveColNameCnt)
Next
If len(vHiveTemptable_ColNames) > 1 then vHiveTemptable_ColNames =
Mid(vHiveTemptable_ColNames,2)

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet
If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then
Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = varf_TC_UnixBox_HostName Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

' Output file name with time stamp(static time stamp from function parameter)
If Mid(Trim(varf_TC_HiveOutput_Location),
len(Trim(varf_TC_HiveOutput_Location)),1) <> "\" Then varf_TC_HiveOutput_Location =
Trim(varf_TC_HiveOutput_Location) & "\"
vHiveOutput_FileNameLocation = varf_TC_HiveOutput_Location &
"HiveTempTableConfirm_" & vStaticTimestamp_DDMMHHMM & ".txt"
vHiveOutput_CommandFileLocation = varf_TC_HiveOutput_Location &
"HiveCreateCommand_TempTable_" & vStaticTimestamp_DDMMHHMM & ".txt"

' Extract the column delimiter from testdata and standardise into hive format
Select Case Trim(Ucase(varf_TC_QA_ColumnDelimiter))
Case "PIPE" varf_TC_QA_ColumnDelimiter = Chr(39) & Chr(124) & Chr(39)
Case "COMMA" varf_TC_QA_ColumnDelimiter = Chr(39) & Chr(44) & Chr(39)
Case "DOT" varf_TC_QA_ColumnDelimiter = Chr(39) & Chr(46) & Chr(39)
End Select

' Frame the Where clause


If varf_TC_Source_Partition_WC <> "" Or varf_TC_Source_Partition_WC <> Empty
then varf_TC_Source_Partition_WC = " Where " & varf_TC_Source_Partition_WC

' Frame the column Name for query


If len(vHiveTemptable_ColNames) <=1 then vHiveTemptable_ColNames = "*"

' Write a script to dynamicaly create a hive command file and each line should have
output file
Set vObj_HiveCmd_File_Dynamic =
Obj_FSO.OpenTextFile(vHiveOutput_CommandFileLocation,2,True)
vObj_HiveCmd_File_Dynamic.WriteLine "hive -e " & Chr(34) & "DROP TABLE IF EXISTS
" & varf_TC_QA_DatabaseName & "." & varf_TC_QA_TableName & ";" & Chr(34)
vObj_HiveCmd_File_Dynamic.WriteLine "hive -e " & Chr(34) & "CREATE TABLE " &
varf_TC_QA_DatabaseName & "." & varf_TC_QA_TableName & _
" ROW FORMAT DELIMITED FIELDS TERMINATED BY
" & varf_TC_QA_ColumnDelimiter & " LINES TERMINATED BY '\n' LOCATION " &_
Chr(39) & varf_TC_QA_Table_HDFS_Location &
varf_TC_QA_TableName & Chr(39) & "STORED AS TEXTFILE AS SELECT " &
vHiveTemptable_ColNames & " FROM " & _
varf_TC_Source_DBName & "." &
varf_TC_Source_TableName & varf_TC_Source_Partition_WC & ";" & Chr(34)
vObj_HiveCmd_File_Dynamic.WriteLine "hdfs dfs -ls " &
varf_TC_QA_Table_HDFS_Location & varf_TC_Source_TableName
vObj_HiveCmd_File_Dynamic.Close

Obj_ExeLog.WriteLine "The batch command file is stored in location -- " &


vHiveOutput_CommandFileLocation
Obj_ExeLog.WriteBlankLines 1

' Create and Execute the Plink command file into Unix

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \
&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN & "
-pw " & vUnixConn_Server_PWD & " -m " & vHiveOutput_CommandFileLocation
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " &
vHiveOutput_FileNameLocation & " &exit"

Obj_ExeLog.WriteLine " Below command will be executed into unix box"


Obj_ExeLog.WriteLine vExecute_CMD_Prompt
Obj_ExeLog.WriteBlankLines 1

Wshell.Run vExecute_CMD_Prompt,0,True

' Extract the output file and create dictionary object


Obj_Dict_HiveColumns_DataTypes
If Obj_FSO.FileExists(vHiveOutput_FileNameLocation) Then
Set Obj_ReadProp_File = Obj_FSO.GetFile(vHiveOutput_FileNameLocation)
If Obj_ReadProp_File.Size > 0 Then
Set ObjRead_HiveOutputFile =
Obj_FSO.OpenTextfile(vHiveOutput_FileNameLocation,1)
Do Until ObjRead_HiveOutputFile.AtEndOfStream
vReadFileLocation =
Ucase(Trim(Replace(ObjRead_HiveOutputFile.ReadLine,Chr(32),"")))
If Instr(1,vReadFileLocation,"000000_0") > 0 Then
vReadFileLocation = "found"
Exit Do
End If
Loop
ObjRead_HiveOutputFile.Close
Else
vRemarksTC = "The unix command output file is 0KB, no data into
file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

Else
vRemarksTC = "The unix command output file is not created, there may be
error or issue with command while executing"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

If vReadFileLocation = "found" Then


vStatus = "PASS"
vRemarksTC = "Temp table is successfully created, ouput file is available
in the HDFS location" & varf_TC_QA_Table_HDFS_Location & varf_TC_Source_TableName
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Else
vStatus = "FAIL"
vRemarksTC = "The ouput file is not available in the HDFS location" &
vHiveOutput_CommandFileLocation & ", Check the table exist"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

End Function

Public Function f_CopyFileFrom_HDFS_to_Unix(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)

'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_QA_Table_HDFSLocation,
varf_TC_Unix_QA_FolderLocation

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_QA_Table_HDFSLocation = Trim(Obj_Dict_RegTC("QA_Table_HDFSLocation"))
varf_TC_Unix_QA_FolderLocation =
Trim(Obj_Dict_RegTC("Unix_QA_FolderLocation"))
varf_TC_HDFS_FileName = Trim(Obj_Dict_RegTC("HDFS_FileName"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

'Create the objects


Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet
If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then
Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = varf_TC_UnixBox_HostName Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

' Output file name with time stamp(static time stamp from function parameter)
If Mid(Trim(varf_TC_QA_Table_HDFSLocation),
len(Trim(varf_TC_QA_Table_HDFSLocation)),1) <> "/" Then
varf_TC_QA_Table_HDFSLocation = Trim(varf_TC_QA_Table_HDFSLocation) & "/"
If Mid(Trim(varf_TC_Unix_QA_FolderLocation),
len(Trim(varf_TC_Unix_QA_FolderLocation)),1) <> "/" Then
varf_TC_Unix_QA_FolderLocation = Trim(varf_TC_Unix_QA_FolderLocation) & "/"
If Mid(Trim(varf_TC_Evidence_Location), len(Trim(varf_TC_Evidence_Location)),1)
<> "\" Then varf_TC_Evidence_Location = Trim(varf_TC_Evidence_Location) & "\"
vHDFS_FileCopyConfirmation = varf_TC_Evidence_Location &
"HDFS_FileCopyConfirmation_" & vStaticTimestamp_DDMMHHMM & ".txt"
vHDFS_GETCommand = varf_TC_Evidence_Location & "HDFS_GetCommand_" &
vStaticTimestamp_DDMMHHMM & ".txt"

' Write a script to dynamicaly create a hive command file and each line should have
output file
Set vObj_HiveCmd_File_Dynamic = Obj_FSO.OpenTextFile(vHDFS_GETCommand,2,True)
vObj_HiveCmd_File_Dynamic.WriteLine "rm -r " & varf_TC_Unix_QA_FolderLocation &
varf_TC_HDFS_FileName
vObj_HiveCmd_File_Dynamic.WriteLine "hdfs dfs -get " &
varf_TC_QA_Table_HDFSLocation & "* " & varf_TC_Unix_QA_FolderLocation &
varf_TC_HDFS_FileName
vObj_HiveCmd_File_Dynamic.WriteLine "ls " & varf_TC_Unix_QA_FolderLocation &
varf_TC_HDFS_FileName
vObj_HiveCmd_File_Dynamic.Close

' Create and Execute the Plink command file into Unix

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" & "&cd \
&cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink " &
varf_TC_UnixBox_HostName
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " -l " & vUnixConn_Server_USN & "
-pw " & vUnixConn_Server_PWD & " -m " & vHDFS_GETCommand
vExecute_CMD_Prompt = vExecute_CMD_Prompt & " > " & vHDFS_FileCopyConfirmation

Wshell.Run vExecute_CMD_Prompt,0,True
If Obj_FSO.FileExists(vHDFS_FileCopyConfirmation) Then
Set Obj_ReadProp_File = Obj_FSO.GetFile(vHDFS_FileCopyConfirmation)
If Obj_ReadProp_File.Size > 0 Then
Set vObjRead_HDFSFileConfirm =
Obj_FSO.OpenTextFile(vHDFS_FileCopyConfirmation,1)
vUnix_FileLocation_available =
Replace(Replace(Trim(vObjRead_HDFSFileConfirm.ReadAll),Chr(10),""),Chr(13),"")
If StrComp(varf_TC_Unix_QA_FolderLocation & varf_TC_HDFS_FileName,
vUnix_FileLocation_available) = 0 Then
vStatus = "PASS"
vRemarksTC = vUnix_FileLocation_available & " File copied
from HDFS to Unix successfully"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Else
vStatus = "FAIL"
vRemarksTC = varf_TC_Unix_QA_FolderLocation &
varf_TC_HDFS_FileName & " Unable to copy file from HDFS to Unix"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
End If
vObjRead_HDFSFileConfirm.Close
Else
vRemarksTC = "The unix command output file is 0KB, no data into
file. there may be error or issue with command while executing"

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

Else
vRemarksTC = "The unix command output file is not created, there may be
error or issue with command while executing"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

Set ObjWS_UnixConnection_Sheet = Nothing


Set Obj_ReadProp_File = Nothing
Set Wshell = Nothing

End Function

Public Function f_CopyFileFrom_UNIX_to_Local(vTC_Name, Obj_Dict_Conf,


Obj_Dict_RegTC, ObjWS_ResultTC, ObjWB_Result, Obj_FSO,
ObjXL_Main,ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)
'Decalaration Of variables
Dim varf_TC_UnixBox_HostName, varf_TC_Unix_QA_FolderLocation,
varf_TC_Unix_FileName, varf_TC_QA_TargetFileLocation, varf_TC_Evidence_Location

'Initialisation of variables
varf_TC_UnixBox_HostName = Trim(Obj_Dict_RegTC("UnixBox_HostName"))
varf_TC_Unix_QA_FolderLocation =
Trim(Obj_Dict_RegTC("Unix_QA_FolderLocation"))
varf_TC_Unix_FileName = Trim(Obj_Dict_RegTC("Unix_FileName"))
varf_TC_QA_TargetFileLocation =
Trim(Obj_Dict_RegTC("QA_TargetFile_into_Local"))
varf_TC_Evidence_Location = Trim(Obj_Dict_RegTC("Evidence_Location"))

'Create the objects


Set Wshell = CreateObject("Wscript.Shell")

' Extract the unix details -USN, PWD, Plink location, PSFTP location from Unix
Connection details sheet
If Func_Worksheet_Exist(vTD_UnixCrdnSheet, ObjWB_Result) =1 Then
Set ObjWS_UnixConnection_Sheet =
ObjWB_Result.Worksheets(vTD_UnixCrdnSheet)

vUnixConnection_UsedColCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Columns.Count)
vUnixConnection_UsedRowCnt =
Cint(ObjWS_UnixConnection_Sheet.UsedRange.Rows.Count)
vRowNoUC = 1

vUnixConn_HostName_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &


vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixBox_HostName").Column
vUnixConn_Server_USN_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_USN").Column
vUnixConn_Server_PWD_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("UnixServer_PWD").Column
vUnixConn_Port_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Port").Column
vUnixConn_Protocol_Type_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("Unix_Protocol_Type").Column
vPlinkExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PlinkExe_Location").Column
vPSFTPExe_Location_ColNo = ObjWS_UnixConnection_Sheet.Range("A" &
vRowNoUC & ":" & Chr(vUnixConnection_UsedColCnt + 64) &
vRowNoUC).Find("PSFTPExe_Location").Column

For vUnixRowCnt = 2 to vUnixConnection_UsedRowCnt


If
Ucase(Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_HostName_ColNo).V
alue)) = varf_TC_UnixBox_HostName Then
vUnixConn_Server_USN =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_USN_ColNo).Value
)
vUnixConn_Server_PWD =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Server_PWD_ColNo).Value
)
vUnixConn_Port =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Port_ColNo).Value)
vUnixConn_Protocol_Type =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vUnixConn_Protocol_Type_ColNo).Va
lue)
vPlinkExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPlinkExe_Location_ColNo).Value)
vPSFTPExe_Location =
Trim(ObjWS_UnixConnection_Sheet.Cells(vUnixRowCnt,vPSFTPExe_Location_ColNo).Value)
vUnixConn_DetailsFound = "Found"
Exit For
End If
Next
If vUnixConn_DetailsFound = "Found" Then
vUnixConn_DetailsFound = Empty
Else
vRemarksTC = "Unix Credential sheet does not have the Host ~" &
varf_TC_UnixBox_HostName & "~, mentioned in the test case " & vTC_Name

ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value = vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
End If
Else
vRemarksTC = "Unix Credential sheet "& vTD_UnixCrdnSheet & " not found in
the test data file, Please add the sheet and rerun the regression suite"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC
Obj_ExeLog.WriteLine vRemarksTC & " Test case is failed "
Obj_ExeLog.WriteBlankLines 1
vStatus = "FAIL"
Exit Function
End If

' Output file name with time stamp(static time stamp from function parameter)
If Mid(Trim(varf_TC_Unix_QA_FolderLocation),
len(Trim(varf_TC_Unix_QA_FolderLocation)),1) <> "/" Then
varf_TC_Unix_QA_FolderLocation = Trim(varf_TC_Unix_QA_FolderLocation) & "/"
If Mid(Trim(varf_TC_QA_TargetFileLocation),
len(Trim(varf_TC_QA_TargetFileLocation)),1) <> "\" Then
varf_TC_QA_TargetFileLocation = Trim(varf_TC_QA_TargetFileLocation) & "\"
If Mid(Trim(varf_TC_Evidence_Location), len(Trim(varf_TC_Evidence_Location)),1)
<> "\" Then varf_TC_Evidence_Location = Trim(varf_TC_Evidence_Location) & "\"
vUnix_GETCommand = varf_TC_Evidence_Location & "Unix_GetCommand_" &
vStaticTimestamp_DDMMHHMM & ".txt"

' Delete the target file already exist in the location


If Obj_FSO.FileExists(varf_TC_QA_TargetFileLocation & varf_TC_Unix_FileName)
Then Obj_FSO.DeleteFile(varf_TC_QA_TargetFileLocation & varf_TC_Unix_FileName)

' Write a script to dynamicaly create a hive command file and each line should have
output file
Set vObj_HiveCmd_File_Dynamic = Obj_FSO.OpenTextFile(vUnix_GETCommand,2,True)
vObj_HiveCmd_File_Dynamic.WriteLine "lcd " & varf_TC_QA_TargetFileLocation
vObj_HiveCmd_File_Dynamic.WriteLine "get " & varf_TC_Unix_QA_FolderLocation &
varf_TC_Unix_FileName
vObj_HiveCmd_File_Dynamic.Close

' Create and Execute the Plink command file into Unix

vPsftpExe_Location_Split = Split(vPSFTPExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPsftpExe_Location_Split(0) & ":" & "&cd \
&cd " & Chr(34) & vPsftpExe_Location_Split(1) & Chr(34) & "&psftp " &
vUnixConn_Server_USN
vExecute_CMD_Prompt = vExecute_CMD_Prompt & "@" & varf_TC_UnixBox_HostName & "
-pw " & vUnixConn_Server_PWD & " -b " & vUnix_GETCommand

Wshell.Run vExecute_CMD_Prompt,0,True

If Obj_FSO.FileExists(varf_TC_QA_TargetFileLocation & varf_TC_Unix_FileName)


Then
vStatus = "PASS"
vRemarksTC = varf_TC_QA_TargetFileLocation & varf_TC_Unix_FileName & "
File copied from Unix to Local successfully"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
Else
vStatus = "FAIL"
vRemarksTC = varf_TC_QA_TargetFileLocation & varf_TC_Unix_FileName & "
Unable to copy file from Unix to Local"
ObjWS_ResultTC.Cells(vTC_FuncRowNo_Value,vFuncTC_Remarks_ColNo).Value =
vRemarksTC
End If

Set ObjWS_UnixConnection_Sheet = Nothing


Set Wshell = Nothing

End Function

Public Function f_Enumeration_Validation(vTC_Name, Obj_Dict_Conf, Obj_Dict_RegTC,


ObjWS_ResultTC, ObjWB_Result, Obj_FSO, ObjXL_Main,ObjWB_Master_Data,_

vTD_DbCrdnSheet,vTD_UnixCrdnSheet,vStaticTimestamp_DDMMHHMM,Obj_ExeLog,vFuncTC_Rema
rks_ColNo,vTC_FuncRowNo_Value,vStatus)

vStatus ="PASS"

End Function

'**********************************************************************************
**************************
' GENERIC FUNCTIONS
'**********************************************************************************
**************************
'==================================================================================
==========================
'Generic Function Name : Unix job Verification
'Description :
'==================================================================================
==========================
Public Function f_UnixProcess_Verification (vTC_Name, Obj_Dict_Conf,
Obj_Dict_RegTC, ObjWB_Result, Obj_FSO, ObjXL_Main, vStatus)

var_pf = "Program Files\SimonTatham\PuTTY"


var_cmd = Obj_Dict_RegTC ("Process_Command")
var_otp = vProjectFdr_Path & "Unix_ProcessValidation\" & "UnixOutput_" &
vStaticTimestamp_DDMMHHMM & ".txt"
var_dom = Obj_Dict_RegTC("HOST NAME")
var_usr = Obj_Dict_RegTC("User Name")
var_pwd = Obj_Dict_RegTC("Password")

Set Wshell = CreateObject("Wscipt.Shell")


var = "cmd /c c: &cd \ &cd " & Chr(34) & var_pf & Chr(34) & "&plink " & var_dom
& " -l " & var_usr & " -pw " & var_pwd & " " & Chr(34) & var_cmd & Chr(34) & " > "
& var_otp & " &exit"
Wshell.Run var,0,True
Set Wshell = Nothing

Set Obj_OFile = Obj_FSO.OpenTextFile (var_otp,1)


'Obj_OFile.ReadAll
Obj_OFile.Close

vStatus = "PASS"

End Function

'==================================================================================
==========================
'Generic Function Name : Func_Worksheet_Exist
'Description :
'==================================================================================
==========================

Public Function Func_Worksheet_Exist(ByVal worksheetName, ByRef WrkObj )


x= 0
For Each objWorkSheet In WrkObj.Worksheets
If objWorkSheet.Name = worksheetName Then
x =1
Exit For
End If
Next
Func_Worksheet_Exist = x
End Function

'==================================== End Function


==========================================

'==================================================================================
==========================
'Generic Function Name : Kill Windows Process
'Description :
'==================================================================================

Public Sub KillProcessor(ByVal ProcessName)


Set ObjProcessor = GetObject("winmgmts:{impersonationLevel=impersonate}")
Set ObjprocessSet = ObjProcessor.ExecQuery("Select * from Win32_process")
For Each ObjProcess In ObjprocessSet
If StrComp(ObjProcess.Name, UCase(ProcessName),1) = 0 Then
ObjProcess.Terminate()
Next
End Sub

'==================================== End Sub


================================================

'==================================================================================
==========================
'Generic Function Name : Func_UpdateStatus
'Description :
'==================================================================================

Public Function Func_UpdateStatus(ByRef Obj_WrkSheet, ByRef vRowNo, ByRef


vColumnNo, ByRef vStatus)

If StrComp(UCase(vStatus), "PASS",1) = 0 Then


Obj_WrkSheet.Cells(vRowNo, vColumnNo).Value = "PASS"
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Interior.ColorIndex = 50
ElseIf StrComp(UCase(vStatus), "FAIL",1) = 0 Then
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Value = "FAIL"
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Interior.ColorIndex = 3
ElseIf StrComp(UCase(vStatus), "NOT EXECUTED",1) = 0 Then
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Value = "Not Exected"
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Interior.ColorIndex = 15
Else
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Value = vStatus
Obj_WrkSheet.Cells(vRowNo, vColumnNo).Interior.ColorIndex = 15
End If

'Obj_WrkSheet.Cells(vRowNo, vRemarkColno).Value = vTCRemarks

End Function

'==================================== End Function


==========================================

'==================================================================================
==========================
'Generic Function Name : f_WriteCommand_TextFile
'Description : Write Unix command based on the Unix environment to a text file
'==================================================================================

Public Function
f_WriteCommand_TextFile(vObj_HiveCmd_File_Dynamic,varf_TC_UnixBox_HostName,
command)
For commandcount = 0 to ubound(command)
if(varf_TC_UnixBox_HostName="wupra92a0033.mylocal.com" or
varf_TC_UnixBox_HostName="wupra92a0201.mylocal.com") then
vObj_HiveCmd_File_Dynamic.WriteLine "su - cdhqa -c " & chr(39) &
command(commandcount) &chr(39)
Else
vObj_HiveCmd_File_Dynamic.WriteLine command(commandcount)
End If
Next
vObj_HiveCmd_File_Dynamic.Close
End Function
Public Function SenMail(SendTo, Subject, Body, Attachment)
Set Otl = CreateObject("Outlook.Application")
Set m = otl.CreateItem(0)
m.to = SendTo
m.Subject = subject
m.Body = Body
mail.attachment.Add(Attachment)
m.Send
otl.Quit
End Function
'==================================== End Function
==========================================

Public Function Regex_Sample


Set MyLife = ObjFso.OpenTextFile(File1)
MyData = MyLife.ReadAll
Set ObjRegEx = New RegEx
ObjRegEx.Pattern = "QTP"
ObjRegEx.Global = True ' Finding All Matches
ObjRegEx.IgnoreCase = True
Set MatchesFound = ObjRegEx.Execute(Mydata)
TotMatches = MatchesFound.Count
Msgbox "Matches:" & TotMatches
End Function
'==================================== End Function
==========================================

'**********************************************************************************
**************************
' QC Driver Script
'**********************************************************************************
**************************

Public Function QC_Connection_and_Driver()

'*********** Declaration Of Variables *************************


Dim otaAttachmentFactory, otaAttachment, otaAttachmentList, otaAttachmentFilter
Dim otaTreeManager, otaSysTreeNode, otaExtendedStorage, StrPath
Dim TSetFact, tsList, theTestSet, tsTreeMgr, tsFolder, Scheduler, execStatus
Dim TSTestFact, TestList, tsFilter, TSTst
Dim RunFinished

sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
Set dri_FSO = CreateObject("Scripting.FileSystemObject")
Set Dr_ExcelObj = CreateObject("Excel.Application")
If dri_FSO.FileExists(sCurPath & "\QC_Details_Driver.xlsx") Then
Set Dr_Wrbook = Dr_ExcelObj.Workbooks.Open(sCurPath & "\QC_Details_Driver.xlsx")
Set Dr_Wsheet = Dr_Wrbook.Worksheets("QC_Details")

'******** Capturing the column number of the test data sheet ************
vTotColumnUsed = Dr_Wsheet.UserRange.Columns.Count
vTotRowUsed = Dr_Wsheet.UserRange.Rows.Count
vRowNoConf = 2

vFdrPath_Local_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &


Chr(vTotColumnUsed + 64) & vRowNoConf).Find("FdrPath_Local").Column
vQC_Trigger_Flag_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("QC_Trigger_Flag").Column
vQC_Domain_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("QC_Domain").Column
vQC_Project_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("QC_Project").Column
vQC_User_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("QC_User").Column
vQC_Password_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("QC_Password").Column
vHostName_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("HostName").Column
vRunWhere_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("RunWhere").Column
vQC_Server_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("QC_Server").Column
vTDFolder_Path_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("TDFolder_Path").Column
vTD_AttachmentName_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("TD_AttachmentName").Column
vTSFolderName_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("TSFolderName").Column
vTestSetName_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("TestSetName").Column
vResultFolderPath_ColNo = Dr_Wsheet.Range("A" & vRowNoConf & ":" &
Chr(vTotColumnUsed + 64) & vRowNoConf).Find("ResultFolderPath").Column

'******** Defining the variables ************

vQC_Trigger_Flag = Dr_Wsheet.Cells(2,vQC_Trigger_Flag_ColNo).Value
qcServer = Dr_Wsheet.Cells(2,vQC_Server_ColNo).Value
qcUser = Dr_Wsheet.Cells(2,vQC_User_ColNo).Value
qcPassword = Dr_Wsheet.Cells(2,vQC_Password_ColNo).Value
qcDomain = Dr_Wsheet.Cells(2,vQC_Domain_ColNo).Value
qcProject = Dr_Wsheet.Cells(2,vQC_Project_ColNo).Value
HostName = Dr_Wsheet.Cells(2,vHostName_ColNo).Value
RunWhere = Dr_Wsheet.Cells(2,vRunWhere_ColNo).Value
TDFolderPath = Dr_Wsheet.Cells(2,vTDFolder_Path_ColNo).Value
TDAttachmentName = Dr_Wsheet.Cells(2,vTD_AttachmentName_ColNo).Value
TSFolderName = Dr_Wsheet.Cells(2,vTSFolderName_ColNo).Value
TSetName = Dr_Wsheet.Cells(2,vTestSetName_ColNo).Value
ResFolderPath = Dr_Wsheet.Cells(2,vResultFolderPath_ColNo).Value
fldPath_Local = Dr_Wsheet.Cells(2,vFdrPath_Local_ColNo).Value
lclPath = fldPath_Local & "\"
vResult_Folder = fldPath_Local & "\"
vRes_testdata = vResult_Folder & "TestData.xls"
vRes_FA_UI = vResult_Folder & "Result_FA_UI_Auto.xlsx"

'******** Create folder in local drive if not yet exist ***********


Set dri_Fso = CreateObject("Scripting.FileSystemObject")

If Not dri_Fso.FolderExists(fldPath_Local) Then dri_Fso.CreateFolder(fldPath_Local)


If Not dri_Fso.FolderExists(fldPath_Local & "\Datasheets") Then
dri_Fso.CreateFolder(fldPath_Local & "\Datasheets")
If Not dri_Fso.FolderExists(fldPath_Local & "\Result") Then
dri_Fso.CreateFolder(fldPath_Local & "\Result")
If Not dri_Fso.FolderExists(fldPath_Local & "\Application_Images") Then
dri_Fso.CreateFolder(fldPath_Local & "\Application_Images")
If Not dri_Fso.FolderExists(fldPath_Local & "\Error_Images") Then
dri_Fso.CreateFolder(fldPath_Local & "\Error_Images")

'******** Establishing QC Connection *******************


Set tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx qcServer
tdc.Login qcUser, qcPassword
tdc.Connect qcDomain, qcProject
Set otaTreeManager = tda.TreeManager

'*********** Downloading the Testdata.xls file into local only if not exist
************
If Not (dri_FSO.FileExists(lclPath & TDAttachment)) Then
Set otaSysTreeNode = otaTreeManager.NodeByPath(TDFolderPath)
Set otaAttachmentFactory = otaSysTreeNode.Attachments
Set otaAttachmentFilter = otaAttachmentFactory.Filter
otaAttachmentFilter.Filter("CR_REFERENCE") = "'ALL_LIST_" &
otaSysTreeNode.NodeID & "_" & TDAttachmentName & "'"
otaAttachmentList = otaAttachementFilter.NewList
If otaAttachmentList.Count > 0 Then
Set otaAttachment = otaAttachmentList.Item(1)
otaAttachment.Load True, ""
StrPath = otaAttachment.FileName
If (dri_FSO.FileExists(otaAttachment.FileName)) Then
dri_FSO.CopyFile StrPath, lclPath & "\" & TDAttachmentName
DownloadAttachment = lclPath & "\" & TDAttachmentName
Else
DownloadAttachment = StrPath
End If
End If
End If

'********** Run the controller script from test lab Of QC ************


Set TSetFact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
nPath = "Root\" & Trim(tsFolderName)
On Error Resume Next
Set tsFolder = tsTreeMgr.NodeByPath(nPath)

If tsFolder Is Nothing Then


err.Raise vbObjectError + 1, "RunTestSet", "Could not find folder" & nPath
End If

Set tsList = tsFolder.FindTestSets(tSetName)

'********** Verifying the controller file exist in testset or not ************


If tsList.Count > 1 Then
Msgbox "FindTestSets found more than onetest sets refine search"
ElseIf tsList.Count < 1 Then
Msgbox "FindTestsets: test set not found"
End If

Set theTestSet = tsList.Item(1)


Debug.Print theTestSet.ID

Set Scheduler = theTestSet.StartExecution("")

'************** Selecting the script should run in which environment


***************
Select Case RunWhere
Case "RUN_LOCAL" ' ====Run all tests on the local
machine
Scheduler.RunAllLocally = True
Case "RUN_REMOTE" ' =====Run tests on a sepecific
remote machine
Scheduler.TDHostName = HostName
Case "RUN_PLANNED_HOST" ' =========== Run on the
hosts as planned inthe test set
Set TSTestFact = theTestSet.TSTestFactory ' ====== Get the instance
from the test set
Set tsFilter = TSTestFact.Filter
tsFilter.Filter("TC_CYCLE_ID") = theTestSet.ID
Set TestList = TSTestFact.NewList(tsFilter.Test)
Debug.Print "Test Instances and planned Hosts:"
For Each TSTst in TestList
Debug.Print "Name:" & TSTst.Name & "ID:" & "Planned Hosts:" &
TSTst.HostName
Scheduler.RunOnHost(TSTst.ID) = TSTst.HostName
Next
Scheduler.RunAllLocally = False
End Select

'********** Run the Tests ************


Scheduler.Run

'********* Get the execution status object **************


Set execStatus = Scheduler.ExecutionStatus

'********* Validate if run is completed and sync the script till it get finished
***********

While (RunFinished = False)


execStatus.RefreshExecStatusInfo "all", True
RunFinished = execStatus.Finished
Wend

'***** Uploading the results into QC both testdata and application specific
*************

Set FileSysTreeNode = otaTreeManager.NodeByPath(ResFolderPath)


Set FileAttachmentFactory = FileSysTreeNode.Attachements
Set FileAttachment = FileAttachmentFactory.AddItem(Null)
FileAttachment.FileName = vRes_testdata
FileAttachment.Type = 1
FileAttachment.Post
Set FileAttachment = Nothing

Set FileAttachment = FileAttachmentFactory.AddItem(Null)


FileAttachment.FileName = vRes_FA_UI
FileAttachment.Type = 1
FileAttachment.Post
Set FileAttachment = Nothing

'****** Close QTP and Remote Agent *********

If IsRunning("UFT.exe") Then
KillProcesses("UFT.exe")
End If
If IsRunning("AQTRmtAgent.exe") Then
KillProcesses("UFT.exe")
End If

If IsRunning("TERun.exe") Then
KillProcesses("UFT.exe")
End If

If IsRunning("EXTRA.exe") Then
KillProcesses("UFT.exe")
End If

If tdc.connect =True Then


tdc.Disconnect
End If

If tdc.LoggedIn = True Then


tdc.LogOut
End If

tdc.ReleaseConnection

'******* Deallocating the memory to defined objects ************


Set tdc = Nothing
Set otaAttachmentFactory = Nothing
Set otaAttachment = Nothing
Set otaAttachmentList = Nothing
Set otaAttachmentFilter = Nothing
Set otaTreeManager = Nothing
Set otaSysTreeNode = Nothing
Set dri_FSO = Nothing

'*********** if Required file not exist then below msgbox will pop up and stops
the script **************
Else
Msgbox "QC_Details.xlsx file not in required location " & Chr(10) & "Please
copy the file in below location and ReRun the script" & Chr(10) & Chr(34) &
sCurPath & Chr(34),4160
End If

End Function
'==================================== End Function
==========================================

'**********************************************************************************
**************************
' QTP Automation Object module Script
'**********************************************************************************
**************************
Public Function QTP_AOM(test_path, lib_path, tsr_path, result_path)

Dim qtApp
Dim qtLibraries, qtRepo
Dim qtResultopt
Set qtApp = CreateObject("QuickTest.Application")
vExistAddin_Test = qtApp.GetAssociatedAddinsForTest(test_path)
AddinList = Array("Web", "WPF","ActiveX")
qtApp.SetActiveAddins(AddinList)
qtApp.Launch
qtApp.Visible = True
qtApp.Open test_path, True

qtApp.Test.Settings.Resources.Libraries.RemoveAll
qtApp.Test.Settings.Resources.Libraries.Add(lib_path)

Set qtLibraries = qtApp.Test.Settings.Resources.Libraries


If qtLibraries.Find(lib_path) Then
qtLibraries.Add(lib_path)
End If

Set qtRepo = qtApp.Test.Actions("Action 1").ObjectRepositories


If qtRepo.Find(tsr_path) = -1 Then
qtRepo.Add(tsr_path)
End If

qtApp.Test.Actions.Item(1).ObjectRepositories.RemoveAll
qtApp.Test.Actions.Item(1).ObjectRepositories.Add(tsr_path)

Set qtResultOpt = CreateObject("QuickTest.RunResultsOptions")


qtResultOpt.ResultsLocation = result_path

qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ImageCaptureForTestResults = "Never"
qtApp.Options.Run.MovieCaptureForTestResults = "Never"

'qtApp.Options.ObjectIdentification("WinEdit").MandatoryProperties
'qtApp.Options.ObjectIdentification("WinEdit").AssistiveProperties
'qtApp.Options.ObjectIdentification("WinEdit").BaseFilterProperties
'qtApp.Options.ObjectIdentification("WinEdit").AvailableProperties
'qtApp.Options.ObjectIdentification("WinEdit").OrdinalIdentifier

qtApp.Test.Settings.Run.ObjectSyncTimeOut = 25000
qtApp.Test.Settings.Run.DisableSmartIdentification = False
qtApp.Test.Settings.Run.IterationMode = "rngIterations"
qtApp.Test.Settings.Run.StartIteration = 1
qtApp.Test.Settings.Run.EndIteration = 1
qtApp.Test.Settings.Run.OnError = "Dialog"
qtApp.Test.Run(qtResultOpt)

qtApp.Test.Save
qtApp.Quit

Set qtApp = Nothing


End Function
'==================================== End Function
==========================================

Public Function XMLToRsRecordset(strXML)


Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.WriteText strXML
objStream.Position = 0
Set oRecordset = Server.CreateObject("ADODB.Recordset")
oRecordset.Open objStream '<-- Line XXX
objStream.Close
Set objStream = Nothing
Set XMLStringToRecordset = oRecordset
Set oRecordset = Nothing
End Function

Public Function entilement(strXML)


Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set ObjRead = ObjFSO.OpenTextFile("C:\temp\sample_POST.txt",1)
POST_MSG = ObjRead.ReadLine

CURD_OPP = "KHADEER"
SERVER_LINK = "http://wupra92a0201.mylocal.com:8086/users/u540458"
'POST_MSG = ""USN = "u403516"
PWD = "QADIr123"

Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.3.0")


oXMLHTTP.open CURD_OPP,SERVER_LINK, false, USN, PWD
oXMLHTTP.setRequestHeader "Content-Type", "application/json"
oXMLHTTP.send POST_MSG
Msgbox "responseText ---- "& oXMLHTTP.responseText & CHr(10) & "status ---- "&
oXMLHTTP.status & Chr(10) & "statusText ---- "& oXMLHTTP.statusText

End Function

'========================= i HUB ======================================

Public Function iHUB()

BZ_DATE = "10/27/2016"

'**********************************************************************************
**************************
'Project Name : <iHub Regression Suite>
'Author : Khadeer
'Creation Date : 2-NOV-2016
'Module Name : Controller
'Description : Regression tool is used to compare iHUB tables with
HIVE and TERADATA. Also provide report about Autosys status and duartion of each
job run
'**********************************************************************************
**************************

'Option Explicit
'==================================================================================
==========================
'Declaration of Variables
'==================================================================================
==========================
Dim varf_TC_UnixBox_HostName, vUnixConn_Server_USN, vUnixConn_Server_PWD,
Log_FileLocation_unix
Dim vAutomationHomeDir_Location,
vPlinkExe_Location,vConfig_File_Loc,vConfig_File_Name,vConfig_SheetName,vExecutionL
og_FileName,vResSummary_FileName
Dim objFSO,Obj_ExeLog,ObjXL_main,Obj_Wsh,Obj_Dict_Conf

'==================================================================================
==========================
'Initialisation of variable whose values will be constant

' UNIX HOST Machine details to be tested against iHUB teradata


varf_TC_UnixBox_HostName = "wppra93a0201.mylocal.com"
vUnixConn_Server_USN = "u403516"
vUnixConn_Server_PWD = "QADIr123"
Log_FileLocation_unix = "/opt/cdhprd/log/"

'Variables used in controller to drive the execution


vAutomationHomeDir_Location = "C:\temp\iHub_Reg_Suite\"
vPlinkExe_Location = vAutomationHomeDir_Location & "Plink\"
vPlinkExe_Name = "Plink.exe"
vConfig_File_Loc = vAutomationHomeDir_Location & "Config_File\"
vResultFDR_Loc = vAutomationHomeDir_Location & "Result\"
vConfig_File_Name = "WDP Phase I Sprint 2 Data Ingestion Config File
non-ihub v1.7.xlsx"
vConfig_SheetName = "Phase I Sprint 2 Data Config"
vIHUB_DB_TB_Schema_FileName = "IHUB_DB_TB_Schema_Details_SPRINT-2.xlsx"
vIHUB_DB_TB_Schema_SheetName = "IHUB_DB_TB_Schema_Details"
vConfig_iHUB_CMP_SheetName = "config Vs iHUB DB"
vStaticTimestamp_DDMMHHMM = Day(Date) & Month(Date) & Hour(Time) &
Minute(Time) & Second(Time)
vExecutionLog_FileName = "ExecutionLog_" & vStaticTimestamp_DDMMHHMM &
".txt"
vResSummary_FileName = "ResultSummary_" & vStaticTimestamp_DDMMHHMM

'==================================================================================
==========================
'Create and define the log file and validate the any Excel files are opened
If Not CreateObject("Scripting.FileSystemObject").FolderExists(vResultFDR_Loc) Then
CreateObject("Scripting.FileSystemObject").CreateFolder vResultFDR_Loc
Set Obj_ExeLog =
CreateObject("Scripting.FileSystemObject").OpenTextFile(vResultFDR_Loc &
vExecutionLog_FileName,2,True)

Obj_ExeLog.WriteLine String(50,"*") & String(5," ") & "Regression_Main_Log" &


String(5," ") & String(50,"*")
Obj_ExeLog.WriteBlankLines 1
Obj_ExeLog.WriteLine "Execution Start Time : " & Now()
Obj_ExeLog.WriteLine "User Running the script : " &
Ucase(CreateObject("WScript.Network").UserName)
Obj_ExeLog.WriteBlankLines 2

' Before execution begin close all excel files currently opened or terminate script

Select Case Msgbox("Please Save the excel files opened and click OK" & Chr(10) &
"Cancel will stop execution",1)
Case 1 Call KillProcessor("EXCEL.EXE")
Case 2 vterminate_msg = "Execution stopped " & Chr(10) & "User not save &
close the excel file"
Call Func_TerminateExec(vterminate_msg,Obj_ExeLog)
End Select

'==================================================================================
==========================
'Defining the class objects FSO, Wscript, Excel, Dictionary
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ObjXL_main = CreateObject("Excel.Application")
Set Obj_Wsh = CreateObject("Wscript.Shell")
Set Obj_WshNet = CreateObject("WScript.Network")
Set Obj_Dict_Conf = CreateObject("Scripting.Dictionary")
Set ObjDict_Config_Dd_Tb = CreateObject("Scripting.Dictionary")
Set ObjDict_iHUB_Dd_Tb = CreateObject("Scripting.Dictionary")
Set ObjDict_OldColumnNames = CreateObject("Scripting.Dictionary")
ObjXL_main.Visible = False
ObjXL_main.DisplayAlerts = False

' Validate Folder structure of regression suite


Obj_ExeLog.WriteLine "# Validating the folder structure of the regression pack"

If Func_FileExists(vConfig_File_Loc,
vConfig_File_Name,vterminate_msg,objFSO,Obj_ExeLog) <> "EXIST" Then Call
Func_TerminateExec(vterminate_msg,Obj_ExeLog)
Obj_ExeLog.WriteLine "Config File Exist : " & vConfig_File_Loc &
vConfig_File_Name

If Func_FileExists(vPlinkExe_Location,
vPlinkExe_Name,vterminate_msg,objFSO,Obj_ExeLog) <> "EXIST" Then Call
Func_TerminateExec(vterminate_msg,Obj_ExeLog)
Obj_ExeLog.WriteLine "Plink File Exist : " & vPlinkExe_Location & vPlinkExe_Namee

Obj_ExeLog.WriteBlankLines 1
Obj_ExeLog.WriteLine String(15,"-") & "Executing the scenarios Defined in Config" &
String(15,"-")

'==================================================================================
==========================
'Create Result File with name as specific to scenario name, data and time stamp
vTDResult_FileName = Replace(Replace(Replace(vConfig_File_Name, " ",
""),"xlsx",""),".","") & "_" & vStaticTimestamp_DDMMHHMM & ".xlsx"

'Create Result File into to result folder and set the result TD object
objFSO.CopyFile (vConfig_File_Loc & vConfig_File_Name), (vResultFDR_Loc &
vTDResult_FileName), True
set ObjWB_Result = ObjXL_main.Workbooks.Open(vResultFDR_Loc & vTDResult_FileName)
'Validate Sheet Exist in config file
vConfigSheet_Found = vConfig_SheetName & " --> Sheet Not Exist in the config file
and Execution is stopped"
For Each vSheet_to_Delete In ObjWB_Result.Sheets
If InStr(1, vSheet_to_Delete.Name, Mid(vConfig_SheetName,1,15)) > 0 Then
ObjWB_Result.Worksheets(vSheet_to_Delete.Name).Visible = True
vConfigSheet_Found = "Found"
Else
vSheet_to_Delete.Delete
End If
Next

If vConfigSheet_Found <> "Found" Then Call


Func_TerminateExec(vConfigSheet_Found,Obj_ExeLog)
set ObjWS_main = ObjWB_Result.Worksheets(vConfig_SheetName)
Obj_ExeLog.WriteLine "# Result Report " & vConfig_File_Loc & vConfig_File_Name & "
is created into folder " & vResultFDR_Loc
Obj_ExeLog.WriteLine "# Result file Name is " & vTDResult_FileName

'==================================================================================
==========================
'Fetch the column Number from configuration sheet for few attributes

vTotRow_ConfigXL = Cint(ObjWS_main.UsedRange.Rows.Count)
vTotCol_ConfigXL = Cint(ObjWS_main.UsedRange.Columns.Count)

If vTotCol_ConfigXL > 50 Then vTotCol_ConfigXL = 50 ' handling the


mistakes while copying or unwanted test data
If vTotCol_ConfigXL > 26 Then
vAlphaExcl_TotCol_Used = "A" & Chr(vTotCol_ConfigXL + 38)
Else
vAlphaExcl_TotCol_Used = Chr(vTotCol_ConfigXL + 64)
End If

vRowNoConfig_HDR = 2

'==================================================================================
==========================
' Standardize the column names into SQL defined in main sheet second record

For ColCnt_Config = 1 To vTotCol_ConfigXL

vColumnName = ObjWS_main.cells(vRowNoConfig_HDR, ColCnt_Config).value


ColumnName_new = Empty

Select Case
Replace(Replace(Replace(Trim(vColumnName),vblf,""),vbcr,""),Chr(32),"")

Case Replace("Target (Hadoop) Job Name",Chr(32),"")


ColumnName_new = "Target_JobName_DataSet"

Case Replace("Source Schema Name (TGT_DB_NME) Or File Path",Chr(32),"")


ColumnName_new = "SchemaName_iHUB"

Case Replace("Source Object Name (table name or filename)",Chr(32),"")


ColumnName_new = "TableName_iHUB"

Case Replace("Source AutoSys Job Name",Chr(32),"")


ColumnName_new = "Autosys_JobName_iHUB"

Case Replace("Source AutoSys Job Frequency",Chr(32),"")


ColumnName_new = "Autosys_JobFreq_iHUB"

Case Replace("Source Time of Job",Chr(32),"")


ColumnName_new = "Autosy_JobTime_iHUB"

Case Replace("Source AutoSys Run Calendar",Chr(32),"")


ColumnName_new = "Autosys_RunCalendar_iHUB"

Case Replace("Source AutoSys Exclude Calendar",Chr(32),"")


ColumnName_new = "Autosys_ExdCalendar_iHUB"

Case Replace("Source Day of Job",Chr(32),"")


ColumnName_new = "Autosy_JobExecDay_iHUB"

End Select

If ColumnName_new <> Empty Then


ObjDict_OldColumnNames.Add ColumnName_new, vColumnName
ObjWS_main.cells(vRowNoConfig_HDR, ColCnt_Config) =
ColumnName_new
End If

Next

ObjWB_Result.Save

'==================================================================================
==========================
' Add a column and enter sequence number to identify the issue in actual excel row
number

vTotCol_ConfigXL = vTotCol_ConfigXL + 1
ObjWS_main.cells(vRowNoConfig_HDR, vTotCol_ConfigXL) = "Actual_SeqNo_Config"

For RowCnt_Config = vRowNoConfig_HDR + 1 To vTotRow_ConfigXL


ObjWS_main.cells(RowCnt_Config, vTotCol_ConfigXL) = RowCnt_Config
Next

ObjWB_Result.Save
'==================================================================================
==========================
' Add a column for identifying any blank values into expected columns

vTotCol_ConfigXL = vTotCol_ConfigXL + 1
ObjWS_main.cells(vRowNoConfig_HDR, vTotCol_ConfigXL) = "Res_BlankValue_Columns"

ObjWB_Result.Save
'==================================================================================
==========================
' Add a column to display the results if there is an issue with Target JobName, it
is not unique
vTotCol_ConfigXL = vTotCol_ConfigXL + 1
ObjWS_main.cells(vRowNoConfig_HDR, vTotCol_ConfigXL) =
"Multiple_TarJobName_1_Schema_Jfrq"

vTotCol_ConfigXL = vTotCol_ConfigXL + 1
ObjWS_main.cells(vRowNoConfig_HDR, vTotCol_ConfigXL) =
"Single_TarJobName_Multi_Schema_Jfrq"

vTotCol_ConfigXL = vTotCol_ConfigXL + 1
ObjWS_main.cells(vRowNoConfig_HDR, vTotCol_ConfigXL) = "Duplicate_entry_Primary"

vTotCol_ConfigXL = vTotCol_ConfigXL + 1
ObjWS_main.cells(vRowNoConfig_HDR, vTotCol_ConfigXL) = "Autosys_Checks"

ObjWB_Result.Save
'==================================================================================
==========================
'Convert the Config file into temp table, to make quick decisions
'Define the database objects
Set Obj_AdodbConnection = CreateObject("ADODB.Connection")
Set Obj_RSGeneric = CreateObject("ADODB.RecordSet")
Set Obj_RSUpdate = CreateObject("ADODB.RecordSet")
If Obj_AdodbConnection.State = 1 Then Obj_AdodbConnection.close

'Update registry and create test connection string


varf_Regedit_JetEngine_path =
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\"
varf_Regedit_JetEngine_path =
"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Jet\4.0\Engines\"

Obj_Wsh.RegWrite varf_Regedit_JetEngine_path & "Excel\DisabledExtensions", "!


xls,xlsx","REG_SZ"
Obj_Wsh.RegWrite varf_Regedit_JetEngine_path & "Excel\TypeGuessRows",
1000000, "REG_DWORD"
Obj_AdodbConnection.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &
vResultFDR_Loc & vTDResult_FileName & "; Extended Properties=""Excel
12.0;HDR=YES;"""' IMEX=2;"""

vConfig_TempTableName = "[" & vConfig_SheetName & "$A2:BZ]"

' Insert_query = "insert into " & vConfig_TempTableName & "


(Target_JobName_DataSet) values('Hello')"

'==================================================================================
==========================
'validation Of Config File using temp table and extra column -->
Actual_SeqNo_Config, Res_BlankValue_Columns
'Check no blank should be available in below columns -->
'Target_JobName_DataSet, SchemaName_iHUB, TableName_iHUB, Autosys_JobName_iHUB,
Autosys_JobFreq_iHUB, Autosy_JobTime_iHUB, Autosy_JobTime_iHUB,
Autosys_RunCalendar_iHUB, Autosys_ExdCalendar_iHUB, Autosy_JobExecDay_iHUB
Query_output = Empty
vQuery_Null_Identification = "select Actual_SeqNo_Config from " &
vConfig_TempTableName & " Where Target_JobName_DataSet is null or SchemaName_iHUB
is null or TableName_iHUB is null or Autosys_JobName_iHUB is null or " &_
"Autosys_JobFreq_iHUB is null or Autosy_JobTime_iHUB is null or
Autosy_JobTime_iHUB is null or (Autosys_RunCalendar_iHUB is null and
Autosys_ExdCalendar_iHUB is null and Autosy_JobExecDay_iHUB is null) "

Obj_RSGeneric.Open vQuery_Null_Identification, Obj_AdodbConnection,1,3

If Obj_RSGeneric.EOF = False then Query_output =


Replace(Replace(Obj_RSGeneric.getString(2,,"",""),Chr(13),","),Chr(10),"")
If Obj_RSGeneric.State = 1 then Obj_RSGeneric.Close

If Query_output <> Empty Then


Query_output = Mid(Query_output,1,len(Query_output)-1)
vUpdate_query = "UPDATE " & vConfig_TempTableName & " SET
Res_BlankValue_Columns='Blank record' WHERE Actual_SeqNo_Config in (" &
Query_output & ")"
Obj_RSUpdate.Open vUpdate_query, Obj_AdodbConnection,1,3
If Obj_RSUpdate.State = 1 then Obj_RSUpdate.Close
End If

ObjWB_Result.Save

'==================================================================================
==========================
'validation Of Config File using temp table and extra column -->
Actual_SeqNo_Config, 'Multiple_TarJobName_1_Schema_Jfrq,
Single_TarJobName_Multi_Schema_Jfrq
' Validate is there are any multiple "Target Job Name" for unique combination of
Source schema and Autosys_JobName_iHUB
Query_output=Empty
vQuery_Multiple_TarJobName = "select XYZ.Schema_JFreq from " & _
"(select ABC.Schema_JFreq,count(*) from " & _
"(select distinct
Target_JobName_DataSet,(SchemaName_iHUB & '@' & Autosys_JobName_iHUB) as
Schema_JFreq from " & vConfig_TempTableName & ") ABC "&_
"group by ABC.Schema_JFreq having
count(*) > 1) XYZ"

Obj_RSGeneric.Open vQuery_Multiple_TarJobName, Obj_AdodbConnection,1,3

If Obj_RSGeneric.EOF = False then Query_output =


Replace(Replace(Obj_RSGeneric.getString(2,,"",""),Chr(13),"','"),Chr(10),"")
If Obj_RSGeneric.State = 1 then Obj_RSGeneric.Close

If Query_output <> Empty Then


Query_output = Mid(Query_output,1,len(Query_output)-3)
vUpdate_query = "UPDATE " & vConfig_TempTableName & " SET
Multiple_TarJobName_1_Schema_Jfrq='Mutiple Target JobName from single Schema & Job
Freq' WHERE SchemaName_iHUB & '@' & Autosys_JobName_iHUB in ('" & Query_output &
"')"
Obj_RSUpdate.Open vUpdate_query, Obj_AdodbConnection,1,3
If Obj_RSUpdate.State = 1 then Obj_RSUpdate.Close
End If

ObjWB_Result.Save

' Validate if one "Target Job Name" assigned to multplie Source schema and Autosys
Job Name combination
Query_output=Empty
vQuery_Single_TarJobName_MulSchema = "select XYZ.Target_JobName_DataSet from " & _
"(select ABC.Target_JobName_DataSet,count(*)
from " & _
"(select distinct
Target_JobName_DataSet,(SchemaName_iHUB & '@' & Autosys_JobName_iHUB) as
Schema_JFreq from " & vConfig_TempTableName & ") ABC "&_
"group by
ABC.Target_JobName_DataSet having count(*) > 1) XYZ"

Obj_RSGeneric.Open vQuery_Single_TarJobName_MulSchema, Obj_AdodbConnection,1,3

If Obj_RSGeneric.EOF = False then Query_output =


Replace(Replace(Obj_RSGeneric.getString(2,,"",""),Chr(13),"','"),Chr(10),"")
If Obj_RSGeneric.State = 1 then Obj_RSGeneric.Close

If Query_output <> Empty Then


Query_output = Mid(Query_output,1,len(Query_output)-3)
vUpdate_query = "UPDATE " & vConfig_TempTableName & " SET
Single_TarJobName_Multi_Schema_Jfrq='Single Target JobName for Multiple Schema &
Job Freq' WHERE Target_JobName_DataSet in ('" & Query_output & "')"
Obj_RSUpdate.Open vUpdate_query, Obj_AdodbConnection,1,3
If Obj_RSUpdate.State = 1 then Obj_RSUpdate.Close
End If
ObjWB_Result.Save

'==================================================================================
==========================
'validate if there any duplicate entries in config file and update result in column
Duplicate_entry_Primary

Query_output=Empty
'vQuery_duplicate_record = "select XYZ.Actual_SeqNo_Config from " &_
' "(select Actual_SeqNo_Config, row_number over
(partition by Target_JobName_DataSet, SchemaName_iHUB, Autosys_JobFreq_iHUB) as
rw_num from " & vConfig_TempTableName & ") XYZ where XYZ.rw_num=1"
'
'vQuery_duplicate_record = "select A.Target_JobName_DataSet, A.SchemaName_iHUB,
A.SchemaName_iHUB,A.Autosys_JobFreq_iHUB,count(*) as Rank from " &
vConfig_TempTableName &_
' " as A INNER JOIN " &
vConfig_TempTableName & " as B On
A.Target_JobName_DataSet>=B.Target_JobName_DataSet group by " &_
' "A.Target_JobName_DataSet,
A.SchemaName_iHUB, A.SchemaName_iHUB,A.Autosys_JobFreq_iHUB"

vQuery_duplicate_record = "select Actual_SeqNo_Config from " &


vConfig_TempTableName & " where " &_
"Target_JobName_DataSet & SchemaName_iHUB &
Autosys_JobFreq_iHUB in (" &_
"select ABC.Target_JobName_DataSet &
ABC.SchemaName_iHUB & ABC.Autosys_JobFreq_iHUB from ( " &_
"select
Target_JobName_DataSet,SchemaName_iHUB,Autosys_JobFreq_iHUB,count(*) from " &
vConfig_TempTableName & " group by
Target_JobName_DataSet,SchemaName_iHUB,Autosys_JobFreq_iHUB having count(*)>1)
ABC)"

Obj_RSGeneric.Open vQuery_duplicate_record, Obj_AdodbConnection,1,3

If Obj_RSGeneric.EOF = False then Query_output =


Replace(Replace(Obj_RSGeneric.getString(2,,"",""),Chr(13),","),Chr(10),"")
If Obj_RSGeneric.State = 1 then Obj_RSGeneric.Close

If Query_output <> Empty Then


Query_output = Mid(Query_output,1,len(Query_output)-1)
vUpdate_query = "UPDATE " & vConfig_TempTableName & " SET
Duplicate_entry_Primary='Record Duplicate' WHERE Actual_SeqNo_Config in (" &
Query_output & ")"
Obj_RSUpdate.Open vUpdate_query, Obj_AdodbConnection,1,3
If Obj_RSUpdate.State = 1 then Obj_RSUpdate.Close
End If

ObjWB_Result.Save

'==================================================================================
==========================
'validation Of Config File - Schema & table against iHUB teradata Database

'Extract Schema name and table name from Tera database into above sheet and store
into dictionary object
'- 2 ways --> Connect teradata extract based on pattern or manual should be
available

vConfig_SourceSchemaName_ColNo = ObjWS_Main.Range("A" & vRowNoConfig_HDR &


":" & vAlphaExcl_TotCol_Used & vRowNoConfig_HDR).Find("SchemaName_iHUB").Column
vConfig_SourcetableName_ColNo = ObjWS_Main.Range("A" & vRowNoConfig_HDR &
":" & vAlphaExcl_TotCol_Used & vRowNoConfig_HDR).Find("TableName_iHUB").Column

Set ObjWB_iHUB_DB_TB = ObjXL_Main.Workbooks.Open(vConfig_File_Loc &


vIHUB_DB_TB_Schema_FileName)
Set ObjWS_iHUB_DB_TB =
ObjWB_iHUB_DB_TB.Worksheets(vIHUB_DB_TB_Schema_SheetName)

vTotRow_iHUB_DB_TB = Cint(ObjWS_iHUB_DB_TB.UsedRange.Rows.Count)
vTotCol_iHUB_DB_TB = Cint(ObjWS_iHUB_DB_TB.UsedRange.Columns.Count)
vRowNoiHUB_HDR = 1

vSource_DatabaseName_IHUB_ColNo = ObjWS_iHUB_DB_TB.Range("A" & vRowNoiHUB_HDR &


":" & Chr(vTotCol_iHUB_DB_TB+64) &
vRowNoiHUB_HDR).Find("Source_DatabaseName_IHUB").Column
vSource_TableName_IHUB_ColNo = ObjWS_iHUB_DB_TB.Range("A" & vRowNoiHUB_HDR &
":" & Chr(vTotCol_iHUB_DB_TB+64) &
vRowNoiHUB_HDR).Find("Source_TableName_IHUB").Column

For RowCnt_iHUB = vRowNoiHUB_HDR+1 To vTotRow_iHUB_DB_TB


vKey_TC = Ucase(Trim(ObjWS_iHUB_DB_TB.cells(RowCnt_iHUB,
vSource_DatabaseName_IHUB_ColNo).value))
vItem_TC = Mid(Ucase(Trim(ObjWS_iHUB_DB_TB.cells(RowCnt_iHUB,
vSource_TableName_IHUB_ColNo).value)),1,30)
vvalue = Ucase(Trim(ObjWS_iHUB_DB_TB.cells(RowCnt_iHUB,
vSource_TableName_IHUB_ColNo).value))
If not ObjDict_iHUB_Dd_Tb.Exists(vKey_TC & "|" & vItem_TC) and vKey_TC &
vItem_TC <> Empty and vKey_TC & vItem_TC <> "" Then ObjDict_iHUB_Dd_Tb.Add vKey_TC
& "|" & vItem_TC, vValue
Next

ObjWB_iHUB_DB_TB.Close

' Extract Config Schema and Table into dictionary object


For RowCnt_config = vRowNoConfig_HDR+1 To vTotRow_ConfigXL
vKey_TC = Ucase(Trim(ObjWS_main.cells(RowCnt_config,
vConfig_SourceSchemaName_ColNo).value))
vItem_TC = Mid(Ucase(Trim(ObjWS_main.cells(RowCnt_config,
vConfig_SourcetableName_ColNo).value)),1,30)
vvalue = Ucase(Trim(ObjWS_main.cells(RowCnt_config,
vConfig_SourcetableName_ColNo).value))
If not ObjDict_Config_Dd_Tb.Exists(vKey_TC & "|" & vItem_TC) and vKey_TC &
vItem_TC <> Empty and vKey_TC & vItem_TC <> "" Then ObjDict_Config_Dd_Tb.Add
vKey_TC & "|" & vItem_TC, vValue
Next

'Create new sheet name "config Vs iHUB DB" to store the results
Set ObjWS_Config_Vs_iHUB = ObjWB_Result.Worksheets.Add
ObjWS_Config_Vs_iHUB.Name = vConfig_iHUB_CMP_SheetName

'Create Header in result sheet


viHUB_SchemaName_ColNo = 1
viHUB_TableName_ColNo = 2
vConfig_SchemaName_ColNo = 3
vConfig_TableName_ColNo = 4
vCMP_Status_ColNo = 5
vCMP_Remarks_ColNo = 6

RowCnt_Config_IHUB_Cmp = 1

ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, viHUB_SchemaName_ColNo).value
= "iHUB_SchemaName"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, viHUB_TableName_ColNo).value
= "iHUB_TableName"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, vConfig_SchemaName_ColNo).value
= "Config_SchemaName"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, vConfig_TableName_ColNo).value
= "Config_TableName"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, vCMP_Status_ColNo).value
= "CMP_Status"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, vCMP_Remarks_ColNo).value
= "CMP_Remarks"

'Compare two dictionary objects of Config and IHUB

For each vSchema_TableName in ObjDict_iHUB_Dd_Tb

RowCnt_Config_IHUB_Cmp = RowCnt_Config_IHUB_Cmp + 1

ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
viHUB_SchemaName_ColNo).value = Split(vSchema_TableName,"|")(0)
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
viHUB_TableName_ColNo).value = ObjDict_iHUB_Dd_Tb(vSchema_TableName)

If ObjDict_Config_Dd_Tb.Exists(vSchema_TableName) Then
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vConfig_SchemaName_ColNo).value = Split(vSchema_TableName,"|")(0)
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vConfig_TableName_ColNo).value = ObjDict_Config_Dd_Tb(vSchema_TableName)
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vCMP_Status_ColNo).value = "PASS"
ObjDict_Config_Dd_Tb.Remove(vSchema_TableName)
' ElseIf Instr(1,vDBNAME_IHUB,"NPRIV_S0") <= 0 Then
' ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vCMP_Status_ColNo).value = "IGNORE"
' ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vCMP_Remarks_ColNo).value = "Not Available in Config File but ignored"
Else
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vCMP_Status_ColNo).value = "FAIL"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vCMP_Remarks_ColNo).value = "Not Available in Config File"
End If

Next

ObjDict_iHUB_Dd_Tb.RemoveAll

For each vConfig_DB_TB in ObjDict_Config_Dd_Tb


RowCnt_Config_IHUB_Cmp = RowCnt_Config_IHUB_Cmp + 1
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vConfig_SchemaName_ColNo).value = Split(vConfig_DB_TB,"|")(0)
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp,
vConfig_TableName_ColNo).value = ObjDict_Config_Dd_Tb(vConfig_DB_TB)
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, vCMP_Status_ColNo).value =
"FAIL"
ObjWS_Config_Vs_iHUB.cells(RowCnt_Config_IHUB_Cmp, vCMP_Remarks_ColNo).value =
"Not Available in iHUB source Database"
Next

ObjDict_Config_Dd_Tb.RemoveAll
ObjWB_Result.Save

ObjWB_Result.Close
If Obj_AdodbConnection.State = 1 Then Obj_AdodbConnection.close
Call KillProcessor("EXCEL.EXE")
ExitTest

'==================================================================================
==========================
'Validate Autosys jobs dependancy available in source --> Autosys_JobName_iHUB,
Autosys_JobFreq_iHUB, Autosy_JobTime_iHUB,

'<Update Code>

'==================================================================================
==========================
'Create New Sheet with Name "STATS_AUTOSYS_JOB_LEVEL" and also create below column
'JobNo --> Dynamic sequence number
'Target Job Name --> Distinct Target Job name to be copied from main sheet
'SourceSchema_Name --> Distinct schema snames to be copied from main sheet
'Probability Job Freq --> Distinct values to be copied from main sheet
'No Of tables --> Extract a value based on the count of tables belongs to each
schema as per main sheet
'Autosys Job Date -->
'Autosys Start Time -->
'Autosys End Time -->
'Job Duartion -->
'No Of records ingested -->
'Job Status -->

'<Update code>

'==================================================================================
==========================
' Create Extra Column in Main sheet to update record count of the tables
'Based on BZ_DATE merge 3 columns in first line and update 2nd line woth below
columns
'1. snap_eff_dt
'2. No of records ingested in HDFS
'3. No Of records source IHUB
'4. Status SU/FA/OI
'Fetch Autosys log file and update the columns in sheet

'< Update code>

' Extract values from autosys log files

For XLRowcnt = 3 To vTotRow_ConfigXL


vSchema_Name = ObjWS.cells(XLRowcnt,10).value
vTable_Name = Trim(ObjWS.cells(XLRowcnt,11).value)
Do
If vTable_Name = "" Or vTable_Name = Empty Then Exit Do
AutoJOB_NAME = Trim(ObjWS.cells(XLRowcnt,29).value)
vTemp_grep_filename = "c:\temp\temp_grepcmd.txt"
Log_FileName = AutoJOB_NAME & "*" & month(BZDATE) & "." &
Day(BZDATE) & "." & YEAR(BZDATE) & "*.out"
log_FileName_location = Log_FileLocation_unix & Log_FileName
vLogOutput_FileLocation = "C:\temp\log_output.txt"
vTotalRecordCount = 0
vTimer_Start = Timer

Set ObjFSO_Write_Temp_GrepFile =
objFileToWrite.OpenTextFile(vTemp_grep_filename,2,True)
ObjFSO_Write_Temp_GrepFile.Writeline "grep 'expectedCount' " &
log_FileName_location & "|grep -v '" & Chr(34) & "expectedCount" & Chr(34) &
":null'" & "|grep -i '" & vTable_Name & "'"
ObjFSO_Write_Temp_GrepFile.Close
vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) &
":" & "&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink -t "
& varf_TC_UnixBox_HostName & _
" -l " & vUnixConn_Server_USN & " -pw " &
vUnixConn_Server_PWD & " -m " & vTemp_grep_filename & " > " &
vLogOutput_FileLocation & " & exit"
Obj_Wsh.Run vExecute_CMD_Prompt,0,True
If Not objFileToWrite.FileExists(vLogOutput_FileLocation) Then wait 2
If objFileToWrite.FileExists(vLogOutput_FileLocation) Then

'Declaring File Paths and File Names


'******************************************************************************
Set ObjFSO_ReadLog =
objFileToWrite.OpenTextFile(vLogOutput_FileLocation,1)
Do until ObjFSO_ReadLog.AtEndOfStream
vReadLine = ObjFSO_ReadLog.ReadLine
If Instr(1,vReadLine,"expectedCount") > 0 Then
vCount =
Split(Replace(Replace(Split(vReadLine,"expectedCount")
(1),":",""),Chr(34),""),Chr(44))(0)
ObjWS.cells(XLRowcnt,42).value = vCount
vSnap_eff_date =
Split(Replace(Replace(Split(vReadLine,"snap_eff_dt")(1),":",""),Chr(34),""),"}")(0)
ObjWS.cells(XLRowcnt,41).value = vSnap_eff_date
End If

Loop
ObjWB.Save
End if
Exit DO
Loop
Next

ObjWB.Save

'==================================================================================
==========================
' Update the results into sheet "STATS_AUTOSYS_JOB_LEVEL" based on Autosys and Log
File. Get count from main sheet

'<Update Code>

ObjWB.Save
ObjWB.Close
ObjXL.Quit
If Obj_AdodbConnection.State = 1 Then Obj_AdodbConnection.close
Call KillProcessor("excel.exe")

'==================================================================================
=
' Generic Functions
'==================================================================================

Public Function Func_FileExists(varFile_DirLoc,


varFile_Name,varExec_msg,objFSO,Obj_ExeLog)
func_Fileexists = "NOT EXIST"
If objFSO.FileExists(varFile_DirLoc & varFile_Name) Then
func_Fileexists = "EXIST"
ElseIf objFSO.FolderExists(varFile_DirLoc) Then
vterminate_msg = varFile_Name & " File is not available in below location
" & Chr(10) & varFile_DirLoc & varFile_Name & Chr(10) & "Execution is stopped"
Else
vterminate_msg = "Folder & File is not available in below location " &
Chr(10) & varFile_DirLoc & "Execution is stopped"
End If
End Function

Public Function Func_TerminateExec(vterminate_msg,Obj_ExeLog)


' End Process wscript.exe if running through VBS and EXIT while running
through UFT
Msgbox vterminate_msg
Obj_ExeLog.WriteLine " # " & vterminate_msg
Obj_ExeLog.Close
Call KillProcessor("excel.exe")
vProjectFdr_Path =
CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") & "\"
If InstR(1, vProjectFdr_Path, "\HP\" ) > 0 Then ExitTest
Call KillProcessor("wscript.exe")
Call KillProcessor("cscript.exe")
End Function

Public Sub KillProcessor(ByVal ProcessName)


Set ObjProcessor = GetObject("winmgmts:{impersonationLevel=impersonate}")
Set ObjprocessSet = ObjProcessor.ExecQuery("Select * from Win32_process")
For Each ObjProcess In ObjprocessSet
If StrComp(ObjProcess.Name, UCase(ProcessName),1) = 0 Then
ObjProcess.Terminate()
Next
End Sub
'==================================== End Sub
=================================================
'========================= i HUB ======================================

End Function

Public Function XL_EXTRACT_SHAREPOINT()


'============== XL sharepoint ===============================
'Initialise all the variables
'vTempFdrLoc = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
& "\"
sharepointUrl = "http://collaboration-wfs-
iceo.mylocal.com/sites/sig/Operations/OpsSolutions_PMO/Data_Services/Shared
%20Documents/UseCases/Volcker/Volcker2FunctionalSpecs/MarketMaking/"
filename = "WFS Volcker Conformance - Market Making Data Capture FSD
APOLLO.docx"
vTempFdrLoc = "C:\temp\"
TempExtractLoc = vTempFdrLoc & "Doc"
ResultXL_DestLoc = vTempFdrLoc
ZipFileLocation = ResultXL_DestLoc & Replace(Ucase(filename),"DOCX","zip")
Embed_XLFdr = TempExtractLoc & "\word\embeddings\"

'Initialise all the objects


Set FSO = CreateObject("Scripting.FileSystemObject")
Set objSA = CreateObject("Shell.Application")
set xmlHttp = createobject("MSXML2.XMLHTTP.3.0")
Set objADOStream = CreateObject("ADODB.Stream")

' Copy the File as Response body from sharepoint save it into a file
xmlhttp.open "GET",sharepointUrl & filename,false
xmlhttp.send
objADOStream.Open
objADOStream.Type = 1 'adTypeBinary
objADOStream.Write xmlhttp.ResponseBody
objADOStream.Position = 0 'Set the stream position to the start
objADOStream.SaveToFile vTempFdrLoc & filename,2

'Check the file existence and extract the XL file from word document
If Cint(xmlhttp.status) = 200 and FSO.FileExists(vTempFdrLoc & filename) Then
FSO.CopyFile vTempFdrLoc & filename, ZipFileLocation,True ' Convert the
DOCX into ZIP file
If FSO.FolderExists(TempExtractLoc)Then FSO.DeleteFile TempExtractLoc &
"\*", true
If FSO.FolderExists(TempExtractLoc)Then FSO.DeleteFolder TempExtractLoc &
"\*", true
If not FSO.FolderExists(TempExtractLoc)Then
FSO.CreateFolder(TempExtractLoc)
Set objSource = objSA.NameSpace(ZipFileLocation).Items ' Collect the ZIP
files
objSA.NameSpace(TempExtractLoc).CopyHere(objSource) ' extract the ZIP file
into temp folder
' Copy the XL files from temp folder where ZIP extracted, folder
location \word\embeddings\
If FSO.FolderExists(Embed_XLFdr)Then
Set EmbdFdr = FSO.GetFolder(Embed_XLFdr)
For Each XLFile in EmbdFdr.Files
vFile_Extension =
Ucase(FSO.GetExtensionName(XLFile.name))
If vFile_Extension = "XLSX" or
vFile_Extension="XLS" then FSO.CopyFile Embed_XLFdr & XLFile.name,
ResultXL_DestLoc, True
XL_Found = true
Next
Else
Msgbox " No XL files inside the document "
End If

If XL_Found <> true then Msgbox "There are no excel files available in
documnet"
FSO.DeleteFile ZipFileLocation,True ' Delete the temp ZIP file which was
converted from word document
FSO.DeleteFolder TempExtractLoc,True ' Delete the temp extrated files
from word document
Else
If Cint(xmlhttp.status) <> 200 Then Msgbox "Unable to copy the file from
sharepoint" & chr(10) & xmlhttp.status & " : " & xmlhttp.statusText
If not FSO.FileExists(vTempFdrLoc & filename) and Cint(xmlhttp.status) =
200 Then Msgbox " File Not Exist in the below location " & Chr(10) & vTempFdrLoc &
filename & chr(10) & xmlhttp.status & " : " & xmlhttp.statusText
End If

xmlhttp.abort
objADOStream.Close
Set FSO = Nothing
Set objSA = Nothing
set xmlHttp = Nothing
Set objADOStream = Nothing

'============== XL sharepoint ===============================


End Function

Public function XML_COMPARISON()


'**********************************************************************************
**************************
'Project Name : SDR - Equities trades validation
'Author : Khadeer
'Creation Date : 10-May-2016
'Module Name : Controller
'Description : Compare 2 XML files using dictionary object
'**********************************************************************************
**************************

'Option Explicit
'==================================================================================
==========================
'Declaration of Variables
'==================================================================================
==========================

Dim vXMLFile_Path_actual, vXMLFile_Path_baseline, vSmpl_FileLoc_actual,


vSmpl_FileLoc_baseline
Dim Obj_FSO, Obj_Dict_Actual, Obj_Dict_Baseline
Dim varf_diff(), varf_DiffCnt

'==================================================================================
==========================
'Initialisation of variable whose values will be constant

vMultiple_XML_CMP = TRUE
vHomeFDR = "C:\temp\"
vHomeFDR =
CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".") & "\"
vXML_PARSED_TXT_FDR = vHomeFDR & "XML_Parsed_TXT\"
vComparison_Reports_FDR = vHomeFDR & "XML_Comparison_Reports\"
vController_XL_FileName = "Galaxy_XML_CMP_Controller.xlsx"
vController_XL_FullPath = vHomeFDR & vController_XL_FileName

vXMLFile_Path_actual = vHomeFDR & "Galxy_XML_95_box_TO160421-76-


equityOption.txt"
vXMLFile_Path_baseline = vHomeFDR & "STV_TO160421-76-
equityOption_94_box_generated.xml"
vComparison_Report_Fmt = "EXCEL"

Select Case Msgbox("Please Save the excel files opened and click OK" & Chr(10) &
"Cancel will stop execution",1)
Case 1 Call KillProcessor("EXCEL.EXE")
Case 2 Msgbox "Execution is stopped"
Call KillProcessor("wscript.exe")
End Select
'==================================================================================
==========================
'Defining the class objects FSO, Wscript, Excel, Dictionary

Set Obj_FSO = CreateObject("Scripting.FileSystemObject")


Set Obj_Dict_Actual = CreateObject("Scripting.Dictionary")
Set Obj_Dict_Baseline = CreateObject("Scripting.Dictionary")
Set Obj_Wsh = CreateObject("Wscript.Shell")
Set ObjXL_Main = CreateObject("Excel.Application")
ObjXL_Main.Visible = False
ObjXL_Main.DisplayAlerts = False

If Not Obj_FSO.FolderExists(vXML_PARSED_TXT_FDR) Then


Obj_FSO.CreateFolder(vXML_PARSED_TXT_FDR)
If Not Obj_FSO.FolderExists(vComparison_Reports_FDR) Then
Obj_FSO.CreateFolder(vComparison_Reports_FDR)

Do
If vMultiple_XML_CMP <> True Then
vXMLFile_Path_actual = InputBox("Enter the Actual XML File Location
with Name and format","XML File 1 Location",vXMLFile_Path_actual)
vXMLFile_Path_baseline = InputBox("Enter the Baseline XML File Location
with Name and format","XML File 2 Location",vXMLFile_Path_baseline)
vComparison_Report_Fmt = InputBox("Required in EXCEL / CSV","Result
Format", vComparison_Report_Fmt)
vResultFileName = "XMLCMP_" &
Left(Split(Split(vXMLFile_Path_baseline,".")(0),"\")
(ubound(Split(Split(vXMLFile_Path_baseline,".")(0),"\"))),10) & "_" & Day(Date) &
Month(Date) & Hour(Time) & Minute(Time)
vResultFileNameLoc = vComparison_Reports_FDR & vResultFileName
varf_ScenarioName = Left(Split(Split(vXMLFile_Path_baseline,".")
(0),"\")(ubound(Split(Split(vXMLFile_Path_baseline,".")(0),"\"))),15)
Call
XML_Comparison_Main(vHomeFDR,vXML_PARSED_TXT_FDR,vComparison_Reports_FDR,vXMLFile_P
ath_actual,vXMLFile_Path_baseline,vComparison_Report_Fmt,_

Obj_FSO,Obj_Dict_Actual,Obj_Dict_Baseline,Obj_Wsh,ObjXL_Main,varf_ScenarioName,vRes
ultFileNameLoc,vXMLCMP_Remarks,vXML_ComparisonStatus,varf_DiffCnt)
If vXML_ComparisonStatus = "FAIL" and Instr(1,vXMLCMP_Remarks,"XML
Comparison Failed") > 0 Then vAuto_open_Result_report = "DON'T OPEN"
vFinal_Result_Report = vResultFileNameLoc
Exit Do
End If

'==================================================================================
==========================
'Fetch the column Number from configuration sheet for few attributes
If Not Obj_FSO.FileExists(vController_XL_FullPath) Then
Msgbox "Controller XL File Not exists" & Chr(10) & vController_XL_FullPath
Exit Do
End If
vFinal_Result_Report = vComparison_Reports_FDR & "XML_Result_Report_" &
Day(Date) & Month(Date) & Hour(Time) & Minute(Time) & ".xlsx"
Obj_FSO.CopyFile vController_XL_FullPath, vFinal_Result_Report
Set ObjWB_Main = ObjXL_Main.Workbooks.Open(vFinal_Result_Report)
Set ObjWS_Main = ObjXL_Main.Worksheets("Galaxy_XML_CMP")

vTotCol_Main = Cint(ObjWS_Main.UsedRange.Columns.Count)
vTotRow_Main = Cint(ObjWS_Main.UsedRange.Rows.Count)

If vTotCol_Main > 20 Then vTotCol_Main = 20 ' handling the


mistakes while copying or unwanted test data
If vTotCol_Main > 26 Then
vAlphaExcl_TotCol_Used = "A" & Chr(vTotCol_Main + 38)
Else
vAlphaExcl_TotCol_Used = Chr(vTotCol_Main + 64)
End If

vRowNoConf = 1

Scenario_Name_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &


vAlphaExcl_TotCol_Used & vRowNoConf).Find("Scenario_Name").Column
ProductType_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("ProductType").Column
Trade_ID_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Trade_ID").Column
XML_FileName_Galaxy_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("XML_FileName_Galaxy").Column
XML_FileName_DS_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("XML_FileName_DS").Column
Set_Flag_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Set_Flag").Column
Max_No_Diff_Report_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Max_No_Diff_Report").Column
Result_Format_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Result_Format").Column
Execution_Status_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Execution_Status").Column
Total_No_Diff_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Total_No_Diff").Column
Result_Report_Location_ColNo = ObjWS_Main.Range("A" & vRowNoConf & ":" &
vAlphaExcl_TotCol_Used & vRowNoConf).Find("Result_Report_Location").Column

For vXLRowNo = vRowNoConf+1 To vTotRow_Main

If ObjWS_Main.Cells(vXLRowNo,Set_Flag_ColNo).Value = "Y" Then


vScenario_Name =
Trim(ObjWS_Main.Cells(vXLRowNo,Scenario_Name_ColNo).Value)
vProductType =
Trim(ObjWS_Main.Cells(vXLRowNo,ProductType_ColNo).Value)
vTrade_ID =
Trim(ObjWS_Main.Cells(vXLRowNo,Trade_ID_ColNo).Value)
vXMLFile_Path_actual =
Trim(ObjWS_Main.Cells(vXLRowNo,XML_FileName_Galaxy_ColNo).Value)
vXMLFile_Path_baseline =
Trim(ObjWS_Main.Cells(vXLRowNo,XML_FileName_DS_ColNo).Value)
vMax_No_Diff_Report =
Trim(ObjWS_Main.Cells(vXLRowNo,Max_No_Diff_Report_ColNo).Value)
vComparison_Report_Fmt =
Trim(ObjWS_Main.Cells(vXLRowNo,Result_Format_ColNo).Value)
varf_ScenarioName = Replace(vProductType & "_" &
vTrade_ID," ","")
vResultFileName = varf_ScenarioName & "_" &
Day(Date) & Month(Date) & Hour(Time) & Minute(Time)
vResultFileNameLoc = vComparison_Reports_FDR &
vResultFileName
varf_DiffCnt = 0
Call
XML_Comparison_Main(vHomeFDR,vXML_PARSED_TXT_FDR,vComparison_Reports_FDR,vXMLFile_P
ath_actual,vXMLFile_Path_baseline,vComparison_Report_Fmt,_

Obj_FSO,Obj_Dict_Actual,Obj_Dict_Baseline,Obj_Wsh,ObjXL_Main,varf_ScenarioName,vRes
ultFileNameLoc,vXMLCMP_Remarks,vXML_ComparisonStatus,varf_DiffCnt)

ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo).Font.Bold =
True
If varf_DiffCnt > 0 Then
ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo) =
"FAIL"
ObjWS_Main.Cells(vXLRowNo,Total_No_Diff_ColNo) =
varf_DiffCnt

ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo).Interior.ColorIndex = 3
Else
ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo) =
"PASS"
ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo).Interior.ColorIndex = 4
End If

If Instr(1,vXMLCMP_Remarks,"XML Comparison Failed") > 0 Then


ObjWS_Main.Cells(vXLRowNo,Result_Report_Location_ColNo) =
vXMLCMP_Remarks
Else
ObjWS_Main.Hyperlinks.add
ObjWS_Main.Range(Chr(Result_Report_Location_ColNo + 64) &
vXLRowNo),vResultFileNameLoc,,,varf_ScenarioName
End If

ElseIf ObjWS_Main.Cells(vXLRowNo,Set_Flag_ColNo).Value = "N" Then


ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo) = "Not
Executed"

ObjWS_Main.Cells(vXLRowNo,Execution_Status_ColNo).Interior.ColorIndex = 15
ObjWS_Main.Cells(vXLRowNo,Result_Report_Location_ColNo) =
""
Else
ObjWS_Main.Cells(vXLRowNo,Result_Report_Location_ColNo) =
"Empty Line, Please delete from Main Controller file"
End If

Next
ObjWB_Main.Save
ObjWB_Main.Close
Exit Do
Loop
ObjXL_Main.Quit
Call KillProcessor("Excel.exe")

' De-allocate the memory of the object


Set Obj_FSO = Nothing
Set Obj_Dict_Actual = Nothing
Set Obj_Dict_Baseline = Nothing

If vAuto_open_Result_report <> "DON'T OPEN" then


MsgBox " XML Comparison Completed "
CreateObject("Wscript.Shell").run Chr(34) & vFinal_Result_Report &
Chr(34),1,1
Else
Msgbox vXMLCMP_Remarks
End If

Public Function
XML_Comparison_Main(vHomeFDR,vXML_PARSED_TXT_FDR,vComparison_Reports_FDR,vXMLFile_P
ath_actual,vXMLFile_Path_baseline,vComparison_Report_Fmt,_

Obj_FSO,Obj_Dict_Actual,Obj_Dict_Baseline,Obj_Wsh,ObjXL_Main,varf_ScenarioName,vRes
ultFileNameLoc,vXMLCMP_Remarks,vXML_ComparisonStatus,varf_DiffCnt)

vSmpl_FileLoc_actual = vXML_PARSED_TXT_FDR &


Split(Split(vXMLFile_Path_actual,".")(0),"\")
(ubound(Split(Split(vXMLFile_Path_actual,".")(0),"\"))) & ".txt"
vSmpl_FileLoc_baseline = vXML_PARSED_TXT_FDR &
Split(Split(vXMLFile_Path_baseline,".")(0),"\")
(ubound(Split(Split(vXMLFile_Path_baseline,".")(0),"\"))) & ".txt"
varf_DiffCnt = 0
' Check the XML file avaibility
If (Not Obj_FSO.FileExists(vXMLFile_Path_actual)) and (Not
Obj_FSO.FileExists(vXMLFile_Path_baseline)) Then
vXMLCMP_Remarks = "XML Comparison Failed" & Chr(10) & "XML given
in Actual & baseline are not Available in below location " & Chr(10) &
vXMLFile_Path_actual & Chr(10) & vXMLFile_Path_baseline
vXML_ComparisonStatus = "FAIL"
Exit Function
ElseIf Not Obj_FSO.FileExists(vXMLFile_Path_baseline) Then
vXMLCMP_Remarks = "XML Comparison Failed" & Chr(10) & "XML given
in Baseline is not Available in below location " & Chr(10) & vXMLFile_Path_baseline
vXML_ComparisonStatus = "FAIL"
Exit Function
ElseIf Not Obj_FSO.FileExists(vXMLFile_Path_actual) Then
vXMLCMP_Remarks = "XML Comparison Failed" & Chr(10) & "XML given
in Actual is not Available in below location " & Chr(10) & vXMLFile_Path_actual
vXML_ComparisonStatus = "FAIL"
Exit Function
End If

' Load the XML content into dictionary object


Call f_LoadXML_DictObj_TXTFile ( vXMLFile_Path_actual, Obj_Dict_Actual,Obj_FSO,
vSmpl_FileLoc_actual, vStatus, vRemarks)
Call f_LoadXML_DictObj_TXTFile ( vXMLFile_Path_baseline,
Obj_Dict_Baseline,Obj_FSO, vSmpl_FileLoc_baseline, vStatus, vRemarks)

' Compare the contents in actual & baseline Object dictionary


Call func_CMP_DictObjects_Array ( Obj_Dict_Actual,
Obj_Dict_Baseline,varf_diff,varf_DiffCnt,vStatus, vRemarks )

' Genrate the Result report based on the values present in array varf_diff
Select Case Ucase(vComparison_Report_Fmt)
Case "CSV"
vResultFileNameLoc = vResultFileNameLoc & ".csv"
Call f_ResultReporting_CSV (varf_diff,
varf_ScenarioName,ObjXL_Main,vResultFileNameLoc, vResultReportExcel_Status)
Case "EXCEL"
vResultFileNameLoc = vResultFileNameLoc & ".xlsx"
Call f_ResultReporting_Excel (varf_diff,
varf_ScenarioName,ObjXL_Main,vResultFileNameLoc, vResultReportExcel_Status)
End Select

Obj_Dict_Actual.RemoveAll
Obj_Dict_Baseline.RemoveAll

End Function

Public Function f_LoadXML_DictObj_TXTFile( vXMLFile_Path, Obj_Dict_Map, Obj_FSO,


vSmpl_FileLoc, vStatus, vRemarks)

' Initialize variables


ctr = 1
vStatus = Empty
XML_EOL = False
vParentNode = Empty
' Define Objects
' Set Obj_XML = CreateObject("Microsoft.XMLDOM")
Set Obj_XML = CreateObject("MSXML2.DOMDocument")
Set ObjDict_Index = CreateObject("Scripting.Dictionary")
Set ObjWrt_XMLparser = Obj_FSO.OpenTextFile (vSmpl_FileLoc,2,True)

' Load XML file into DOM object


Obj_XML.async = False
Obj_XML.load vXMLFile_Path

' Wait for the XML file to be loaded into DOM object
Do
' "Wscript.sleep 10000" wont work in UFT & "wait" won't work in VBS, an
alternate way to delay script by running the ping cmd in back ground
CreateObject("wscript.Shell").Run "%COMSPEC% /c ping -n " & ctr & "
127.0.0.1>nul",0,1
ctr = ctr + 1
If ctr = 10 Then Msgbox " Unable to load XML" ' Counter help to come
out of loop if XML is loaded in 45 seconds
If Obj_XML.ReadyState = 4 Then Exit Do ' ' ReadyState = 4
indicates XML load into DOM is complete
Loop

' Exit Function if XML is not loaded into DOM


If Obj_XML.ReadyState <> 4 Then
vStatus = "Fail"
Exit Function
End If

If Obj_XML.childnodes.length > 0 Then

' Store all attributes and elements of each node with index value into dictionary
object and also save the same into sample txt file
For PNodeCnt = 1 to Obj_XML.childnodes.length
Set Obj_XMLDOM = Obj_XML.childnodes
PNode_strt = 1
PNode_LevelCnt = 1
vCurLevel = 1
vCurIndex = 1
Execute "vNodeLevel" & PNode_LevelCnt & "_index=" & PNode_strt
currChildNode = Trim(Obj_XMLDOM.item(PNodeCnt-1).NodeName) & "[" &
PNode_strt-1 & "]/"
ObjDict_Index.Add Trim(Obj_XMLDOM.item(PNodeCnt-1).NodeName) & "/",
PNode_strt-1
Execute "vChildNodeIndex" & PNode_LevelCnt & " = " & Chr(34) &
currChildNode & Chr(34)
Execute "vChildNode_With_Index = " & "vChildNodeIndex" &
PNode_LevelCnt
Call func_CheckAttribute_AddDict (Obj_XMLDOM, PNodeCnt-1,
vChildNode_With_Index, Obj_Dict_Map, ObjWrt_XMLparser)
Execute "Node_index = Cint(" & "vNodeLevel" & PNode_LevelCnt &
"_index)"
Execute "vNodeLevel" & PNode_LevelCnt &" = " & Chr(34) & ".item(" &
PNodeCnt-1 & ").ChildNodes" & Chr(34)
Execute "Node_siblings = " & "vNodeLevel" & PNode_LevelCnt
Do
Execute "Set Obj_XMLDOM_CH = " & "Obj_XMLDOM" &
Node_siblings
If Obj_XMLDOM_CH.length > 0 Then
vStartIndex = 1
PNode_LevelCnt = PNode_LevelCnt + 1
Execute "vnum1 = vNodeLevel" & PNode_LevelCnt &
"_index"
vCurIndex = cint(vnum1) + vStartIndex

if Instr(1,Trim(Obj_XMLDOM_CH.item(vCurIndex-
1).NodeName),"#text") > 0 then
' Execute "vCurIndex_tmp = vNodeLevel" &
PNode_LevelCnt-1 & "_index"
Execute "vchild_temp1 = " & "vChildNodeIndex"
& PNode_LevelCnt-2
vNewKey = vchild_temp1 &
Trim(Obj_XMLDOM_CH.item(vCurIndex-1).parentnode.NodeName)
If ObjDict_Index.Exists(vNewKey) Then
ObjDict_Index.Item(vNewKey) = ObjDict_Index(vNewKey) - 1
Else
Execute "vchild_temp1 = " & "vChildNodeIndex"
& PNode_LevelCnt-1
vNewKey = vchild_temp1 &
Trim(Obj_XMLDOM_CH.item(vCurIndex-1).NodeName)

End If

If ObjDict_Index.Exists(vNewKey) Then
New_indexValue = ObjDict_Index(vNewKey) + 1
ObjDict_Index.Item(vNewKey) =
New_indexValue
Else
New_indexValue = 0
ObjDict_Index.Add vNewKey,New_indexValue
End If
currChildNode = vNewKey & "[" & New_indexValue &
"]/"
Execute "vChildNodeIndex" & PNode_LevelCnt & " = "
& Chr(34) & currChildNode & Chr(34)
Execute "vChildNode_With_Index = " &
"vChildNodeIndex" & PNode_LevelCnt
Call func_CheckAttribute_AddDict (Obj_XMLDOM_CH,
vCurIndex-1, vChildNode_With_Index, Obj_Dict_Map, ObjWrt_XMLparser)
Execute "vNodeLevel" & PNode_LevelCnt & "_index ="&
vCurIndex
Set Obj_XMLDOM_temp = Obj_XMLDOM_CH
Execute "Node_index = Cint(" & "vNodeLevel" &
PNode_LevelCnt & "_index)"
Execute "temp_value1 = " & "vNodeLevel" &
PNode_LevelCnt-1
Execute "temp_value2 = " & Chr(34) & ".item(" &
Node_index-1 & ").ChildNodes" & Chr(34)
Execute "vNodeLevel" & PNode_LevelCnt &" = " &
Chr(34) & temp_value1 & temp_value2 & Chr(34)
Execute "Node_siblings = " & "vNodeLevel" &
PNode_LevelCnt
Else

Call
func_WriteXMLElem_ObjDict_TxtFile(vChildNode_With_Index, vCurIndex-1,
Obj_XMLDOM_temp, Obj_Dict_Map, ObjWrt_XMLparser)
Do
If PNode_LevelCnt <= 1 Then
Exit Do
Execute "vnum =
cint(vNodeLevel" & PNode_LevelCnt & "_index)"
vCurIndex = vnum + 1
Execute "vNodeLevel" &
PNode_LevelCnt & "_index ="& vCurIndex
Execute
"Node_siblings_len_chk = " & "vNodeLevel" & PNode_LevelCnt-1
Execute "Set
Obj_XMLDOM_Len_chk = " & "Obj_XMLDOM" & Node_siblings_len_chk
If Obj_XMLDOM_Len_chk.length
>= vCurIndex Then
Exit Do
Else
Execute "vNodeLevel" &
PNode_LevelCnt & "_index = 0"
Execute
"vChildNodeIndex" & PNode_LevelCnt & " = Empty"
PNode_LevelCnt =
PNode_LevelCnt - 1
End If
Loop
If PNode_LevelCnt <= 1 Then Exit Do
Execute "temp_value1 = " & "vNodeLevel" &
PNode_LevelCnt-1
Execute "Set Obj_XMLDOM_CH_temp = " &
"Obj_XMLDOM" & temp_value1
' CurrChildNode =
Trim(Obj_XMLDOM_CH_temp.item(vCurIndex-1).NodeName) & "[" & vCurIndex-1 & "]/"
Execute "vchild_temp1 = " &
"vChildNodeIndex" & PNode_LevelCnt-1
vNewKey = vchild_temp1 &
Trim(Obj_XMLDOM_CH_temp.item(vCurIndex-1).NodeName)
If ObjDict_Index.Exists(vNewKey) Then
New_indexValue =
ObjDict_Index(vNewKey) + 1
ObjDict_Index.Item(vNewKey) =
New_indexValue
Else
New_indexValue = 0
ObjDict_Index.Add
vNewKey,New_indexValue
End If
currChildNode = vNewKey & "[" &
New_indexValue & "]/"

Execute "vChildNodeIndex" & PNode_LevelCnt &


" = " & Chr(34) & currChildNode & Chr(34)
Execute "vChildNode_With_Index = " &
"vChildNodeIndex" & PNode_LevelCnt
Call func_CheckAttribute_AddDict
(Obj_XMLDOM_CH_temp, vCurIndex-1, vChildNode_With_Index, Obj_Dict_Map,
ObjWrt_XMLparser)
Execute "Node_index = Cint(" & "vNodeLevel"
& PNode_LevelCnt & "_index)"
Execute "temp_value2 = " & Chr(34) &
".item(" & Node_index-1 & ").ChildNodes" & Chr(34)
Execute "vNodeLevel" & PNode_LevelCnt &" = "
& Chr(34) & temp_value1 & temp_value2 & Chr(34)
Execute "Node_siblings = " & "vNodeLevel" &
PNode_LevelCnt

End If
Loop
ObjDict_Index.RemoveAll
Next

Else
vRemarks = "There are no nodes or elements in the XML file"
vStatus = "FAIL"
End If

ObjWrt_XMLparser.close

Set Obj_XML = Nothing


End Function

Public Function func_CheckAttribute_AddDict (V_ObjXMLDOM, V_PNodeCnt,


V_vParentNode, Obj_Dict_Map, ObjWrt_XMLparser)
' Get Attributes from node and store in dictionary
On Error Resume Next
Set Obj_XMLDOM_AT = V_ObjXMLDOM.item(V_PNodeCnt).attributes
Tot_AttriCnt = Obj_XMLDOM_AT.length
If Err.Number <= 0 Then
For AttriCnt = 0 to Tot_AttriCnt-1
Call func_WriteXMLAttr_ObjDict_TxtFile(V_vParentNode,
AttriCnt, Obj_XMLDOM_AT, Obj_Dict_Map, ObjWrt_XMLparser)
Next
End If
On Error Goto 0
End Function

Public Function func_WriteXMLAttr_ObjDict_TxtFile(vParentNode, AttriCnt,


Obj_XMLDOM_AT, Obj_Dict_Map, ObjWrt_XMLparser)
vAtrribute_Name = Trim(Obj_XMLDOM_AT.item(AttriCnt).NodeName)
vAttribute_Value = Trim(Obj_XMLDOM_AT.item(AttriCnt).Value)
Dict_Key = vParentNode & vAtrribute_Name & "[A_" & AttriCnt & "]"
Dict_Value = vAttribute_Value
Obj_Dict_Map.Add Dict_Key, Dict_Value
ObjWrt_XMLparser.WriteLine Dict_Key & " = " & Dict_Value
End Function

Public Function func_WriteXMLElem_ObjDict_TxtFile(vChildNode_With_Index,


V_vCurIndex, Obj_XMLDOM_temp, Obj_Dict_Map, ObjWrt_XMLparser)
On Error Resume Next
vElement_length = Trim(Obj_XMLDOM_temp.item(V_vCurIndex).length)
If Err.Number > 0 or vElement_length = Empty Then
Obj_Dict_Map.Add Split(vChildNode_With_Index,"/#")(0),
"$Broken_XPath/Blank_Value$"
ObjWrt_XMLparser.WriteLine Dict_Key & " = " & Dict_Value
On Error Goto 0
Exit Function
End If
vElement_Value = Trim(Obj_XMLDOM_temp.item(V_vCurIndex).NodeValue)
Dict_Key = Split(vChildNode_With_Index,"/#")(0)
Dict_Value = vElement_Value
Obj_Dict_Map.Add Dict_Key, Dict_Value
ObjWrt_XMLparser.WriteLine Dict_Key & " = " & Dict_Value
On Error Goto 0
End Function

Public Function func_CMP_DictObjects_Array ( Obj_Dict_Actual,


Obj_Dict_Baseline,varf_diff,varf_DiffCnt, vStatus, vRemarks )

vParent_DTobj_max = StrComp(Obj_Dict_Baseline.Count, Obj_Dict_Actual.Count)


vFailure_Cnt = 0

Select Case vParent_DTobj_max


Case 0
vRemarks = "count is matching beteen actual and baseline XMLS"
Case 1
vRemarks = "Baseline XML is having more records than Actual XML"
vStatus = "FAIL"
Case -1
vRemarks = "Actual XML is having more records than Baseline XML"
vStatus = "FAIL"
End Select

For each vKey in Obj_Dict_Baseline


Do
If Obj_Dict_Actual.Exists(vKey) Then
ReDim Preserve varf_diff(varf_DiffCnt)
If Ucase(Obj_Dict_Actual(vKey)) = Ucase(Obj_Dict_Baseline(vKey))
Then
varf_diff(varf_DiffCnt) = "XML Value Match" & "^$!" & vKey &
"^$!" & Obj_Dict_Actual(vKey) & "^$!" & Obj_Dict_Baseline(vKey) & "^$!" & "PASS"
Else
varf_diff(varf_DiffCnt) = "XML Value MisMatch" & "^$!" &
vKey & "^$!" & Obj_Dict_Actual(vKey) & "^$!" & Obj_Dict_Baseline(vKey) & "^$!" &
"FAIL"
vFailure_Cnt = vFailure_Cnt + 1
End If
varf_DiffCnt = varf_DiffCnt + 1
Obj_Dict_Actual.Remove(vKey)

Else
ReDim Preserve varf_diff(varf_DiffCnt)
vFailure_Cnt = vFailure_Cnt + 1
If Obj_Dict_Baseline(vKey) = "$Broken_XPath/Blank_Value$" Then
varf_diff(varf_DiffCnt) = "Xpath Broken Baseline" & "^$!" &
vKey & "^$!" & " - " & "^$!" & Obj_Dict_Baseline(vKey) & "^$!" & "FAIL"
Else
varf_diff(varf_DiffCnt) = "Xpath Missing Actual" & "^$!" &
vKey & "^$!" & " Not available (Missing) " & "^$!" & Obj_Dict_Baseline(vKey) &
"^$!" & "FAIL"
End If
varf_DiffCnt = varf_DiffCnt + 1
End If
Exit Do
Loop

Next
For each vKey in Obj_Dict_Actual
ReDim Preserve varf_diff(varf_DiffCnt)
vFailure_Cnt = vFailure_Cnt + 1
If Obj_Dict_Actual(vKey) = "$Broken_XPath/Blank_Value$" Then
varf_diff(varf_DiffCnt) = "Xpath Broken Actual" & "^$!" & vKey & "^$!" &
Obj_Dict_Actual(vKey) & "^$!" & " - " & "^$!" & "FAIL"
Else
varf_diff(varf_DiffCnt) = "Xpath Missing Baseline" & "^$!" & vKey & "^$!"
& Obj_Dict_Actual(vKey) & "^$!" & " Not available (Missing) " & "^$!" & "FAIL"
End If
varf_DiffCnt = varf_DiffCnt + 1
Next

varf_DiffCnt = vFailure_Cnt

End Function

Public Function f_ResultReporting_Excel (varf_diff,


varf_ScenarioName,ObjXL_Main,vResultFileNameLoc, vResultReportExcel_Status)

vResult_Type_ColNo = 1
vXpath_ColNo = 2
vActual_XML_value_ColNo = 3
vBaseline_XML_value_ColNo = 4
vMatching_Status_ColNo = 5
vTotalNoColUsed_ResultReport = 5
vDiffSheetName = varf_ScenarioName
vStartingRowNo_ResultReport = 3

Set ObjWB_Result = ObjXL_Main.Workbooks.Add


Set ObjWS_ResultReport = ObjWB_Result.Worksheets.Add
ObjWS_ResultReport.Name = vDiffSheetName

vTotRow_ResultReport = Cint(ObjWS_ResultReport.UsedRange.Rows.Count)
If vTotRow_ResultReport < 3 Then

' Defining the Header (First Row) in differnce sheet

ObjWS_ResultReport.Cells(vStartingRowNo_ResultReport-1,
vResult_Type_ColNo).Value = "Result Type"
ObjWS_ResultReport.Cells(vStartingRowNo_ResultReport-1,
vXpath_ColNo).Value = "Xpath With Index"
ObjWS_ResultReport.Cells(vStartingRowNo_ResultReport-1,
vActual_XML_value_ColNo).Value = "Actual XML Value"
ObjWS_ResultReport.Cells(vStartingRowNo_ResultReport-1,
vBaseline_XML_value_ColNo).Value = "Baseline XML Value"
ObjWS_ResultReport.Cells(vStartingRowNo_ResultReport-1,
vMatching_Status_ColNo).Value = "Matching Status"

ObjWS_ResultReport.columns("A:E").select
ObjXL_Main.Selection.NumberFormat = "@"

Else
vStartingRowNo_ResultReport = vTotRow_ResultReport + 1
End If

For vResultReportCnt = 0 To Ubound(varf_diff)


vResultReport_RecSplit =
Split(varf_diff(vResultReportCnt),"^$!")
ObjWS_ResultReport.Range("A" & vStartingRowNo_ResultReport & ":" &
Chr(vTotalNoColUsed_ResultReport + 64) & vStartingRowNo_ResultReport).Value =
vResultReport_RecSplit
vStartingRowNo_ResultReport = vStartingRowNo_ResultReport + 1
Next

ObjWS_ResultReport.Range("A1:E" & vStartingRowNo_ResultReport-


1).Borders.LineStyle = xlContinuous
ObjWS_ResultReport.Range("A1:E" & vStartingRowNo_ResultReport-
1).Borders.color = vbBlack

' Defining the Header (First Row) in differnce sheet


ObjWS_ResultReport.Cells(1,1).Value = " XML Comparison Report - " &
Chr(34) & varf_ScenarioName & Chr(34)
ObjWS_ResultReport.Range("A1:" & Chr(vTotalNoColUsed_ResultReport + 64) &
"1").MergeCells = True
ObjWS_ResultReport.Range("A1:" & Chr(vTotalNoColUsed_ResultReport + 64) &
"1").Interior.ColorIndex = 40
ObjWS_ResultReport.Range("A1:" & Chr(vTotalNoColUsed_ResultReport + 64) &
"1").HorizontalAlignment = -4108
ObjWS_ResultReport.Range("A1:" & Chr(vTotalNoColUsed_ResultReport + 64) &
"1").Font.Bold = True

ObjWS_ResultReport.Range("A2" & ":" & Chr(vTotalNoColUsed_ResultReport +


64) & "2").Font.Bold = True
ObjWS_ResultReport.Range("A2" & ":" & Chr(vTotalNoColUsed_ResultReport +
64) & "2").Font.Size = 12
ObjWS_ResultReport.Range("A2" & ":" & Chr(vTotalNoColUsed_ResultReport +
64) & "2").Interior.Colorindex = 37
ObjWS_ResultReport.Range("A2" & ":" & Chr(vTotalNoColUsed_ResultReport +
64) & "2").HorizontalAlignment = -4108

ObjWS_ResultReport.Activate

For Each vSheet_to_Delete In ObjWB_Result.Sheets


If InStr(1, vSheet_to_Delete.Name, "Sheet") > 0 Then
vSheet_to_Delete.Delete
Next
ObjWS_ResultReport.Range("B2").AutoFilter

ObjXL_Main.Columns(1).columnwidth = 20
ObjXL_Main.Columns(2).columnwidth = 112
ObjXL_Main.Columns(3).columnwidth = 30
ObjXL_Main.Columns(4).columnwidth = 30
ObjXL_Main.Columns(5).columnwidth = 20

vResultReportExcel_Status = "PASS"
ObjWB_Result.Worksheets(vDiffSheetName).Visible = True

ObjWB_Result.SaveAs vResultFileNameLoc
ObjWB_Result.Close

End Function

Public Function f_ResultReporting_CSV (varf_diff,


varf_ScenarioName,ObjXL_Main,vResultFileNameLoc, vResultReportExcel_Status)

vDelimiter = Chr(124) & Chr(124)

If Obj_FSO.FileExists(vResultFileNameLoc) Then
Set ObjWrt_ResultReportCSV =
Obj_FSO.OpenTextFile(vResultFileNameLoc , 8 ,True)
Else
Set ObjWrt_ResultReportCSV =
Obj_FSO.OpenTextFile(vResultFileNameLoc , 2 ,True)
ObjWrt_ResultReportCSV.WriteLine "Result Type" & vDelimiter & "Xpath With
Index" & vDelimiter & "Actual XML Value" & vDelimiter & "Baseline XML Value" &
vDelimiter & "Matching Status"
End If

For vResultReportCnt = 0 To Ubound(varf_diff)


vStartingRowNo_ResultReport = vStartingRowNo_ResultReport + 1
ObjWrt_ResultReportCSV.WriteLine
Replace(Replace(varf_diff(vResultReportCnt),"^$!",vDelimiter), Chr(44), "`")
Next

vResultReportExcel_Status = "PASS"
ObjWrt_ResultReportCSV.Close

End Function

'==================================================================================
==========================
'Generic Function Name : Kill Windows Process
'Description :
'==================================================================================

Public Sub KillProcessor(ByVal ProcessName)


Set ObjProcessor = GetObject("winmgmts:{impersonationLevel=impersonate}")
Set ObjprocessSet = ObjProcessor.ExecQuery("Select * from Win32_process")
For Each ObjProcess In ObjprocessSet
If StrComp(ObjProcess.Name, UCase(ProcessName),1) = 0 Then
ObjProcess.Terminate()
Next
End Sub

'==================================== End Sub


================================================

End Function

'****************************************End Of Compare 2 XML files using


dictionary
object********************************************************************

Public Function JSON_XML_to_CSV_conversion()

'===================== FACS trade attributes


==============================================
set xmlDoc = CreateObject("Msxml2.DOMDocument")
'Object creations
'********************************************************************************
Set objFileToWrite = CreateObject("Scripting.FileSystemObject")
'set xmlDoc = CreateObject("Msxml2.DOMDocument")
Set Obj_Wsh = CreateObject("Wscript.Shell")

vPlinkExe_Location = "C:\temp\KRegression_Tool\pTools"
varf_TC_UnixBox_HostName = "wppra93a0201.mylocal.com"
vUnixConn_Server_USN = "u448515"
vUnixConn_Server_PWD = "Apr0417$"
Json_FileLocation_unix = "/opt/cdhprd/daas/cdbo-message-
ingestion/raw_message_store/"
Json_FileName = "messages20170102.json"
'Json_FileName = inputbox("Enter the JSON File Name")
Json_FileName_location = Json_FileLocation_unix & Json_FileName
vGrepJson_Command = Chr(34) & "grep -i 'swap' " & Json_FileName_location
& " |head -10" & Chr(34)
vJsonOutput_FileLocation = "C:\temp\json_output.json"
vTotalRecordCount = 0
keyword_cnt_tot = 0
Jsonlines = 0
TempXMLFile = "C:\temp\tradeSample.xml"
TempKeywordFile = "C:\temp\TradeAttribute.txt"
vTimer_Start = Timer

vDelimiter = Chr(34) & "|" & Chr(34)


vEffdate = "20171202"
vSourceSubsystemName = "DataService"
vRecordCount = 0
vAll_commodities_products =
"CommodityCapFloor,CommodityCptyCredit,CommodityForward,CommodityImbalance,Commodit
yParkAndLoan,CommodityStorage,CommodityStorageBalance,CommodityStructProd,Commodity
Swap,CommoditySwaption," &_
"CommodityTransportation,CommodityTRSwap,EngyFee,floor"

vPlinkExe_Location_Split = Split(vPlinkExe_Location,":\")
vExecute_CMD_Prompt = "cmd /c " & vPlinkExe_Location_Split(0) & ":" &
"&cd \ &cd " & Chr(34) & vPlinkExe_Location_Split(1) & Chr(34) & "&plink " &
varf_TC_UnixBox_HostName & _
" -l " & vUnixConn_Server_USN & " -pw " &
vUnixConn_Server_PWD & " " & vGrepJson_Command & " > " & vJsonOutput_FileLocation &
" & exit"

'Obj_Wsh.Run vExecute_CMD_Prompt,0,True

If Not objFileToWrite.FileExists(vJsonOutput_FileLocation) Then wait 2


If objFileToWrite.FileExists(vJsonOutput_FileLocation) and
objFileToWrite.GetFile(vJsonOutput_FileLocation).Size > 0 Then

'Declaring File Paths and File Names


'******************************************************************************
Set ObjFSO_ReadJson =
objFileToWrite.OpenTextFile(vJsonOutput_FileLocation,1)
Set Obj_Write_Trade = objFileToWrite.OpenTextFile(TempKeywordFile,2,true)
Obj_Write_Trade.WriteLine Chr(34) & "Effdate" & vDelimiter &
"FrontOfficeSystemName" & vDelimiter & "SourceSubsystemName" & vDelimiter &
"FrontOfficeReferenceID" & vDelimiter & "Product" & vDelimiter &_
"Currency" & vDelimiter & "OTC" & vDelimiter &
"AttributeType" & vDelimiter & "AttributeTypeId" & vDelimiter &
"AtrributeClassification" & vDelimiter & "AttributeName" & vDelimiter &
"AttributeValue" & Chr(34)

Do until ObjFSO_ReadJson.AtEndOfStream
Jsonlines = Jsonlines + 1
vSingleXML = ObjFSO_ReadJson.ReadLine
vSingleXML_split = Split(vSingleXML,Chr(34) & "body" & Chr(34) & ":"
& Chr(34))
No_Of_proxyproductleg = 0
Do
If ubound(vSingleXML_split) <= 0 Then Exit Do
vFinalXML = Replace(Replace(Split(vSingleXML_split(1),Chr(34)
& Chr(44) & Chr(34))(0),"\" & Chr(34),Chr(34)), "\n",Chr(13) & Chr(10))
Set Obj_Write_XML =
objFileToWrite.OpenTextFile(TempXMLFile,2,true)
Obj_Write_XML.WriteLine vFinalXML
Obj_Write_XML.Close

'Load the xml document


'*********************************************************************************
xmlDoc.async="false"
xmlDoc.load(TempXMLFile)

'Traversing through the nodes for proxyproductleg_node


'*********************************************************************************

Set frontOfficeSysName_node =
xmlDoc.selectNodes("//req:bo_request/source")
frontOfficeSysName_Val
=frontOfficeSysName_node.item(0).text

Set frontOfficeReferenceID_node =
xmlDoc.selectNodes("//req:bo_request/trade/tradeId")
frontOfficeReferenceID_Val =
frontOfficeReferenceID_node.item(0).text

vFrst_ProxyProduct_Xpath =
"//req:bo_request/trade/proxyProduct/"
Set proxyproductleg_node =
xmlDoc.selectNodes(vFrst_ProxyProduct_Xpath & "proxyType")
No_Of_proxyproductleg = proxyproductleg_node.length - 1

If No_Of_proxyproductleg >= 0 Then


vProxyType = proxyproductleg_node.item(0).text
ExecuteOnly_frst_PrxyPrdt_leg = ""
ExecuteOnly_Secnd_PrxyPrdt_leg = ""
OnlyRefentity_swap = ""
Execute_Attribute_type_leg = "vAttr_type = "
& Chr(34) & "Leg" & Chr(34)
Execute_Attribute_type_outside = "vAttr_type = "
& Chr(34) & "" & Chr(34)
Trigger_Run_Main_Script = FALSE
vProd_OTC_CURR_Non_STRUC = TRUE
If ucase(vProxyType) = "CDSINDEX" or
ucase(vProxyType) = "CREDITDEFAULTSWAP" or ucase(vProxyType)="CDSSTRUCTPROD" Then
ExecuteOnly_frst_PrxyPrdt_leg =
"No_first_prxprdt_leg_length = 0"
ExecuteOnly_Secnd_PrxyPrdt_leg =
"No_secnd_prxprdt_leg_length = 0"
ExecuteOnly_third_PrxyPrdt_leg =
"No_third_prxprdt_leg_length = 0"

Execute_Attribute_type_outside = "vAttr_type = " & Chr(34) & "Product" & Chr(34)

OnlyRefentity_swap = "/refEntity"
Trigger_Run_Main_Script = TRUE
ElseIf ucase(vProxyType) = "SWAP" or
ucase(vProxyType) = "CAP" or ucase(vProxyType) = "FRA" or ucase(vProxyType) =
"TREASURYLOCK" Then
Trigger_Run_Main_Script = TRUE

ElseIf ucase(vProxyType) = "STRUCTUREDPRODUCT"


Then
Trigger_Run_Main_Script = TRUE
vProd_OTC_CURR_Non_STRUC = FALSE
ElseIf Instr(1, Ucase(vAll_commodities_products),
Ucase(vProxyType)) > 0 Then
vcommodities_products_split =
Split(vAll_commodities_products ,Chr(44))
For each Commodity_producttype in
vcommodities_products_split
If Ucase(Commodity_producttype)
= Ucase(vProxyType) Then
Trigger_Run_Main_Script =
TRUE
Exit For
End If
Next
End If

If Trigger_Run_Main_Script = TRUE Then


Trigger_Run_Main_Script = FALSE
Call
vProduct_OTC_Currency(vFrst_ProxyProduct_Xpath, vProduct_Val, vCurrency_Val,
vOTC_Val)
Set frst_proxprdt_leg =
xmlDoc.selectNodes(vFrst_ProxyProduct_Xpath & "leg")
No_first_prxprdt_leg_length =
frst_proxprdt_leg.length-1

If No_first_prxprdt_leg_length >=
0 Then
Execute
ExecuteOnly_frst_PrxyPrdt_leg
Execute
Execute_Attribute_type_leg
For
vFrstPrxprdt_leg_cnt = 0 To No_first_prxprdt_leg_length
Set
frst_proxprdt_leg_node = xmlDoc.selectNodes(vFrst_ProxyProduct_Xpath & "leg[" &
vFrstPrxprdt_leg_cnt & "]")
Set
frst_proxprdt_leg_legid =
frst_proxprdt_leg_node.item(0).Getelementsbytagname("legId")
If
frst_proxprdt_leg_legid.length > 0 Then attr_Type_Id_Val =
frst_proxprdt_leg_legid.Item(0).text

vProductTypeNode_Xpath = vFrst_ProxyProduct_Xpath & "leg[" & vFrstPrxprdt_leg_cnt &


"]"
Call
CashFlow_XMLBLOB_Extract(vProductTypeNode_Xpath,vEffdate,frontOfficeSysName_Val,vSo
urceSubsystemName,frontOfficeReferenceID_Val,vProduct_Val,vCurrency_Val,_

vOTC_Val,vAttr_type,attr_Type_Id_Val,attr_class_Val,attr_name_Val,attr_Val_Val,Obj_
Write_Trade)

Set
frst_proxprdt_leg_xmlblob_node = xmlDoc.selectNodes(vFrst_ProxyProduct_Xpath &
"leg[" & vFrstPrxprdt_leg_cnt & "]/xml_blob")

frst_proxprdt_leg_xmlblob_length = frst_proxprdt_leg_xmlblob_node.length-1
If
frst_proxprdt_leg_xmlblob_length>=0 Then
For
frst_proxprdt_leg_xmlblob_length_cnt = 0 To frst_proxprdt_leg_xmlblob_length
Set
frst_proxprdt_leg_xmlblob =
frst_proxprdt_leg_xmlblob_node.item(frst_proxprdt_leg_xmlblob_length_cnt).childNode
s

frst_proxprdt_leg_xmlblob_lenth = frst_proxprdt_leg_xmlblob.length-1
For
Frst_proxprdt_leg_xmbob_cnt = 0 To frst_proxprdt_leg_xmlblob_lenth

attr_class_Val =
frst_proxprdt_leg_xmlblob.item(Frst_proxprdt_leg_xmbob_cnt).nodeName

attr_Name_Val =
frst_proxprdt_leg_xmlblob.item(Frst_proxprdt_leg_xmbob_cnt).nodeName

attr_Val_Val = frst_proxprdt_leg_xmlblob.item(Frst_proxprdt_leg_xmbob_cnt).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val & _

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1
Next
Next
End If
Next
End If

Set frst_proxprdt_xmlblob_node =
xmlDoc.selectNodes(vFrst_ProxyProduct_Xpath & "xml_blob" & OnlyRefentity_swap)
If frst_proxprdt_xmlblob_node.length >
0 Then
Set attr_Type_Id_Elmt =
frst_proxprdt_xmlblob_node.item(0).childnodes
Execute
Execute_Attribute_type_outside
attr_Type_Id_Val = ""
For
frst_xmlblob_childnodes_cnt = 0 To attr_Type_Id_Elmt.length-1
Set
ref_Entity_Elmt = attr_Type_Id_Elmt.item(frst_xmlblob_childnodes_cnt).childNodes

ref_Entitiy_Child_Length = ref_Entity_Elmt.length-1

If
ref_Entitiy_Child_Length = 0 Then

attr_class_Val = ref_Entity_Elmt.item(0).parentNode.nodeName

attr_Name_Val = ref_Entity_Elmt.item(0).parentNode.nodeName

attr_Val_Val = ref_Entity_Elmt.item(0).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1
ElseIf
ref_Entitiy_Child_Length >= 1 Then

For
refEntityIterator = 0 To ref_Entitiy_Child_Length

attr_class_Val = ref_Entity_Elmt.item(refEntityIterator).parentNode.nodeName

attr_Name_Val = ref_Entity_Elmt.item(refEntityIterator).nodeName

attr_Val_Val = ref_Entity_Elmt.item(refEntityIterator).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)


vRecordCount = vRecordCount + 1
Next
End If
Next
End If

Set second_prxprdt_main =
xmlDoc.selectNodes(vFrst_ProxyProduct_Xpath & "proxyProduct")
No_secnd_prxprdt_length =
second_prxprdt_main.length-1
If No_secnd_prxprdt_length >= 0 Then
For vsecndPrxprdt_cnt = 0 To
No_secnd_prxprdt_length
second_prxprdt_xpath =
vFrst_ProxyProduct_Xpath & "proxyProduct[" & vsecndPrxprdt_cnt & "]"
Set second_prxprdt =
xmlDoc.selectNodes(second_prxprdt_xpath)
If
vProd_OTC_CURR_Non_STRUC = TRUE Then Call
vProduct_OTC_Currency(second_prxprdt_xpath & "/", vProduct_Val, vCurrency_Val,
vOTC_Val)
Set second_proxprdt_leg
= xmlDoc.selectNodes(second_prxprdt_xpath & "/leg")

No_secnd_prxprdt_leg_length = second_proxprdt_leg.length-1

If
No_secnd_prxprdt_leg_length >= 0 Then

Execute ExecuteOnly_Secnd_PrxyPrdt_leg

Execute Execute_Attribute_type_leg
For
vsecndPrxprdt_leg_cnt = 0 To No_secnd_prxprdt_leg_length

Set secnd_proxprdt_leg_node = xmlDoc.selectNodes(second_prxprdt_xpath & "/leg[" &


vsecndPrxprdt_leg_cnt & "]")

Set secnd_proxprdt_leg_legid =
secnd_proxprdt_leg_node.item(0).Getelementsbytagname("legId")

If secnd_proxprdt_leg_legid.length > 0 Then attr_Type_Id_Val =


secnd_proxprdt_leg_legid.Item(0).text

vProductTypeNode_Xpath = second_prxprdt_xpath & "/leg[" & vsecndPrxprdt_leg_cnt &


"]"

Call
CashFlow_XMLBLOB_Extract(vProductTypeNode_Xpath,vEffdate,frontOfficeSysName_Val,vSo
urceSubsystemName,frontOfficeReferenceID_Val,vProduct_Val,vCurrency_Val,_

vOTC_Val,vAttr_type,attr_Type_Id_Val,attr_class_Val,attr_name_Val,attr_Val_Val,Obj_
Write_Trade)
Set secnd_proxprdt_leg_xmlblob_node = xmlDoc.selectNodes(second_prxprdt_xpath &
"/leg[" & vsecndPrxprdt_leg_cnt & "]/xml_blob")

secnd_proxprdt_leg_xmlblob_length = secnd_proxprdt_leg_xmlblob_node.length-1

If secnd_proxprdt_leg_xmlblob_length>=0 Then

For secnd_proxprdt_leg_xmlblob_length_cnt = 0 To secnd_proxprdt_leg_xmlblob_length

Set secnd_proxprdt_leg_xmlblob_child =
secnd_proxprdt_leg_xmlblob_node.item(secnd_proxprdt_leg_xmlblob_length_cnt).childNo
des

secnd_proxprdt_leg_xmlblob_lenth = secnd_proxprdt_leg_xmlblob_child.length-1

For secnd_proxprdt_leg_xmbob_cnt = 0 To secnd_proxprdt_leg_xmlblob_lenth

attr_class_Val =
secnd_proxprdt_leg_xmlblob_child.item(secnd_proxprdt_leg_xmbob_cnt).nodeName

attr_Name_Val =
secnd_proxprdt_leg_xmlblob_child.item(secnd_proxprdt_leg_xmbob_cnt).nodeName

attr_Val_Val =
secnd_proxprdt_leg_xmlblob_child.item(secnd_proxprdt_leg_xmbob_cnt).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1

Next

Next

End If
Next
End If

Set
secnd_proxprdt_xmlblob_node = xmlDoc.selectNodes(second_prxprdt_xpath & "/xml_blob"
& OnlyRefentity_swap)
If
secnd_proxprdt_xmlblob_node.length > 0 Then
Set
attr_Type_Id_Elmt = secnd_proxprdt_xmlblob_node.item(0).childnodes
Execute
Execute_Attribute_type_outside

attr_Type_Id_Val = ""
For
secnd_xmlblob_childnodes_cnt = 0 To attr_Type_Id_Elmt.length-1
Set
ref_Entity_Elmt = attr_Type_Id_Elmt.item(secnd_xmlblob_childnodes_cnt).childNodes

ref_Entitiy_Child_Length = ref_Entity_Elmt.length-1
If
ref_Entitiy_Child_Length = 0 Then

attr_class_Val = ref_Entity_Elmt.item(0).parentNode.nodeName

attr_Name_Val = ref_Entity_Elmt.item(0).parentNode.nodeName

attr_Val_Val = ref_Entity_Elmt.item(0).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1
ElseIf
ref_Entitiy_Child_Length >= 1 Then

For refEntityIterator = 0 To ref_Entitiy_Child_Length

attr_class_Val = ref_Entity_Elmt.item(refEntityIterator).parentNode.nodeName

attr_Name_Val = ref_Entity_Elmt.item(refEntityIterator).nodeName

attr_Val_Val = ref_Entity_Elmt.item(refEntityIterator).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1

Next
End If
Next
End If
Set third_prxprdt_main
= xmlDoc.selectNodes(second_prxprdt_xpath & "/proxyProduct")
No_third_prxprdt_length
= third_prxprdt_main.length-1
If
No_third_prxprdt_length >= 0 Then
For
vthirdPrxprdt_cnt = 0 To No_third_prxprdt_length

third_prxprdt_xpath = second_prxprdt_xpath & "/proxyProduct[" & vthirdPrxprdt_cnt &


"]"
Set
third_prxprdt = xmlDoc.selectNodes(third_prxprdt_xpath)
If
vProd_OTC_CURR_Non_STRUC = TRUE Then Call vProduct_OTC_Currency(third_prxprdt_xpath
& "/", vProduct_Val, vCurrency_Val, vOTC_Val)
Set
third_proxprdt_leg = xmlDoc.selectNodes(third_prxprdt_xpath & "/leg")

No_third_prxprdt_leg_length = third_proxprdt_leg.length-1

If
No_third_prxprdt_leg_length >= 0 Then

Execute ExecuteOnly_third_PrxyPrdt_leg

Execute Execute_Attribute_type_leg

For vthirdPrxprdt_leg_cnt = 0 To No_third_prxprdt_leg_length

Set third_proxprdt_leg_node = xmlDoc.selectNodes(third_prxprdt_xpath & "/leg[" &


vthirdPrxprdt_leg_cnt & "]")

Set third_proxprdt_leg_legid =
third_proxprdt_leg_node.item(0).Getelementsbytagname("legId")

If third_proxprdt_leg_legid.length > 0 Then attr_Type_Id_Val =


third_proxprdt_leg_legid.Item(0).text

vProductTypeNode_Xpath = third_prxprdt_xpath & "/leg[" & vthirdPrxprdt_cnt & "]"

Call
CashFlow_XMLBLOB_Extract(vProductTypeNode_Xpath,vEffdate,frontOfficeSysName_Val,vSo
urceSubsystemName,frontOfficeReferenceID_Val,vProduct_Val,vCurrency_Val,_

vOTC_Val,vAttr_type,attr_Type_Id_Val,attr_class_Val,attr_name_Val,attr_Val_Val,Obj_
Write_Trade)

Set third_proxprdt_leg_xmlblob_node = xmlDoc.selectNodes(third_prxprdt_xpath &


"/leg[" & vthirdPrxprdt_leg_cnt & "]/xml_blob")

third_proxprdt_leg_xmlblob_length = third_proxprdt_leg_xmlblob_node.length-1
If third_proxprdt_leg_xmlblob_length>=0 Then

For third_proxprdt_leg_xmlblob_length_cnt = 0 To third_proxprdt_leg_xmlblob_length

Set third_proxprdt_leg_xmlblob_child =
third_proxprdt_leg_xmlblob_node.item(third_proxprdt_leg_xmlblob_length_cnt).childNo
des

third_proxprdt_leg_xmlblob_lenth = third_proxprdt_leg_xmlblob_child.length-1

For third_proxprdt_leg_xmbob_cnt = 0 To third_proxprdt_leg_xmlblob_lenth

attr_class_Val =
third_proxprdt_leg_xmlblob_child.item(third_proxprdt_leg_xmbob_cnt).nodeName

attr_Name_Val =
third_proxprdt_leg_xmlblob_child.item(third_proxprdt_leg_xmbob_cnt).nodeName

attr_Val_Val =
third_proxprdt_leg_xmlblob_child.item(third_proxprdt_leg_xmbob_cnt).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1

Next

Next

End If

Next
End If

Set
third_proxprdt_xmlblob_node = xmlDoc.selectNodes(third_prxprdt_xpath & "/xml_blob"
& OnlyRefentity_swap)
If
third_proxprdt_xmlblob_node.length > 0 Then
Set
attr_Type_Id_Elmt = third_proxprdt_xmlblob_node.item(0).childnodes

Execute Execute_Attribute_type_outside

attr_Type_Id_Val = ""
For
third_xmlblob_childnodes_cnt = 0 To attr_Type_Id_Elmt.length-1

Set ref_Entity_Elmt =
attr_Type_Id_Elmt.item(third_xmlblob_childnodes_cnt).childNodes
ref_Entitiy_Child_Length = ref_Entity_Elmt.length-1

If ref_Entitiy_Child_Length = 0 Then

attr_class_Val = ref_Entity_Elmt.item(0).parentNode.nodeName

attr_Name_Val = ref_Entity_Elmt.item(0).parentNode.nodeName

attr_Val_Val = ref_Entity_Elmt.item(0).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1

ElseIf ref_Entitiy_Child_Length >= 1 Then

For refEntityIterator = 0 To ref_Entitiy_Child_Length

attr_class_Val = ref_Entity_Elmt.item(refEntityIterator).parentNode.nodeName

attr_Name_Val = ref_Entity_Elmt.item(refEntityIterator).nodeName

attr_Val_Val = ref_Entity_Elmt.item(refEntityIterator).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter & frontOfficeSysName_Val


& vDelimiter & vSourceSubsystemName & vDelimiter & frontOfficeReferenceID_Val &_

vDelimiter & vProduct_Val & vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_

vDelimiter & vAttr_type & vDelimiter & attr_Type_Id_Val & vDelimiter &
attr_class_Val & vDelimiter &_

attr_name_Val & vDelimiter & attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1

Next

End If
Next
End If
Next
End If
Next
End If
End If
End If
Exit Do
Loop
Loop
vTotal_ExecTime = Timer - vTimer_Start
Msgbox " Trade count completed" & Chr(10) & " Execution Time = " &
Round(vTotal_ExecTime,2) & " Sec" & Chr(10) & "Total Number of Trade records in --
" & vRecordCount

Obj_Write_Trade.Close

Else
Msgbox "Unable to fetch result from unix box"
End If

Public Function vProduct_OTC_Currency(vProxyProduct_node, vProduct_Val,


vCurrency_Val, vOTC_Val)

vProduct_Val = Empty
vCurrency_Val = Empty
vOTC_Val = Empty

Set Proxprdt_ProductType_node = xmlDoc.selectNodes(vProxyProduct_node &


"proxyType")
If Proxprdt_ProductType_node.length >=0 Then vProduct_Val =
Proxprdt_ProductType_node.item(0).text

Set Proxprdt_Currencye_node = xmlDoc.selectNodes(vProxyProduct_node &


"currency")
If Proxprdt_Currencye_node.length >=0 Then vCurrency_Val =
Proxprdt_Currencye_node.item(0).text

Set Proxprdt_OTC_node = xmlDoc.selectNodes(vProxyProduct_node & "OTC")


If Proxprdt_OTC_node.length >=0 Then vOTC_Val =
Proxprdt_OTC_node.item(0).text

End Function

Public Function
CashFlow_XMLBLOB_Extract(fProxyProduct_Xpath,vEffdate,frontOfficeSysName_Val,vSourc
eSubsystemName,frontOfficeReferenceID_Val,vProduct_Val,_

vCurrency_Val,vOTC_Val,vAttr_type,attr_Type_Id_Val,attr_class_Val,attr_name_Val,att
r_Val_Val,Obj_Write_Trade)

cashflow_node_Xpath = vProductTypeNode_Xpath & "/cashFlowSet/cashFlow"


cashflow_XMLBLOB_node_Xpath = cashflow_node_Xpath & "/xml_blob"
Set cashflow_node = xmlDoc.selectNodes(cashflow_node_Xpath)
No_Of_cashflow_length = cashflow_node.length - 1
If No_Of_cashflow_length>=0 Then
Set cashflow_xml_blob_node = xmlDoc.selectNodes(cashflow_XMLBLOB_node_Xpath)
No_Of_cashflow_xml_blob_length = cashflow_xml_blob_node.length-1
If No_Of_cashflow_xml_blob_length>=0 Then
For cashFlow_xmlblob_length_cnt = 0 To No_Of_cashflow_xml_blob_length
Set cashFlow_xmlblob_childnodes =
cashflow_xml_blob_node.item(cashFlow_xmlblob_length_cnt).childNodes
cashFlow_xmlblob_childnodes_length =
cashFlow_xmlblob_childnodes.length-1
For cashFlow_xmlblob_childnodes_cnt = 0 To
cashFlow_xmlblob_childnodes_length
attr_class_Val =
cashFlow_xmlblob_childnodes.item(cashFlow_xmlblob_childnodes_cnt).nodeName
attr_Name_Val =
cashFlow_xmlblob_childnodes.item(cashFlow_xmlblob_childnodes_cnt).nodeName
attr_Val_Val =
cashFlow_xmlblob_childnodes.item(cashFlow_xmlblob_childnodes_cnt).text

Obj_Write_Trade.WriteLine Chr(34) & vEffdate & vDelimiter


& frontOfficeSysName_Val & vDelimiter & vSourceSubsystemName & vDelimiter &
frontOfficeReferenceID_Val &_
vDelimiter & vProduct_Val &
vDelimiter & vCurrency_Val & vDelimiter & vOTC_Val &_
vDelimiter & vAttr_type &
vDelimiter & attr_Type_Id_Val & vDelimiter & attr_class_Val & vDelimiter &_
attr_name_Val & vDelimiter &
attr_Val_Val & Chr(34)

vRecordCount = vRecordCount + 1
Next
Next
End If
End If

End Function

'===================== FACS trade attributes


==============================================

End Function