Former Member

### Two table comparisions (logic problem)

Suppose I have a table itab1 with two cols

```col1         col2
A            0001
A            0002
A            0004
B            0001
B            0002
B            0003
B            0004```

second table itab2 has values

0001

0002

0003

0004

i want to delete all rows from itab1 based on itab 2 which does not hav all the values in itab1 from itab2 based on cl1 n col2 both

e.g in this case only this shud remain

```B            0001
B            0002
B            0003
B            0004```

Edited by: Karan Chopra on Jun 21, 2010 3:16 PM

Edited by: Karan Chopra on Jun 21, 2010 3:18 PM

10|10000 characters needed characters exceeded

• Former Member
Jun 21, 2010 at 09:50 AM

Hi,

Karan wrote...

```second table itab2 has values

0001
0002
0003
0004

i want to delete all rows from itab1 based on itab 2 which does not hav all the values in itab1 from itab2 based on cl1 n col2 both
e.g in this case only this shud remain
```

But Itab2 does not have cl1 n col2 .

Can you please clarify me on this point.

Regards

DKS

10|10000 characters needed characters exceeded
• Former Member
Jun 21, 2010 at 09:55 AM

Yes itab 2 does not hav col1 value s

the thing is all the values of itab2 here shud exist in itab1 for same col1 value

as here col1 value B has all 0001 to 0004 values so it is considered

10|10000 characters needed characters exceeded
• Former Member

Hi Karan,

This code will move the records from itab1 to itab3 where the value of col2 is present in itab2

```data: lw_tabix type sytabix.
* Declare itab3 like itab1
loop at itab1 into wa_1.
* Search the value of col2 in table itab1
read table itab2 into wa_2 with key col1 = wa_1-col2.
if sy-subrc eq 0.
* if found then move the record to itab3
Move wa_2 to wa_3.
append wa_3 to itab3
endif.
endloop.
```

Now itab3 will hold the desired records

Regards

DKS

• Jun 21, 2010 at 10:21 AM

Hi,

Please search the SCN before Posting. Many threads available in SCN related to this and refer the SCN rules before Posting.

With Regards,

Sumodh.P

10|10000 characters needed characters exceeded
• Former Member
Jun 21, 2010 at 10:28 AM

But on what criteria to search SCN

as this is very specific thing and I donot by what search criteria I should search

10|10000 characters needed characters exceeded
• Suhas Saha Former Member

Try this logic:

```* Populate the master key based on ITAB2, before that SORT ITAB2
SORT ITAB2.
CONCATENATE LINES OF itab2 INTO v_master_key.

* Remember to SORT ITAB1
SORT itab1 BY col1 col2.

LOOP AT itab1.
itab3 = itab1.
APPEND itab3.
CONCATENATE v_key itab1-col2 INTO v_key.
AT END OF col1.
CONDENSE v_key NO-GAPS.
IF v_key NE v_master_key.
*     We're not interested in these records, delete them
DELETE itab3 WHERE col1 = itab1-col1.
ENDIF.
CLEAR: v_key. "Don't forget to clear the key
ENDAT.
ENDLOOP.

LOOP AT itab3.
WRITE: / itab3.
ENDLOOP.```

BR,

Suhas

PS: I took Dzed's code as reference & tweaked it as per my logic. Apologies to Dzed ðŸ˜‰

• Former Member
Jun 21, 2010 at 10:58 AM

Hi ,