Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

loop

Former Member
0 Likes
1,263

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.

10 REPLIES 10
Read only

Former Member
0 Likes
1,237

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.

Read only

Former Member
0 Likes
1,237

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

Read only

0 Likes
1,237

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

Read only

0 Likes
1,237

Just chk my post...i guess it will work...any queries revert

Read only

0 Likes
1,237

Hi,

check my code(previous reply).it will work according to ur requirement.

rgds,

bharat.

Read only

0 Likes
1,237

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.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,237

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

Read only

0 Likes
1,237

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'.

Read only

Former Member
0 Likes
1,237

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.

Read only

Former Member
0 Likes
1,237

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.