2023 Jan 16 7:42 AM
I have an internal table with 300 records. How can i delete every 3rd record of my internal table
2023 Jan 16 9:38 AM
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>
2023 Jan 16 7:53 AM
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.
2023 Jan 16 7:57 AM
Hi,
have you tried this
loop at it_data into data(wa_data).
check sy-tabix mod 3 = 0.
delete it_data.
endloop.
2023 Jan 17 5:45 AM
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.
2023 Jan 17 9:29 AM
The problem is that after the deletion sy-tabix will always be three.
2023 Jan 17 11:10 AM
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.
2023 Jan 16 8:02 AM
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
2023 Jan 16 8:32 AM
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 ] ) ).
2023 Jan 16 9:38 AM
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>
2023 Jan 17 6:30 AM
2023 Jan 16 11:55 AM
2023 Jan 16 11:56 AM
Same way as 2000 https://answers.sap.com/questions/13795556/delete-statement-1.html