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

Delete from Internal table

Former Member
0 Likes
1,153

Hi I have an internal table Itab and it has the following :

Field1 Field2

-


A1 B1

A2 B2

A3 B3

A4 B2

Now I want to retain only the records which have B2 or B3 in the internal table and delete all other records.

I am trying to do this:

Delete Itab where Field2 <> 'B2' or Field2 <> 'B3'.

This statement is not working and it deletes all the contents of the internal table.

Can someone tell me how I can acheieve the delete .

Thanks in advance.

8 REPLIES 8
Read only

Former Member
0 Likes
1,131

Delete Itab where Field2 NE 'B2' and Field2 NE 'B3'.

Try this

Read only

Former Member
0 Likes
1,131
Total Questions:  88 (71 unresolved)

Why not follow up on your old posts?

Rob

Read only

Former Member
0 Likes
1,131
Loop at itab.

If itab-field2 NE 'B2' and itab-field2 NE 'B3'.
Delete Itab index sy-tabix.
Endif.

Endloop.

Hope this resolves the issue.

Regards,

Gurpreet

Read only

Former Member
0 Likes
1,131

Try this

delete it_tab where not ( f2 = 'B2' or f2 = 'B3').

Thanks.

Read only

Former Member
0 Likes
1,131

Hi Kiran,

Try using DELETE itab where ( field2 ne 'B2' and field2 ne 'B3' ).

Hope this should solve the problem.

Regards

Sravan

Read only

faisalatsap
Active Contributor
0 Likes
1,131

Hi, Kiran

Please Mark your All Question as answered if solved

Test the following Sample Code it will solve out your problem,

DATA: BEGIN OF it OCCURS 10,
  c1(3),
  c2(3),
  END OF it.
RANGES: r_rec FOR it.

r_rec-sign = 'I'.
r_rec-option = 'EQ'.
r_rec-low = 'B2'.
APPEND r_rec TO r_rec.
r_rec-low = 'B3'.
APPEND r_rec TO r_rec.

it-c1 = 'A1'.
it-c2 = 'B1'.

DO 5 TIMES.
  APPEND it TO it.
  ADD 1 TO : it-c1+1(1),
             it-c2+1(1).
ENDDO.

DELETE it WHERE c2 IN r_rec.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,131

Hi try usingdelete itab where field2 <> b1 or field2 <> b2.

Thanks

Read only

Former Member
0 Likes
1,131

try usin delete itab where f2 <> b1 or f2 <> b2.

Regards