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: 

Records in table1 but not in table2

Former Member
0 Kudos

Hi all,

I use the following statement to select all records from table equi that also exist in itab lt_temp:

SELECT mandt equnr

FROM equi

INTO CORRESPONDING FIELDS OF TABLE lt_equi_temp

FOR ALL ENTRIES IN lt_temp

WHERE equnr EQ lt_temp-equnr

AND equnr LIKE 'C%'.

Problem is I want the records in equi that do not exist in itab lt_temp. I tried changing the 'EQ' to 'NE' in the where clause but that query never comes back.

thanks in advance,

4 REPLIES 4

Former Member
0 Kudos

try this....

SELECT mandt equnr

FROM equi

INTO CORRESPONDING FIELDS OF TABLE lt_equi_temp

where equnr LIKE 'C%'.

if sy-subrc = 0.

loop at lt_equi_temp.

read table lt_temp with key equnr = lt_equi_temp-equnr.

if sy-subrc = 0.

delete lt_equi_temp index sy-tabix.

endif.

endloop.

endif.

Regards

vasu

Former Member
0 Kudos

HI MAthew,

SELECT mandt equnr

FROM equi

INTO CORRESPONDING FIELDS OF TABLE lt_equi_temp

where equnr LIKE 'C%'.

if sy-subrc = 0.

loop at lt_temp.

read table lt_equi_temp with key equnr = lt_temp-equnr.

if sy-subrc = 0.

delete lt_equi_temp index sy-tabix.

endif.

endloop.

endif.

never loop at an internal table and perform a delete operation on the same internal table.

It may lead to severe problems.

JozsefSzikszai
Active Contributor
0 Kudos

hi Mathew,

move the entries from lt_temp to a range the following way:

sign = I

option = NE

low = ...

and now select :

SELECT mandt equnr

FROM equi

INTO CORRESPONDING FIELDS OF TABLE lt_equi_temp

WHERE equnr IN lt_temp-equnr

for the range you can do as well:

sign = E

option = EQ

hope this helps

ec

Former Member
0 Kudos

Hi,

Do as below :

ranges : gr_equnr for equi-equnr.

loop at lt_temp.
gr_equnr-sign = 'I'.
gr_equnr-option = 'EQ'.
gr_equnr-low = lt_temp-equnr.
gr_equnr-high = lt_temp-equnr.

append gr_equnr.
endloop.

SELECT mandt equnr
FROM equi
INTO CORRESPONDING FIELDS OF TABLE lt_equi_temp
WHERE equnr not in gr_equnr
or equnr LIKE 'C%'.

Thanks,

Sriram Ponna.