05-18-2006 5:15 AM
Hi all,
I have to delete the itab comparing two fields.
Is this possible.
for ex,
delete itab where field1 >= field2.
where field1 and field2 are date fields.
I dont want to put this query in a loop.
Bye
Regrds
Priya OJ
05-18-2006 5:22 AM
yes that comparison exp >= is permitted with delete itab.
but what u want excatly
delete itab comparing field of the same row?
even if field1 , field2 are of date types also, >= comparison works.
LOOP AT ITAB.
DELETE ITAB WHERE ITAB-FIELD1 >= ITAB-FIELD2.
ENDLOOP.
IF FIELD1 AND FIELD2 ARE DIFFERENT FIELDS FROM ITAB.
THEN
DATA: FIELD1 TYPE DATE, FIELD2 TYPE DATE.
LOOP AT ITAB.
DELETE ITAB WHERE FIELD1 >= FIELD2.
ENDLOOP.
05-18-2006 5:23 AM
05-18-2006 5:23 AM
Hi Priya,
Do you want to delete the whole internal table on comparing a value in the field 1 and in the field2.
Then...
READ TABLE itab INDEX 1 INTO itab_wa.
if itab_wa-f1 ge itab_wa-f2.
delete itab index 1. "If you want to delete that line.
clear itab. "Whole itab is deleted.
endif.
If you want to check row by row then...
you have to go for a loop.
loop at itab into itab_wa.
if itab_wa-f1 ge itab_wa-f2.
delete itab index sy-tabix.
endif.
endloop.
Hope it helps.
Regards,
Maheswaran.B
Message was edited by: Maheswaran B
Message was edited by: Maheswaran B
Message was edited by: Maheswaran B
05-18-2006 5:59 AM
Hi priya,
1. There is no direct one-shot statement
which can achieve this.
2. If possible, while populating the internal table,
we can take one extra field FLAG
and put value 'X' if date1 > date2.
(this may be done while populating the internal table
itself, or else, may be done in a loop)
(loop as u say, u do not want)
3. Then using DELETE ITAB where FLAG = 'X'.
4. to get a taste of it , just copy paste in new program.
5.
REPORT abc .
*----
Data
data : begin of itab occurs 0,
d1 type sy-datum,
d2 type sy-datum,
flag type c,
end of itab.
*----
itab-d1 = '20060518'.
itab-d2 = '20060517'.
append itab.
itab-d1 = '20060518'.
itab-d2 = '20060519'.
append itab.
itab-d1 = '20060518'.
itab-d2 = '200605120'.
append itab.
*----
Extra logic while populating table
loop at itab.
if itab-d1 > itab-d2.
itab-flag = 'X'.
modify itab.
endif.
endloop.
*----
break-point.
delete itab where flag = 'X'.
break-point.
regards,
amit m.
05-18-2006 6:21 AM
05-18-2006 6:53 AM
Hi,
lOOP AT ITAB.
DELETE IT_TAB WHERE ITAB-FILED1 NE ITAB-FILED2.
CONTINUE.
ENDLOOP.
Check for Continue statement.
Regards,
Irfan Hussain
05-18-2006 6:55 AM
Hai Priya
Check the following Link
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/delete_i.htm
Thanks & regards
Sreenivasulu P