Absent Member.
Absent Member.
2449 views

Keep row number

Jump to solution

Hi all,

Im having trouble making QTP do a For loop with stuff for 100 rows in a DataTable, then do different stuff 1 time and do the first stuff again for the next 100 rows (ie row 101-200), rinse and repeat with 100 rows each time. My problem is that it starts at row 2 after doing the code first time and I need it to continue from row 101 instead.

For clarification I added a msg box in the code and what im trying to accomplish is for that to add 1 each time, also between running full circle in the code (ie for each 100 rows). So lets say after doing 400 rows the msgbox should say 400 and the "do different stuff" code would then have been done 4 times.

Dim x

For x = 1 To 100

'Do stuff
msgbox DataTable.GlobalSheet.GetCurrentRow

Next

'Do different stuff 1 time and then start the For loop again from row 101

 

Is it in any way possible to "save" the row number and continue from that after doing the full code?

I would really appreciate any effort spend helping 🙂

 

Using QTP 11 and in settings its set to run on all rows

 

0 Likes
1 Solution

Accepted Solutions
Absent Member.
Absent Member.

Just wanted to give a status and close this thread cause I finally found a workable solution.

 

I did try all of the above but could not get the several action method suggested to work. I think i am too unfamiliar with UFT to fully understand how it should work.

 

But i came aross the MOD expresion in Excel and thought that I would give that a go and it does excately what i need. So ill post my solution here and close the thread.

 

Again thanks for all the suggestions.

 

If DataTable.GetSheet("Global").GetCurrentRow MOD 100=0 Then

 

Do stuff each 100th time

 

End if

 

Do stuff

View solution in original post

0 Likes
14 Replies
Captain Captain
Captain

I'm puzzled, why not save the last used rownumber in a variable? And the run from saverownumber + 1?

If a variable can't be used, you could write the value of course to a datatable, and pick it up again...

0 Likes
Absent Member.
Absent Member.

Thanks for the response 🙂

 

I did try to save rownumber in a variable, but variables seem to get "reset" as well after each run.

 

Im not familiar with saving to databases in QTP, but I will try to look into that and see if that can do the trick.

0 Likes
Captain Captain
Captain

Why don't you use the SetCurrentRow Method? <script src="/t5/forums/replypage/board-id/sws-Fun_TEST_SF/SkinSupport/MadCapAll.js" type="text/javascript"></script>

DataTable.SetCurrentRow(RowNumber)

 

Or put the 

 

'Do stuff'

 

part in a function, and you can reuse it. 

 

 

 

 
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

Save that Variable in another sheet in same excel.

Create Another worksheet in the excel and save the sheet.

Take this value for all your execution. First time it will take 0, before the next iteration set this value to 100 so that next execution takes 100 from this cell.

Hope this helps.

Absent Member.
Absent Member.

Thanks for the suggestions.

 

Not sure how the suggestion with the function is meant to work though, cause i will still have to make the function run only once every 100th time. How would that code look?

 

I am currently waiting for my company to install latest version of UTF and that might behave different than QTP that im using now, so i ll wait with messing with this until then.

 

I did try the DataTable.SetCurrentRow(RowNumber) earlier but that gets reset as well.

 

But I will try to save the variable in a sheet and see if that can work once i get the new installation.

 

Cheers 🙂

0 Likes
Ensign Ensign
Ensign

Here is a quick way to do it.  It's probably not the best way, but it may work in your situation.  In your data spreadsheet, on every hundreth row set a flag that let's QTP know to "do different stuff 1 time" as you mentioned.  In my example below, I created a new column in the spreadsheet called "MyColumnFlag" on each hundreth row I put the text "END" in the Excel cell.  If you have lots of rows (like in the 1,000s) then this might not be a good approach, but if you're talking a few hundred or less then it may work for you.  Be sure to set the run time setting to "Run one iteration only".  Hope this helps.

 

