Application Development 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: 

question about comparing 2 internal tables...

aris_hidalgo
Contributor
0 Kudos

Hello experts,

I have 2 internal tables, it_ekpo and it_mseg2. now, what I want to do is delete records from itab it_ekpo that doesn't exist in itab it_mseg2. Bewlo is the code that I made. Please let me know if it's wrong or if it can be done in a better way. Thank you guys and take care!

LOOP AT it_ekpo.

READ TABLE it_mseg2 WITH KEY ebeln = it_ekpo-ebeln.

IF sy-subrc <> 0.

DELETE it_ekpo.

CLEAR it_ekpo.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

just make one more internal table it_ekpo1

of same type it_ekpo.

sort it_mseg2.

LOOP AT it_ekpo.

READ TABLE it_mseg2 binary search WITH KEY ebeln = it_ekpo-ebeln.

IF sy-subrc = 0.

it_ekpo1 = it_ekpo.

append it_ekpo1.

clear it_ekpo1.

ENDIF.

ENDLOOP.

5 REPLIES 5

naimesh_patel
Active Contributor
0 Kudos

Hello,

Try like this...

LOOP AT it_ekpo.

READ TABLE it_mseg2 WITH KEY ebeln = it_ekpo-ebeln.

IF sy-subrc <> 0.

DELETE it_ekpo.

<b>continue.</b>

ENDIF.

ENDLOOP.

Regards,

Naimesh

Reward points, if it is useful

0 Kudos

You should use Binary Search to speed up the read statement. Also if we are trying to remove the amount of lines of code being executed then you should use: -

LOOP AT it_ekpo.

READ TABLE it_mseg2 WITH KEY ebeln = it_ekpo-ebeln

BINARY SEARCH

CHECK sy-subrc <> 0.

DELETE it_ekpo.

ENDLOOP.

Make sure the table it_mseg2 is sorted to enable the binary search to work.

Thanks

Martin

Former Member
0 Kudos

Hi,

I think what you have done is right. Just a small change.

DELETE it_ekpo index sy-tabix.

Regards,

Ravi

Note : Please mark the helpful answers

Former Member
0 Kudos

hi viray,

i think it would be better if u wud write as

DELETE it_ekpo index sy-tabix.

or

DELETE it_ekpo where ebeln = it_ekpo-ebeln.

hope this helps,

priya.

Former Member
0 Kudos

just make one more internal table it_ekpo1

of same type it_ekpo.

sort it_mseg2.

LOOP AT it_ekpo.

READ TABLE it_mseg2 binary search WITH KEY ebeln = it_ekpo-ebeln.

IF sy-subrc = 0.

it_ekpo1 = it_ekpo.

append it_ekpo1.

clear it_ekpo1.

ENDIF.

ENDLOOP.