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

How do I delete rows from an internal table?

Former Member
0 Likes
927

Hi,

I have a simple block of code that reads rows from an internal table (already populated from a database table) and displays the data on the screen with a WRITE statement.

Just for practice I am trying to delete the rows from the internal table after I have displayed them.

Here is the code that I have so far, but this is not correct. Can someone please tell me how to code the DELETE statement?

Thank you!

Andy

LOOP AT it_zmember01 INTO wa_zmember01.

WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',

wa_zmember01-mname UNDER 'NAME',

wa_zmember01-mdob UNDER 'DOB'.

WRITE / '----


'.

DELETE it_zmember01 FROM wa_zmember01.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
895

Use this code

data : l_tabix like sy-tabix.

LOOP AT it_zmember01 INTO wa_zmember01.

l_tabix = sy-tabix.

WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',

wa_zmember01-mname UNDER 'NAME',

wa_zmember01-mdob UNDER 'DOB'.

WRITE / '----


'.

DELETE it_zmember01 index l_tabix.

ENDLOOP.

Use this code

data : l_tabix like sy-tabix.

LOOP AT it_zmember01 INTO wa_zmember01.

l_tabix = sy-tabix.

WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',

wa_zmember01-mname UNDER 'NAME',

wa_zmember01-mdob UNDER 'DOB'.

WRITE / '----


'.

DELETE it_zmember01 index l_tabix.

ENDLOOP.

6 REPLIES 6
Read only

Former Member
0 Likes
895

Hi Andrew,

Use DELETE t_itab statement inside the loop.

I have modified your code. It is perfectly working.See bellow -


LOOP AT it_zmember01 INTO wa_zmember01.
WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',
wa_zmember01-mname UNDER 'NAME',
wa_zmember01-mdob UNDER 'DOB'.
WRITE / '-----------------------------------------------------------------'.
DELETE it_zmember01.               " Modified
ENDLOOP.

DELETE it_zmember01. statement inside the loop will delete the current row of the table.

Regards

Pinaki

Read only

0 Likes
895

Pinaki,

One thing I did not mention is that this internal table does not have a header line, so your solution did not work in my case. But now I know that if I had a header line I could use your solution.

Thank you very much.

Andy

Read only

Former Member
0 Likes
896

Use this code

data : l_tabix like sy-tabix.

LOOP AT it_zmember01 INTO wa_zmember01.

l_tabix = sy-tabix.

WRITE: / wa_zmember01-mnumber UNDER 'NUMBER',

wa_zmember01-mname UNDER 'NAME',

wa_zmember01-mdob UNDER 'DOB'.

WRITE / '----


'.

DELETE it_zmember01 index l_tabix.

ENDLOOP.

Read only

0 Likes
895

Vijayakumar V

Perfect...Thank you very much!

Andy

Read only

Former Member
0 Likes
895

Hi,

Try this.

data: v_tabix type sy-tabix.

loop at itab

v_tabix = sy-tabix.

write: itab-field.

delete itab index sy-tabix.

endloop.

Read only

0 Likes
895

N Soumya

Your solution was exactly the same as Vijayakumar V

Thank you very much for the help. I appreciate it!

Andy