Dim x, rowcount
DataTable.ImportSheet "C:\Temp\MySpreadsheetExample.xls""Global""Global"
rowcount = DataTable.GlobalSheet.GetRowCount
For x = 1 To rowcount
    DataTable.GetSheet("Global").SetCurrentRow(x)
    'Do stuff
    If DataTable.Value("MyColumnFlag""Global") = "END" Then
        msgbox "This was the hundredth row."
        'Do different stuff 1 time and then start the For loop again from row 101
    End If
    DataTable.GetSheet("Global").SetNextRow
Next

Absent Member.
Absent Member.

The 100th cell value might work, but I do have a lot of rows, like 10.000, but of cause its just 1 time i have to set it up.

 

If the other suggestions i havent tried yet fails me, i might go for that one.

 

Still waiting for the installation of UTF.

 

Thanks 🙂

0 Likes
Absent Member.. Absent Member..
Absent Member..

I have a suggestion, but need a clarification first.

Is the thing you do every 100th row the same thing or different?

I think you could maybe do this by using a Global datasheet and an Action datasheet.

 

The Action datasheet would include the 10,000 rows for which you want to perform some activity for every block of 100 rows. That activity would be defined in a separate Action to which that datasheet would be associated.

 

The Global datasheet would have one row for every 100 rows in your Action sheet. So, if your Action sheet has 10,000 rows, then your Global sheet would have 100.

 

The Global sheet drives the overall iteration of your main test script. Within the main test script, in each of its iterations you execute the activity that you want to execute for every 100th row. Then you insert a call to your Action, telling it to iterate through rows n through n+99 of your Action datasheet.

 

Your main test would iterate 100 times (the number of rows in the Global datasheet). Within each of those iterations, you would iterate 100 times through the  secondary Action. You could even make the starting and ending rows for the secondary action part of the row data in your Global sheet.

 

I do something similar in my testing, but I use an External Action and have to use commands to load the DataTable that goes with the External Action. I choose to store my datatables separate from my test scripts. You might be able to do this with datatables stored as part of the test script, though.

[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
Absent Member.
Absent Member.

I will try to clarify the 100 /1 row "stuff" and why i need to do it this way.

 

The automation im doing is creating user data in SAP and each row is setting data in SAP for 1 user.

 

Problem is that there is some kind of memory leak in this process in SAP, so for each user the step takes more time and after 100 users or so, SAP simply breaks down due to lack of memory. So the "do different stuff" I have to do for each 100th row is actually shutting down SAP and reopening it, so it can start with fresh memory with user number 101. This means there isnt actually a row for the "do different stuff".

 

So I need to set data in SAP for 100 users (rows) then shut down SAP and reopen it, then continue from last row -  rinse and repeat.

0 Likes
Absent Member.. Absent Member..
Absent Member..

I believe that you could use my suggestion, then.

[If this post solves or helps solve your issue, mark the thread as solved and give KUDOS to the author for their assistance.]

(Opinions expressed in my postings are mine alone, and do not reflect the opinions of my employer.No warranties express or implied for any solution/suggestion posted.)
0 Likes
Absent Member.
Absent Member.

I finally got UFT installed so have been messing a bit with this again. Its quite different looking than the QTP version i had, so trying to get familiar with it.

 

I did try to set it up as  you suggested Trudy Claspill,  but cant get it to work as intended.

 

Could you please clarify these 2 sentenses:

 
--------------------------------------------------------------------------------
Trudy Claspill wrote:

Within the main test script, in each of its iterations you execute the activity that you want to execute for every 100th row.
--------------------------------------------------------------------------------

 

As I can see it I cant set up code in the actual main script as it only consists of Start - Actions - End. i Can enter code in the actions, but not anywhere else, but maybe im missing something, as I am very new to QTP/UFT. Where do you mean I should write the "do different stuff" code?


--------------------------------------------------------------------------------
Trudy Claspill wrote:
Then you insert a call to your Action, telling it to iterate through rows n through n+99 of your Action datasheet.
--------------------------------------------------------------------------------

 

Do you mean an actual loop in the Action1 og do you just mean that this happens by itself due to the setup with 1 row in global for each 100 in the action1?

 

You also mention a secondary action, which confuse me a bit. Do you have more than one action in the setup?

 

Thanks very much for the suggestions and the effort helping 🙂

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.