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 two internal tables

Former Member
0 Likes
872

how to compare two internal tables based on specific fields?

1 ACCEPTED SOLUTION
7 REPLIES 7
Read only

Former Member
0 Likes
838

Hi!

Check out these links...

Regards

Tamá

Read only

Former Member
0 Likes
838

hi Mathew Parera

chk this sample code

  • Entries: 100 (ITAB1), 1000 (ITAB2)

  • Line width: 100

  • Both tables sorted by key K

LOOP AT ITAB1 INTO WA1.

LOOP AT ITAB2 INTO WA2

WHERE K = WA1-K.

" ...

ENDLOOP.

ENDLOOP.

  • Entries: 1000 (ITAB1), 300 (ITAB2)

  • Line width: 100

  • Both tables sorted by unique key K ascending

LOOP AT ITAB1 INTO WA1.

READ TABLE ITAB2 INTO WA2

WITH KEY K = WA1-K BINARY SEARCH.

IF SY-SUBRC = 0.

" ...

ENDIF.

ENDLOOP.

regards

Deva

Read only

Former Member
0 Likes
838

Hi,

plz try this way :

sort : itab1 by num,

itab2 by num.

loop at itab1.

read table itab2 with key num = itab1-num binary search.

if sy-subrc = 0.

flag = 'X'.

else.

exit.

endif.

hope this helps.

thanx,

dhanashri.

Read only

Former Member
0 Likes
838

Try it this way:

loop at itab1 into wa1.

  describe table itab2 lines w_line.
  
 do w_line times.

   read table itab2 into wa2 index counter.

   if wa2-field = wa1-field.
   .........
   endif.
  counter = counter + 1.  
 enddo.
endloop.

With luck,

Pritam.

Read only

Former Member
0 Likes
838

Hi,

Try this.

Loop at itab1 into wa_itab.

read table itab2 into wa_itab2 with key f1 = wa_itab1-f1.

if sy-subrc eq 0.

< carry out ur requirement>

endif.

endloop.

Sharin.

Read only

Former Member
0 Likes
838

hi,

check out this code. i am giving the raw idea to compare internal table field.

types: begin of gs_vbak,

vbeln TYPE vbak-vbeln,

erdat TYPE vbak-erdat,

end of gs_vbak.

data: it_vbak type standard table of gs_vbak,

wa_vbak type gs_vbak.

****************************************************

types: begin of gs_vbap,

VBELN type vbap-VBELN, "sales order

MATNR type vbap-MATNR, "material no

ARKTX type vbap-ARKTX, "material description

end of gs_vbap.

data: it_vbap type standard table of gs_vbap,

wa_vbap type gs_vbap.

****************************************************

select-options: s_vbeln for vbak-vbeln.

select vbeln

erdat

kunnr

ernam from vbak into table it_vbak where vbeln in s_vbeln.

select VBELN

MATNR

ARKTX

from vbap into table it_vbap up to 20 rows.

loop at it_vbak into wa_vbak.

read table it_vbap into wa_vbap INDEX sy-index.

if wa_vbak-vbeln = wa_vbap-vbeln.

write: 'vbeln for both table are equal'.

elseif wa_vbak-vbeln GT wa_vbap-vbeln.

write: -


else.

write: -


endif.

endloop.