‎2013 Mar 05 3:09 PM
Hello all ,
iam new to abap.
i have a requirement where i need retain the fiest 3 records for the combination werks and matnr in an internal table and delete ramaining records for that combination
can any one pls help me how can i do this.
thanks
Ramesh
‎2013 Mar 05 3:39 PM
Ramesh, there are many ways to achieve this.
sort table1 by werks matnr.
table2[] = table1[].
delete adj duplicates from table2 comparing werks matnr.
loop at table2 into wa2.
clear counter.
loop at table1 assigning <fs1> where werks = wa2-werks and matnr = wa-matnr.
counter = counter + 1.
if counter > 3.
clear <fs1>-werks.
endif.
endloop.
endloop.
delete table1 where werks is initial.
thanks,
Vikram.M
‎2013 Mar 05 3:44 PM
Hi Ramesh.
Maybe try something like this
Declare a work area same as your internal table.
Data: wa_itab type (same as your internal table),
lv_tabix type sy-tabix.
Loop at itab into wa_itab,
lv_tabix = sy-tabix.
if lv_tabix > 3.
delete itab from wa_itab index lv_tabix.
endif.
Endloop.
‎2013 Mar 05 3:49 PM
Hi,
Try this for deleting first 3 rows.
while sy-tabix > 4.
delete it where <condition>.
endwhile.
‎2013 Mar 05 4:05 PM
‎2013 Mar 05 4:58 PM