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
598

I have two internal tables IT_A and IT_B.

IT_A contains fields as P, Q, R and IT_B contains fields Q,R.

The contents are

IT_A

P Q R

P1 q1 r1

P2 q2 r1

P3 q3 r2

P4 q4 r1

P4 q4 r2

And that of IT_B is

Q R

q1 r1

q1 r2

q2 r1

q3 r1

q4 r1

I want to find all the values of IT_A with respect to IT_B which are not common. The output should be P3 and P4.

Could you please help me out!!!!

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
574

Hi Pravin,

try this with help ogf sorted table.:

data:
it_b_sort like table of it_b with unique key q r.
it_b_sort = it_B[].

loop at it_a.
read table it_b_sort with table key q = it_a-q r = it_a-r.
if sy-subrc = 0.
write: 'This is not common'.
endif.
endloop.

Regards,

Clemens

5 REPLIES 5
Read only

kishorepallapothula
Participant
0 Likes
574

Hi pavin,

select * from itab for all entries in itab1 where <condition>.

try this.

reward if useful.

kishore

Read only

Former Member
0 Likes
574

Reading your question as "I want all entries in IT_A that do not have an entry in IT_B" then you could try (not syntax checked):

sort IT_B by q r. "for binary search

loop at IT_A.  "assume header line

  read table it_b
    with key q = it_a-q
             r = it_a-r
    binary search
    transporting no fields.

  if not sy-subrc is initial.
    write: / 'No IT_A entry in IT_B for', it_a-p, it_a-q, it_a-r.
  endif.

endloop.

Read only

Clemenss
Active Contributor
0 Likes
575

Hi Pravin,

try this with help ogf sorted table.:

data:
it_b_sort like table of it_b with unique key q r.
it_b_sort = it_B[].

loop at it_a.
read table it_b_sort with table key q = it_a-q r = it_a-r.
if sy-subrc = 0.
write: 'This is not common'.
endif.
endloop.

Regards,

Clemens

Read only

Former Member
0 Likes
574

Thanks a lot Clemens !!!!!!!!!!

I put in the code and it worked. Appreciate your help..

Cheers!!!

Pravin

Read only

Clemenss
Active Contributor
0 Likes
574

... but not exactly. Should have been


read table it_b_sort transporting no fields with table key q = it_a-q r = it_a-r.

Regards,

Clemens

Thanks anyway!