Application Development 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: 

Delete itab

Former Member
0 Kudos

Hi Experts,

I have one internal table itab.

Itab contains the values:

Field X Field Y

10 A

10 B

10 K

20 A

20 C

30 A

i want to delete the internal table records

where Field X = 'K' and also i dont want the records field X values if any one of field Y contains 'K'.

i want output like this.

Field X Field Y

20 A

20 C

30 A

here field Y contains value 'K' in field X value 10. so i want to delete field X which are contains value "10'.( i want to delete records if any one the field Y contains "K').

please how to code for this. help me..

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi Silviya,

you can do like this..

data : x1 like itab-x.
....
read table itab with key Y ='K'.
x1 = itab-x.
delete itab where X = x1.
delete itab where X = 'K'.

regards

satesh

5 REPLIES 5

Former Member
0 Kudos
LOOP AT itab WHERE Y = 'K'..
  DELETE itab WHERE X = itab-x.
ENDLOOP.

Former Member
0 Kudos

hi Silviya,

you can do like this..

data : x1 like itab-x.
....
read table itab with key Y ='K'.
x1 = itab-x.
delete itab where X = x1.
delete itab where X = 'K'.

regards

satesh

Former Member
0 Kudos

Hi,

Try this.

DATA: BEGIN OF ITAB1 OCCURS 0,

X TYPE ANY,

Y TYPE ANY,

END OF ITAB1.

DATA: BEGIN OF ITAB2 OCCURS 0,

X TYPE ANY,

END OF ITAB2.

LOOP AT ITAB1 WHERE Y = 'K'.

ITAB2-X = ITAB1-X.

APPEND ITAB2.

ENDLOOP.

SORT ITAB2.

DELETE ADJACENT DULTICATE FROM ITAB2.

LOOP AT ITAB1.

READ TABLE ITAB2 WITH KEY X = ITAB1-X.

IF SY-SUBRC = 0.

DELETE ITAB1.

ENDIF.

ENDLOOP.

I hope this will work for you.

Thanks,

Pal

Former Member
0 Kudos

you can simply do this.

read table itab into wa with key field2 = 'K'.

    delete itab  where field2 = 'K'
                    or field1 = wa-field1.

regards,

Kinshuk Saxena

Former Member
0 Kudos

---- This will delete all the record of field1 for coreesponding value of field2 with value 'K'.----


loop at itab where field2 = 'K'.

delete itab where field1 = itab-field1.

endloop.

---- This will delete all the record for value field2 ='K'.------

delete itab where field2 = 'K'.

hope solve your problem