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 IT_final table with condition

Former Member
0 Likes
1,332

Hi Expert,

       Following IT_final data to be filtered..

            Field1   Field2   Field3

            1            ABC     234

            3            234    

           4            CDE     89

            5            XYZ      22

            6            SLK     SPA

            8            89      

            9            DF       888

           10           FSD    

           12           234      

Note:  To delete the final table based on Red marked one where you can find logic ...the field3 would be coming same no again with blank space then to be deleted.

Here....Row 3, 8,12 should be deleted based on condition equal to previous field3 and field2 values and field3 next row.

thanks

shree

5 REPLIES 5
Read only

former_member585060
Active Contributor
0 Likes
1,121

Hi,

FIELD-SYBBOLS : <fs_final> TYPE LINE OF it_final.
DATA : v_tabix TYPE sy-tabix.


* Add a last field as flag TYPE c LENGTH 1, in the it_final.

LOOP AT it_final INTO wa_final.

v_tabix = sy-tabix + 1.

READ TABLE it_final ASSIGNING <fs_final>
           INDEX v_tabix.
IF sy-subrc = 0 AND
   <fs_final>-field2 = wa_final-field3 AND
   <fs_final>-field3 = ' '.

<fs_final>-flag = 'X'.


ENDIF.

CLEAR : wa_final, v_tabix.
ENDLOOP.


DELETE it_final WHERE flag = 'X'.

Thanks & Regards

Bala Krishna

Read only

0 Likes
1,121

Hi Bala,

         you use read statment. In case same record twice in the reading table..What can be don?

Thanks

shree

Read only

0 Likes
1,121

Then first use DELETE ADJUSCENT DUPLICATE ENTRIES FROM it_final COMPARING ALL FIELDS. and then use my logic.

Read only

Former Member
0 Likes
1,121

Hi Shree,

Create an internal table where you can save values of third field.

Loop at your internal table and in each loop append the third field to the new internal table.

After appending sort  the new internal table.

Inside the same Loop read the new internal table with third field value to check whether any record has the same value in second field.

If found delete the record.

Regards,

Vinay Mutt

Read only

0 Likes
1,121

Hello,

use the following

Make a copy of IT_final with data.(IT_final_cpy)

then

loop at IT_final into Is_final.

read table IT_final_cpy into Is_final_cpy with key field2 = ls_final-Field2.

if sy-subrc = 0.

delete IT_final_cpy  index sy-tabix.

else.

read table IT_final_cpy into Is_final_cpy with key field3 = ls_final-Field2.

if sy-subrc = 0.

delete IT_final_cpy index sy-tabix.

else.

read table IT_final_cpy into Is_final_cpy with key field3 = ls_final-Field3.

if sy-subrc = 0.

delete IT_final_cpy  index sy-tabix.

endif.

endif.

endif.

IT_final_cpy have correct data you want.

BR

Chandra...