04-06-2009 10:17 PM
LOOP AT ITAB INTO WA_ITAB.
read table itab2 into wa_itab2.
if sy-subrc is initial.
*I want to delete entries from ITAB.*
DELETE ITAB FROM WA_ITAB.
MODIFY ITAB.
endif.
ENDLOOP.
I am getting a dump if i do like this.
What is the correct syntax for this?
Rgds
Praveen
Edited by: PRAVEEN s on Apr 6, 2009 11:19 PM
04-06-2009 10:23 PM
Check this
LOOP AT ITAB INTO WA_ITAB.
v_tabix = sy-tabix. "<<<
read table itab2 into wa_itab2.
if sy-subrc is initial.
DELETE ITAB FROM WA_ITAB index v_tabix. "<<<<<.
MODIFY ITAB. " <<<< After deleting why need a modify ???
endif.
ENDLOOP.
a®
04-06-2009 10:24 PM
Not a good idea to delete records from a table that you are looping through. SY-TABIX would be hard to interpret.
Having said that, we quite often delete the particular line that we are on.
Rob
Edited by: Rob Burbank on Apr 6, 2009 5:32 PM
04-06-2009 10:50 PM
Hi,
I am getting an error message
on
DELETE ITAB FROM WA_ITAB index v_tabix
WA_ITAB May not be converted into a number.
Rob I have a situation to use this logic..
rgds
praveen
04-07-2009 5:58 AM
Hi Praveen,
Change line DELETE ITAB FROM WA_ITAB index v_tabix.
To DELETE TABLE ITAB FROM WA_ITAB. <----
Use keyword 'TABLE'.
Since 'itab' is internal table not database table.
That is why you are getting error 'WA_ITAB May not be converted into a number.
Edited by: Sap Fan on Apr 7, 2009 7:19 AM
04-07-2009 1:06 AM
Hi,
change your statement like below specified
DELETE ITAB index v_tabix
Regards,
Peranandam
04-07-2009 6:07 AM
Hi Praveen,
Here in this problem , according to sytax we cant specify work area and index same time.
so change your staemt to DELETE itab INDEX idx.
because we are specifying index so there is no need to give work area.
Regards,
Nitin
04-07-2009 6:24 AM
Hi,
You can do that, but with little modification
Don't use DELETE statement in LOOP and ENDLOOP statement, instead set a flag if the condition is met.
Note:- If we use DELETEstatement in LOOP, every time the statement is executed, it has to regenerate the index, which will effect the performance if the records are more in the internal table.
Then with DELETE statement delete all the records with the flag is set outside the LOOP.
see the sample code
'You have not used any where condition in READ statement, so not clear that how you are comparaing itab and itab2
"Declare a field flag of type c in itab internal table.
LOOP AT itab INTO wa_itab.
w_tabx = sy-tabix.
READ TABLE itab2 INTO wa_itab2 WITH KEY field = wa_itab-field.
IF sy-subrc = 0.
wa_itab-flag = 'X'.
MODIFY itab INDEX w_tabx FROM wa_itab TRANSPORTING flag.
ENDIF.
CLEAR w_tabx.
ENDLOOP.
DELETE itab WHERE flag = 'X'.
Regards
Bala Krishna
04-07-2009 7:06 AM
Simply write down
DELETE ITAB.
when u have written ur delete statement.
04-07-2009 7:10 AM
Simple write down
DELETE ITAB.
in place of
DELETE ITAB FROM WA_ITAB.
MODIFY ITAB.
Regards,
Chintan.
04-07-2009 11:24 AM
Praveen,
the best way to do is jus by
DELETE ITAB where (some key ) = WA_ITAB-key.
since itab and wa_itab has a key field this should work. Test it and telme in case you need any help.
@ Chintan,
Your statement will work only if the table contains a header line. If it is without header line the statement wont work.
Gowri
04-07-2009 5:46 PM
Thank you all.
As I am having issues with this delete statement with Work area.I moved it to different internal table
and resolved issue.
rgds
Praveen
07-11-2014 9:22 PM
do like that
DATA: v_tabix TYPE i.
LOOP AT itab INTO wa_itab.
ADD 1 TO v_tabix.
READ TABLE itab2 INTO wa_itab2.
IF sy-subrc IS INITIAL.
DELETE itab INDEX v_tabix.
SUBTRACT 1 FROM v_tabix.
ENDIF.
ENDLOOP.