‎2007 Dec 26 4:41 AM
hi all,
may i know how to loop to check this.
hope to have the code.
thanks
table abc
fielda lot no fieldb status
123
123 x
123 x
123
LOOP AT itab.
va_tabix = sy-tabix.
(check against table abc base on [lot no]
if [status] in all records in table abc for the same lot '123' are 'x' then
DELETE itab INDEX va_tabix.
example of the table abc above only 2 records have 'x' so cannot delete itab.
ENDIF.)
ENDLOOP.
‎2007 Dec 26 4:56 AM
HI,
do like this
LOOP AT itab.
READ TABLE itab WITH KEY no = itab-no status = ' '.
IF sy-subrc NE 0.
delete itab where no = itab-no.
ENDIF.
ENDLOOP.
rgds,
bharat.
‎2007 Dec 26 4:58 AM
Hi,
LOOP AT itab.
va_tabix = sy-tabix.
select * from abc
where lot = itab-lot
and status NE 'X'.
if sy-subrc <> 0.
DELETE itab INDEX va_tabix
endif.
endloop.
Edited by: Ramesh Hirial on Dec 26, 2007 5:28 PM
‎2007 Dec 26 5:05 AM
hi,
i mean for the same lot no, if all status are 'x' then only delete. if out of 4, only 2 have 'x' then will not delete.
thanks
rgds
‎2007 Dec 26 5:11 AM
Just chk my post...i guess it will work...any queries revert
‎2007 Dec 26 5:12 AM
Hi,
check my code(previous reply).it will work according to ur requirement.
rgds,
bharat.
‎2007 Dec 26 5:21 AM
hi,
i loop at internal table ITAB.
each loop, will check lot no in TRANSPARENT TABLE ABC lot no.
if in TRANSPARENT TABLE ABC has 4 records with same lot no AND all status 'x' then only delete ITAB.
if in TRANSPARENT TABLE ABC has 4 records with same lot no but only 2 have status 'x' then not to delete ITAB.
table abc
field lot no field status
123
123 x
123 x
123
loop at ITAB.
va_tabix = sy-tabix.
(check against TRANSPARENT TABLE ABC base on lot no
if status in all records in TRANSPARENT TABLE ABC for the same lot '123' are 'x' then
DELETE itab INDEX va_tabix.
example of the TRANSPARENT TABLE ABC above only 2 records have 'x' so cannot delete itab.
ENDIF.)
ENDLOOP.
‎2007 Dec 26 5:05 AM
sort itab by field1 field 2 ascending.
create one extra field for deletion indicator.
loop at itab.
at new field1.
wk_field1 = itab-field1.
endat.
if itab-field1 = wk_field1 and itab-field2 = 'X'.
wk_status = 'D'.
else.
wk_status = 'N'.
endif.
at end of field1.
if wk_status = 'D'.
itab-del_flg = 'D'.
modify itab transporting del_flg where field1 = wk_field1.
endif.
clear wk_status.
clear wk_field.
endat.
endloop.
delete itab where del_flg = 'D'.
check whether this works
‎2007 Dec 26 5:28 AM
sort itab by field1 field 2 ascending.
create one extra field for deletion indicator.
Try to bring the status 'X' into the same itab and try my code.
or just include the select like below.
loop at itab.
at new field1.
wk_field1 = itab-field1.
endat.
select single * from <TAB> where = <----><pass your where
if TAB-field = 'X'
wk_status = 'D'.
else.
wk_status = 'N'.
endif.
CLEAR TAB.
at end of field1.
if wk_status = 'D'.
itab-del_flg = 'D'.
modify itab transporting del_flg where field1 = wk_field1.
endif.
clear wk_status.
clear wk_field.
endat.
endloop.
delete itab where del_flg = 'D'.
‎2007 Dec 26 8:21 AM
Hi,
Try the following set of code. It should definitely work.
Please let me know if you have any queries.
declare another variable.
DATA check_stat TYPE c.
check_stat = 'X'.
SORT itab BY lot_no.
LOOP AT itab.
IF itab-status NE 'X'.
CLEAR check_stat.
ENDIF.
AT END OF lot_no.
IF check_stat EQ 'X'.
DELETE itab WHERE lot_no EQ itab-lot_no.
ENDIF.
check_stat = 'X'.
ENDAT.
CLEAR itab.
ENDLOOP.
‎2007 Dec 26 8:28 AM
And, I want to update one more thing in continuation to my previous reply.
From the transparent table ABC, first retrieve all the relevant records into the internal table itab and then process the internal table using the loop statement, which will improve performance rather than the select statement inside the loop.
Hence, before the code that I have given, you should include SELECT statement to retrieve data from database into itab.
Regards,
Vidhya.