2007 Mar 19 2:26 PM
Hi all,
I know there are a bunch of posts regarding this issue...but I don't see one that quite fits this scenario. I have two tables with the exact same structure...with key field matnr. I want to delete all of those records from table A where the material does NOT exist in table B. Is there a terse way to accomplish this?
2007 Mar 19 2:29 PM
sort: itaba,itabb.
loop at itaba.
read table itab b with key matnr = itaba-matnr.
if sy-subrc ne 0.
delete itaba.
endif.
endloop.
~Suresh
Hi all,
I know there are a bunch of posts regarding this issue...but I don't see one that quite fits this scenario. I have two tables with the exact same structure...with key field matnr. I want to delete all of those records from table A where the material does NOT exist in table B. Is there a terse way to accomplish this?
2007 Mar 19 2:29 PM
sort: itaba,itabb.
loop at itaba.
read table itab b with key matnr = itaba-matnr.
if sy-subrc ne 0.
delete itaba.
endif.
endloop.
~Suresh
2007 Mar 19 2:37 PM
Suresh and Ravi,
you are real good contributors to this forum and i like that.
Not that you give a LOT of answers, your answers even porve quality.
BUT i have one thing. People asking questions here are sometimes not TOO used to the ABAP syntax and other concepts.
SAP noticed that themselves and made some concepts "obsolete", to get a code which is better to read. Especially for newbies.
And well HEADER LINES are obsolete by now.
People not beeing really used to ABAP will have really big Problems in reading things like:
Loop at itab.
...
endloop.
or even harder:
modify itab.
this shall not be critic in any way, but rather a suggestion on how you can help the better. Accoring to your number of posts thats what you actually want.
thx for convenience.
2007 Mar 19 2:39 PM
I was just about to say that I'm making every effort to develop my code without the use of header lines. How might I implement a similar solution without using a header line?
2007 Mar 19 2:53 PM
DATA: itab1 type ???,
itab2 type ???,
wa1 like line of itab1.
loop at itab1 into wa1.
read table itab2 with key matnr = wa1-matnr.
if sy-subrc <> 0.
delete from itab1 where matnr = wa1-matnr.
endif.
endloop.
this is a piece of code withput header lines.
2007 Mar 19 2:59 PM
The second line of the code snippet is still looking for a header line....it throws an error at itab2.
2007 Mar 19 3:01 PM
oh sorry i was too much in a hurry.
DATA: itab1 type ???,
itab2 type ???,
wa1 like line of itab1,
wa2 like line of itab1.
loop at itab1 into wa1.
read table itab2 into wa2 with key matnr = wa1-matnr.
if sy-subrc <> 0.
delete from itab1 where matnr = wa1-matnr.
endif.
endloop.
this is a piece of code withput header lines.
2007 Mar 19 3:08 PM
I got the work area part figured out. But...I get a strange error on the delete that says the table is not active or does not exist. Can I delete form a table while I'm looping over it?
2007 Mar 19 3:10 PM
2007 Mar 19 3:11 PM
2007 Mar 19 3:13 PM
Replace
delete from itab1 where matnr = wa1-matnr.
with
delete itab1 where matnr = wa1-matnr.
delete from option is used when you delete entires in the database table not an internal table. That is the reason, you get the synatx error that the table is not active.. since itab1 is not in the dictionary.
~Suresh
2007 Mar 19 2:30 PM
Hi Mathhew,
these is no terse way to do this. A liitle code nugget will do it for you.
loop at it_a.
lv_tabix = sy-tabix.
read table it_b with key matnr = it_a-matnr.
if sy-subrc <> 0.
delete it_a index lv_tabix.
endif.
endloop.Regards,
Ravi
2007 Mar 19 2:30 PM
loop at itab1 into wa1.
read table itab2 with key matnr = wa1-matnr.
if sy-subrc NE 0.
delete from itab1 where matnr = wa1_matnr.
endif.
endloop.
Message was edited by:
Florian Kemmer
2007 Mar 19 2:39 PM
Hi,
If those are internal tables then you can use any of these experts code, if those are database tables then you need to include one more statement ...
DELETE dbtab FROM TABLE itab.
loop at itab1.
read table itab2 with key matnr = itab1-matnr.
if sy-subrc NE 0.
DELETE dbtab FROM wa
DELETE dbtab FROM itab1.
endif.
endloop.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |