How to synchronize 2 loops?

Hi, I’m trying to compare each row in an Excel file with another row in a diffrent file. if the rows are the same (rowstring_1 =rowstring_2) it must add 1 to the integer “T_sum” else it must add 1 to “F_sum”
for this I created the workflow underneath.
Excel.xaml (16.0 KB)
both tables have 400 rows. as it is now it is checking each single row with all 400 of the other. this equals to 160000 operations and takes waaay too long. what I’m trying is to synchronize both loops so it checks the first row with the first, the second with the second, third with third etc. so it’s only 400 operations.

That’s would be: (Using Continue Activity inside Foreach)

f(row1 == row2) { 
 continue; 
} else { 
//do something 
}

I thought two different way.

  1. You can union your excel files. Like;

col1col2 col1col2

col1col2col3col3

Then you can compare in one for each row activity.

  1. If you have just one column for each excel, you can get values with dynamic “Read Cell” activity. Then you can compare those values with a for each activity.

Hope these helps.

Ercan

continue doesn’t help in this case because the first loop has to skip synchronously with the second loop. also it has to skip regardless of the result even if row1 <> row 2. the problem is so far the second loop doesn’t halt it is iterating through every row until 400. instead of checking 1 with 1 and then 1 with 2,3,4 up to 1 with 400 and starting over again with 2. I want to check 1 with 1, 2 with 2… 400 with 400. therfore the first loop and second loop have to be synchronous.

Hi, the files have 9 colums with long text in some cells. after checkiing the Excel file 1 with Excel file 2. file 1 has to be chekced with 3,4,5 etc. until the true counter T_sum is high enough. like when (T_sum/F_sum) is higher than 0.90 it has to overwrite that file with the new file. But first I have to solve this loop synchronization issue.

I see a single loop like this

That may work. Can you attach the file so I can look at the exact method ? Didn’t you use Excel App scope above ?

Read Datatables just before looping. Screenshot ilustrates only loop over DT1, using an Index (Index property of For each Datarow activity. In the Screenshot is RowIndex Variable) you could access to DT2 row using One single loop (DT2.Rows(RowIndex)({column_index})). Inside IF statement you can control all scenarios.

You should first read both excel file to DataTable then do a loop in the first one using an integer variable, you dont need even a For Each Row to be honest…

Can you show what you mean ?

what is written in the assign action ?

i mean you should not have an excel scope inside your loop :slight_smile: this is what makes your process very slow…

isn’t it required to open and process the 2nd excel file ?

with all do respect, i think this question do not belong in RPA Dev Advanced.
Yes, the first thing you need to do in your process is read both your excel files to generate 2 DataTables, then just follow what @asesor-rpa showed you 2 hours ago…

For ilustration purposes, Assign is just to create a new instance of Datatable. In Real life, Datatable are created by using Read Range activity.

1 Like

ok thanks

I tried it with 2 DTs before. but for some reason it didn’t work. anyway I will try @asesor-rpa solution again

1 Like