04-17-2008 5:11 PM
Hi,
I have an ABAP internal table with four fields f1 f2 f3 f4 that i am deleting adjacent duplicates from. However for each line that i delete i wish to know how many lines were deleted (i.e. how many f4's there were). Anyone know how i could code this?
for example i initially have :
f1 f2 f3 f4
data gad fsd vsds
data gad fsd gdfgf
faff gfg gdg fsgs
after that i have
f1 f2 f3 f4 count
data gad fsd vsds 2
faff gfg gdg fsgs 1
Basically i want to delete the extra rows but know how many were deleted via some sort of count applied to the itab before the DELETE ADJACENT DUPLICATES FROM itab comparing f1 f2 f3 statement. Any help would be much appreciacted.
04-17-2008 5:14 PM
Unless you want to know how many of each type was deleted, you can use DESCRIBE TABLE it_table lines linecount, before and after your DELETE line. Subtract the two values and you'll have the result.
04-17-2008 5:25 PM
Hi,
Thanks for that - i think i will need to use some sort of describe but i will have many rows in the table that have been collected - sorry my example was a little short. So basically i need to know the count FOR EACH row that is summed. Thanks
A better one would be :
f1 f2 f3 f4
data gad fsd vsds
data gad fsd gdfgf
faff gfg gdg fsgs
sds fsf fsfsf fsfs
sds fsf fsfsf dgs
becomes
f1 f2 f3 f4 count
data gad fsd vsds 2
faff gfg gdg fsgs 1
sds fsf fsfsf fsfs 2
04-17-2008 5:31 PM
hi samir,
You can use collect statement inside the loop for summarised output.
for exmaple:
TYPES: BEGIN OF COMPANY,
NAME(20) TYPE C,
SALES TYPE I,
END OF COMPANY.
DATA: COMP TYPE COMPANY,
COMPTAB TYPE HASHED TABLE OF COMPANY
WITH UNIQUE KEY NAME.
COMP-NAME = 'Duck'. COMP-SALES = 10. COLLECT COMP INTO COMPTAB.
COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB.
COMP-NAME = 'Duck'. COMP-SALES = 30. COLLECT COMP INTO COMPTAB.
Table COMPTAB now has the following contents:
NAME | SALES
---------------
Duck | 40
Tiger | 20
04-17-2008 5:15 PM
Do like this.
Make sure that your count is numeric type
loop at itab.
collect itab to itab_new.
endloop.
*itab and itab_new are of same type and itab_new should have the count
Regards,
Ravi Kanth Talagana
Edited by: Ravi Kanth Talagana on Apr 17, 2008 6:15 PM
04-17-2008 5:25 PM
Hi Samir,
you can do one thing.check the following program
REPORT zchaitu_report5.
data:begin of itab occurs 0,
f1 type i,
f2 type i,
end of itab.
data:c1 type i,
c2 type i.
itab-f1 = 1.itab-f2 = 2.append itab.
itab-f1 = 1.itab-f2 = 1.append itab.
itab-f1 = 2.itab-f2 = 3.append itab.
loop at itab.
c1 = c1 + 1.
endloop.
sort itab.
delete adjacent duplicates from itab comparing f1.
loop at itab.
c2 = c2 + 1.
endloop.
write: / c1,c2.
c1 is the no of records before deletion,c2 is the no of records after deletion.difference between c1 and c2 is the no of records deleted.
04-17-2008 5:33 PM
The crucial thing that i need is the NUMBER OF LINES WITH WHICH f1 f2 and f3 are equal FOR EACH ROW. Hope that clarifies what i need... Thanks,
Samir
04-17-2008 6:01 PM
Before doing the delete you can do this.
LOOP AT ITAB.
AT NEW (field2).
add 1 to lv_records.
NOW store this data in a separate internal table together with the identifying fields.
ENDAT.
ENDLOOP.
04-17-2008 6:08 PM
Hello
Ravi has given you a good solution as per below.
****************
Do like this.
Make sure that your count is numeric type
loop at itab.
collect itab to itab_new.
endloop.
*itab and itab_new are of same type and itab_new should have the count
Regards,
Ravi Kanth Talagana
*****************
I would add a couple of details.
itab and itab_new will look like:
f1 f2 f3 f4 count
where count is an integer and should be equal to 1 for each line in itab.
Also, f1 - f4 are all non-numeric.
Now when you run Ravi's code above itab_new-count will have the record
count that you are looking for.
Now you can go ahead and delete adjacent duplicates.
Regards
Greg Kern