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

Find the difference between two internal table

Former Member
0 Likes
2,500

how can i see the difference between two interal tables?

The requirement is as follows

1. We have a transparent table, which stores the employee data with EMP ID as key.

2. We load the transp table data into a interal table (B).

3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).

Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).

We want to do followign things

I = A - B

D = B - A

Both A and B will have around 40k records. Hence we are trying to avoid the looping.

Please suggest the best option for us.

Thank you in advance.

Raghavendra

1 ACCEPTED SOLUTION
Read only

raviprakash
Product and Topic Expert
Product and Topic Expert
0 Likes
1,085

>

> how can i see the difference between two interal tables?

> The requirement is as follows

>

> 1. We have a transparent table, which stores the employee data with EMP ID as key.

> 2. We load the transp table data into a interal table (B).

> 3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).

>

> Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).

>

> We want to do followign things

> I = A - B

> D = B - A

>

> Both A and B will have around 40k records. Hence we are trying to avoid the looping.

>

> Please suggest the best option for us.

>

> Thank you in advance.

> Raghavendra

Hi Raghavendra,

Currently as of my knowledge, these operations are only possible through LOOPs. But LOOPign can be really fast here if you properly utilize the SORTING, READ with BINARY SEARCH and FIELD-SYMBOLS usage. I would say:-

Steps for Insert:-

SORT: A, B.

LOOP AT A ASSIGNING <WA_A>.

READ TABLE B WITH TABLE KEY key = <WA_A>-key BINARY SEARCH.

IF SY-SUBRC NE 0.

APPEND <WA_A> TO I.

ENDIF.

ENDLOOP.

Steps for Delete:-

SORT: A, B.

LOOP AT B ASSIGNING <WA_B>.

READ TABLE A WITH TABLE KEY key = <WA_B>-key BINARY SEARCH.

IF SY-SUBRC NE 0.

APPEND <WA_B> TO D.

ENDIF.

ENDLOOP.

Regards,

Ravi.

4 REPLIES 4
Read only

raviprakash
Product and Topic Expert
Product and Topic Expert
0 Likes
1,086

>

> how can i see the difference between two interal tables?

> The requirement is as follows

>

> 1. We have a transparent table, which stores the employee data with EMP ID as key.

> 2. We load the transp table data into a interal table (B).

> 3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).

>

> Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).

>

> We want to do followign things

> I = A - B

> D = B - A

>

> Both A and B will have around 40k records. Hence we are trying to avoid the looping.

>

> Please suggest the best option for us.

>

> Thank you in advance.

> Raghavendra

Hi Raghavendra,

Currently as of my knowledge, these operations are only possible through LOOPs. But LOOPign can be really fast here if you properly utilize the SORTING, READ with BINARY SEARCH and FIELD-SYMBOLS usage. I would say:-

Steps for Insert:-

SORT: A, B.

LOOP AT A ASSIGNING <WA_A>.

READ TABLE B WITH TABLE KEY key = <WA_A>-key BINARY SEARCH.

IF SY-SUBRC NE 0.

APPEND <WA_A> TO I.

ENDIF.

ENDLOOP.

Steps for Delete:-

SORT: A, B.

LOOP AT B ASSIGNING <WA_B>.

READ TABLE A WITH TABLE KEY key = <WA_B>-key BINARY SEARCH.

IF SY-SUBRC NE 0.

APPEND <WA_B> TO D.

ENDIF.

ENDLOOP.

Regards,

Ravi.

Read only

Former Member
0 Likes
1,085

Hi,

If you want to seperate out these data into three interal tables then you must use LOOP. In this situation you can use hash tables for big internal tables for better performance.

But if you only need to update the database it's sometimes the best and fastest to delete it first and then to insert the new data.

Regards,

Ali

Read only

Former Member
0 Likes
1,085

looping is not a bad option and u have to loop it only once.

Loop at internal table A.

Read B with records of A.

If sy-subrc eq 0.

Store it in internal table i_delete.

else.

Store it in internal table i_insert.

endif.

endloop.

Regards

Neha

Read only

0 Likes
1,085

thanks everyone for your quick response.