UFT/QTP Datatables Methods

Datatables are one of the the means to provide test data to your script. Once you entered the columns and values in the Datatables provided by UFT/QTP you can access these values and can even modify it from the run time datatables with the use of Datatable objects . There are few in build methods that enable us to work on the data from the sheets of the datatable.
It is made up of three kinds of objects Datatable,DTSheet and DTParameter.

Using Datatable for passing on the values to scripts as test data or object properties or anywhere else can be considered as one way of parameterization.

Associated methods :

AddSheet Method: Adds the specified sheet to run time Datatable
DataTable.AddSheet(“TestDataSheet”)

DeleteSheet Method: As the name suggests it deletes the sheet from the run time Datatable.
DataTable.DeleteSheet “TestDataSheet”

Export Method: It helps to keep the run time Datatable stored on the desired location.
DataTable.Export(fileLocation)

ExportSheet Method: It can export the desired run time Datatable sheet to the defined location.
DataTable.ExportSheet(fileName, SheetName)

GetCurrentRow Method: Gets the current active row number from the first sheet in the run time Datatable.
var rowNumber
rowNumber = DataTable.GetCurrentRow

GetRowCount Method: Get the total number of rows present in the desired sheet of the run time DataTable.
var rowCounts
rowCounts = DataTable.GetSheet(“TestDataSheet”).GetRowCount

GetSheet Method: Returns the specified sheet from the run time Datatable. This is usually used with the method GetParameter, AddParameter etc (Methods associated with DTSheet object)
var getValue = DataTable.GetSheet(“TestDataSheet”).GetParameter(ColumnName)

GetSheetCount Method: Gives the total number of sheets available in the run time DataTable.
var sheetCount
sheetCount = DataTable.GetSheetCount

Import Method: This has capability to Import all the data from the external excel file to the run time DataTable.
DataTable.Import(fileName)

Its very important to keep few things in mind is the excel file must have the sheet names same as the action names, and column names must match the parameters used in the script.
If you are trying to import multiple values in one cell with the help of combo box or list cells then it will just have one fixed value, can not take multiple values in the DataTable.

ImportSheet Method: Imports a sheet in the specified file to a run time datatable.
DataTable.ImportSheet(fileName, SourceSheetNameOrIndex, DestinationSheetNameOrIndex)

The same rule applies as for import method. The columns name must match the parameters used in the script.

SetCurrentRow Method: With this we can specify the row to be made as active.
DataTable.SetCurrentRow(rowNumber)

SetNextRow Method: This is to move the focus from the current row to the next row.
DataTable.SetNextRow
If the current row is the last row in the DataTable the it will set up first row as the new current row.

SetPreviousRow Method: Set the focus to the row above the current active row.
DataTable.SetPreviousRow
If the current active row is the first row, then it will move the focus to the last row of the DataTable.

Associated Properties :

GlobalSheet : It points to the first sheet of the run time DataTable. It is generally used in conjunction with the DTParameter object methods.
DataTable.GlobalSheet.AddParameter(ColumnName, value)

LocalSheet : It points to the current local sheet in focus, in the run time DataTable. It again is used in conjunction with the DTParameter object methods.
DataTable.LocalSheet.AddParameter(ColumnName, value)

RawValue : This returns the actual value present in the cell before computing the values. Suppose we have some formula present in the cell, so this method will return the formula but not the value computed by the formula.
var rawVal
rawVal = DataTable.RawValue(ColumName, SheetNameOrId)

Value Property : Return the value present in the cell based on the parameter and sheet
var CellVal
CellVal = DataTable.Value(ColumnName, SheetIDOrName)

In case the cell has some formula defined, the the value return will be the result of the formula, not the formula itself.

Name Property : It will return the name of the column created in the run time DataTable.
paramName = DataTable.GetSheet(SheetName).AddParameter(ColumnName,Value).Name

paramName variable will have the same value as ColumnName

ValueByRow Property : This will return the value by row number based on a specific parameter.
RowValue = DataTable.GeetSheet(SheetName).GetParameter(ColName).ValueByRow(rowNumber)

AddParameter : This method creates new parameters in the run time Datatable sheet.
DataTable.GetSheet(SheetName).AddParameter(ColumnName,ColValue)

DeleteParameter : This method deletes the parameters in the run time Datatable sheet.
DataTable.GetSheet(SheetName).DeleteParameter(ColumnName)

GetParameter : This method gets the parameters from the run time Datatable sheet.
DataTable.GetSheet(SheetName).GetParameter(ColumnName)

GetParameterCount : This method gets the parameters count from the run time Datatable sheet.
DataTable.GetSheet(SheetName).GetParameterCount

Leave a comment