Micro Focus QTP (UFT) Forums
How to add multiple local datatables to one action? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to add multiple local datatables to one action? (/Thread-How-to-add-multiple-local-datatables-to-one-action)



How to add multiple local datatables to one action? - sratna - 11-06-2009

Hi,
Is it possible to add more than one local datatable for one action.I know if we split that action into two we can create two local datatables. Is there any other way without splitting the action? If yes, please tell me how.

I see by default only global and action1 datatables.
I tried :
DataTable.ImportSheet"C:\Documents and Settings\user\Desktop\12.xls",1,2
DataTable.ImportSheet"C:\Documents and Settings\user\Desktop\11.xls",1,3

only one of the above two statements worked and it inserted data from my excel.
Its not creating another local datatable. Please suggest.

Thanks


RE: How to add multiple local datatables to one action? - sreekanth chilam - 11-06-2009

Hi Ratna,

Basically in QTP there will be Design Time Datatable(in QTP window) & RunTime Datatable(in Test Results).
BY default there will be only two Datasheets i.e Global & Localsheets in Design Time Datatable.

Bt If you want to add newdata sheets , you can do that by using "Datatable.AddSheet" method which would be added in RunTime Datatable.

Refer QTP Help for Datatble Methods for more info.


RE: How to add multiple local datatables to one action? - sratna - 11-07-2009

can i do this? for runtime datatable
Code:
DataTable.AddSheet("12.xls")
DataTable.ImportSheet"C:\Documents and Settings\c-vkanchu\Desktop\12.xls"
If i have to specify parameters, how am i gonna do that
Code:
Datatable. addsheet("12.xls").addparameter("column1", "its value")("column2","its value")
etc
how am i gonna do the above for 10 rows and 10 columns.

also in my script do i have to give like this
Code:
Browser("").Page("").webedit("").Set DataTable("RFCN",dtLocalSheet)
even for runtime datatable data if RFCN is a column in my runtime datatable?

how do i get the rowcount just like the global/local datatable?
Code:
GlobalRowCount=datatable.GetSheet("Global").GetRowCount
ActionRowCount=datatable.GetSheet("Action1").GetRowCount
what would i give in place of Global and Action1??? if its a runtime datatable?

I am new to QTP. so, Please be patient with me

Thanks in advance.


RE: How to add multiple local datatables to one action? - sreekanth chilam - 11-07-2009

Hi Ratna,

Yes, you can add datasheets to Runtime Datatable.

Syntax
DataTable.AddSheet(SheetName)

Example:
Code:
Datatable.AddSheet("xxxx")

Datatable.Importsheet Imports a sheet of a specified file to a specified sheet in the run-time Data Table. The data in the imported sheet replaces the data in the destination sheet
Syntax :
DataTable.ImportSheet(FileName, SheetSource, SheetDest)

Example:
Code:
Datatable.Importsheet "C:\doc & Settings\sample.xls","Sheet1","xxxx"


For Adding parameters you can use "AddParameter" method:
"AddParameter" method Adds the specified parameter (column) to the sheet in the run-time Data Table.
Syntax
DTSheet.AddParameter(ParameterName, Value)

Example :
Code:
DataTable.GetSheet("xxxx").AddParameter "Place","INDIA"

"also in my script do i have to give like this
Browser("").Page("").webedit("").Set DataTable("RFCN",dtLocalSheet) even for runtime datatable data if RFCN is a column in my runtime datatable?"
--> You can give as below
Code:
Browser("").Page("").webedit("").Set DataTable("colname","xxxx")

[color]"how do i get the rowcount just like the global/local datatable?
what would i give in place of Global and Action1??? if its a runtime datatable?"--> [/color]You can give as below:

Code:
NewsheetRowcount=datatable.GetSheet("xxxx").GetRowCount

Finally, for your [color]"how am i gonna do the above for 10 rows and 10 columns"[/color] question use the below code & execute, check the test results for RunTime Datatable.

Code:
Datatable.AddSheet"xxxx"
    For i=1 to 10
         Datatable.GetSheet("xxxx").AddParameter "Col"&i,""
    Next
  
    For j=1 to 10
      Datatable.GetSheet("xxxx").SetCurrentRow(j)
           For k=1 to datatable.GetSheet("xxxx").GetParameterCount
                 Datatable.Value("Col"&k,"xxxx")="Value of"&"Row"&j&"Col"&k
           Next
    Next
  
   msgbox Datatable.GetSheet("xxxx").Name&" : "&Datatable.GetSheet("xxxx").GetRowcount