Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

problem with two open cursor

Former Member
0 Likes
1,241

Hi Expert,

I am using two open Cursor to call the data from two database table then I am trying to compare the data to find out the different data and records between them, but everything was in vain because the first cursor called 10000 records let us say material numbers.. the sound cursor call 10000 material numbers but they are totally different from the first cursor called data.....


The operation is going wrongly as no one of the first 10000 is in the second 10000 although they are in the second database but has not been called in this pass of looping....


I have tried to make append lines to a new intern tables and then to compare them but this is not a solution as I have millions of records and this will be like a select statement....

Please, any advises solving this..

Best Regards

Jenie

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,153
SELECT... FROM table1 INTO TABLE first_data_set PACKAGE SIZE 10000.
SELECT ... FROM table2 INTO TABLE second_data_set FOR ALL ENTRIES IN first_data_set WHERE key eq first_data_set-key " compare first_data_set with second_data_set. ... ENDSELECT.

No need for a cursor.

5 REPLIES 5
Read only

matt
Active Contributor
0 Likes
1,154
SELECT... FROM table1 INTO TABLE first_data_set PACKAGE SIZE 10000.
SELECT ... FROM table2 INTO TABLE second_data_set FOR ALL ENTRIES IN first_data_set WHERE key eq first_data_set-key " compare first_data_set with second_data_set. ... ENDSELECT.

No need for a cursor.

Read only

1,153

If you select data from table1 and table with some order by clause, the for all entries could be replaced by some range of data, getting usually much better performance?

SELECT ... FROM table2 INTO TABLE second_data_set 
       WHERE key between table1_min_key and table1_max_key.
Read only

matt
Active Contributor
0 Likes
1,153

Oh yes. A far better solution - combine my answer with yours. i.e. with order, but without cursor.

Read only

DoanManhQuynh
Active Contributor
1,153

this is what i tried to tell her in other post but seem like she need sample code instead :).

Read only

RaymondGiuseppi
Active Contributor
1,153

Well you could try to optimize if the select are 'ordered' (select order by) some pseudocode could be

open cursor 1.
open cursor 2.
do 
  Fetch a package from table 1 into internal table 1
  if no record, exit 
  loop at internal table 1 into record 1.
    while cursor 2 open and second table last value lower than record 1 key
      fetch a package of table2 
      if no record, close cursor 2 and exit 
    endwhile
    compare data with record 1 with internal table 2
  endloop
enddo