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

Compare 2 internal tables

adel_adel
Participant
0 Likes
463

Hi all,

I need a good algorithms for the next question:

Given 2 internal tables with the same structures, i need to print out the difference between the 2 tables .

types : BEGIN OF ty_s_table,

PERSONNR type i,

END OF ty_s_table.

DATA : itab1 TYPE TABLE OF ty_s_table,

itab2 TYPE TABLE OF ty_s_table.

For example : if itab1 contains the persons 1 , 2 , 3 , 5 and

itab2 contains the persons 2 , 4 , 6.

I need to print 1,3,4,6 (difference)

Thanks

Hi all,

I need a good algorithms for the next question:

Given 2 internal tables with the same structures, i need to print out the difference between the 2 tables .

types : BEGIN OF ty_s_table,

PERSONNR type i,

END OF ty_s_table.

DATA : itab1 TYPE TABLE OF ty_s_table,

itab2 TYPE TABLE OF ty_s_table.

For example : if itab1 contains the persons 1 , 2 , 3 , 5 and

itab2 contains the persons 2 , 4 , 6.

I need to print 1,3,4,6 (difference)

Thanks

2 REPLIES 2
Read only

Former Member
0 Likes
436

Add one more field say FLAG with CHAR1 to ITAB2.

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY PERSON = ITAB1-PERSON.

IF SY-SUBRC = 0.

ITAB2-FLAG = 'X'.

MODIFY ITAB2 TRANSPORTING FLAG.

ELSE.

WRITE ITAB1-PERSON.

ENDLOOP.

LOOP AT ITAB2 WHERE FLAG <> 'X'.

WRITE ITAB2-PERSON.

ENDLOOP.

Output will contain all the persons which are not common.

Read only

0 Likes
436

Something like this?



report zrich_0001 .

types: begin of ty_s_table,
        personnr type i,
       end of ty_s_table.

data: itab1 type table of ty_s_table,
      itab2 type table of ty_s_table,
      itab3 type table of ty_s_table.

data: wa1 type ty_s_table.
data: wa2 type ty_s_table.
data: wa3 type ty_s_table.

wa1-personnr = '1'.  append wa1 to itab1.
wa1-personnr = '2'.  append wa1 to itab1.
wa1-personnr = '3'.  append wa1 to itab1.
wa1-personnr = '5'.  append wa1 to itab1.

wa2-personnr = '2'.  append wa2 to itab2.
wa2-personnr = '4'.  append wa2 to itab2.
wa2-personnr = '6'.  append wa2 to itab2.


append lines of itab1 to itab3.
append lines of itab2 to itab3.

loop at itab3 into wa3.

  clear wa1.
  clear wa2.
  read table itab1 into wa1 with key personnr = wa3-personnr.
  read table itab2 into wa2 with key personnr = wa3-personnr.

  if wa1 <> wa2.
    write:/ wa3-personnr.
  endif.

endloop.

Regards,

RIch Heilman