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

Comparing Internal tables

Former Member
0 Likes
871

Hi Expert,

i have two internal tables , i have to comapre a field which have no value in other it- tables. e.g.

it_tab1-posnr have value 10,20,30,40,50.

it_tab2-posnr have value 10,20,30,40.

i hav to put a condition when some posnr from it_tab1 not in it_tab2.

rgds

abaper.

1 ACCEPTED SOLUTION
Read only

alex_m
Active Contributor
0 Likes
847

Loop at itab1,

Read table itab2 with key Vbeln and POSNR.

If sy-subrc = 0.

Record exist in itab2.

else.

not exist in itab2.

Endloop.

9 REPLIES 9
Read only

Former Member
0 Likes
847

loop at it_tab1 into wa.

read table it_tab2 with key posnr = wa-posnr.

if sy-subrc <> 0.

....

else.

...

EndIf.

EndLoop.

Santhosh

Read only

Former Member
0 Likes
847

Hi,

Put a simple condn

if it_tab1-posnr = it_tab21-posnr (in the loop of it_tab1, after reading it_Tab2)

then move the data to some other int table

endif.

reward if useful

regards,

Anji

Message was edited by:

Anji Reddy Vangala

Read only

alex_m
Active Contributor
0 Likes
848

Loop at itab1,

Read table itab2 with key Vbeln and POSNR.

If sy-subrc = 0.

Record exist in itab2.

else.

not exist in itab2.

Endloop.

Read only

Former Member
0 Likes
847
loop at itab1.
 read table itab2 with key field1 eq itab1-field1.
 if sy-subrc ne 0.
   write : 'value itab1-field1 does not exist in itab2'.
 endif.
endloop.

Message was edited by:

Chandrasekhar Jagarlamudi

Read only

Former Member
0 Likes
847

hi,

chk this:

sort itab2 by posnr.

loop at itab1.

read table itab2 with key posnr = itab1-posnr.

if sy-subrc <> 0.

.....

endif.

endloop.

regards,

madhu

Read only

Lakshmant1
Active Contributor
0 Likes
847

Hi ABAP king,

try function module COMPARE_TABLES.

also have a look at demo program DEMO_INT_TABLES_COMPARE

Hope this helps

Thanks

Lakshman

Read only

Former Member
0 Likes
847

Hi all,

thanks for ur replies, but in second internal table the value may be like

10,20,20,30,30,40. so actually my reqs is find a value in first internal table which is not in second and at that point a have to done some work.

rgds

abaper.

Read only

0 Likes
847

Its not a problem, anyway the read statement success if the records present in itab2. If 2 values there in itab2 the read statement get the first one.

Read only

Former Member
0 Likes
847

Hi

Try like this

DATA: begin of it_tab1 occurs 0,

data1 type i,

end of it_tab1.

DATA: begin of it_tab2 occurs 0,

data2 type i,

end of it_tab2.

it_tab1-data1 = 10.

append it_tab1.

it_tab1-data1 = 20.

append it_tab1.

it_tab1-data1 = 30.

append it_tab1.

it_tab1-data1 = 40.

append it_tab1.

it_tab1-data1 = 50.

append it_tab1.

it_tab2-data2 = 10.

append it_tab2.

it_tab2-data2 = 30.

append it_tab2.

it_tab2-data2 = 50.

append it_tab2.

it_tab2-data2 = 70.

append it_tab2.

it_tab2-data2 = 80.

append it_tab2.

loop at it_tab1.

read table it_tab2 with key data2 = it_tab1-data1.

if sy-subrc <> 0.

write:/ 'Not there'.

else.

write:/ 'Exists'.

endif.

endloop.

Regards

Haritha.