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

Internal tables issue

ashok_2329
Explorer
0 Likes
2,527

I have an internal table with 300 records. How can i delete every 3rd record of my internal table

1 ACCEPTED SOLUTION
Read only

shantraj6
Explorer
0 Likes
2,399

Check the below.

Data: lv_index type sy-tabix.
loop at it_data assigning field symbol(<lfs_data>).
lv_index = sy-tabix.
  check lv_index mod 3 = 0.
   clear <lfs_data>-fieldname.
endloop.
delete it_data where fieldname is initial.<br>

I have an internal table with 300 records. How can i delete every 3rd record of my internal table

11 REPLIES 11
Read only

Sandra_Rossi
Active Contributor
2,399

You can look at all possible operations on internal tables here: https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentable_processing_...

Concerning the logic of deleting lines number 3, number 6, number 9, etc., I guess you won't have any difficulty knowing the statements to process the internal tables.

Read only

ThorstenHoefer
Active Contributor
0 Likes
2,399

Hi,

have you tried this

loop at it_data into data(wa_data).
check sy-tabix mod 3 = 0.
delete it_data.
endloop.
Read only

0 Likes
2,399

Hi,

I was trayed this but it will delete every record after 1 and 2.

I am getting only first two records in my output after use this statement.

Read only

matt
Active Contributor
0 Likes
2,399

The problem is that after the deletion sy-tabix will always be three.

Read only

0 Likes
2,399

Can you add your own variable like

i_cnt

loop at it_data into data(wa_data).
  add 1 to i_cnt.
  check i_cnt mod 3 = 0.
  delete it_data.
endloop.
Read only

lenapadeken
Product and Topic Expert
Product and Topic Expert
2,399

Hi ashok_2329,

Since ABAP Release 7.87/7.55, SAP BTP ABAP Environment 2202, there's the addition STEP, which you can use for defining a step size. For example:

DELETE itab STEP 3.

Link to documentation (https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapdelete_itab_lines...) and blog post (https://blogs.sap.com/2022/07/04/reverse-loop-finally-possible-with-step-addition-for-abap-internal-...).

Best regards,

Lena

Read only

ThorstenHoefer
Active Contributor
2,399

I haven't tested this. But this could work:

DATA(output) =
      value #(
        FOR  i = 1 THEN i + 3  WHILE i <= lines( itab )
        ( itab[ i ] )  ).


output =
      value #(
        base output
        FOR  i = 2 THEN i + 3  WHILE i <= lines( itab )
        ( itab[ i ] )  ).
Read only

shantraj6
Explorer
0 Likes
2,400

Check the below.

Data: lv_index type sy-tabix.
loop at it_data assigning field symbol(<lfs_data>).
lv_index = sy-tabix.
  check lv_index mod 3 = 0.
   clear <lfs_data>-fieldname.
endloop.
delete it_data where fieldname is initial.<br>
Read only

0 Likes
2,399

Thanks a lot it's working

Read only

matt
Active Contributor
2,399

Homework question is it?

Read only

matt
Active Contributor