2007 Aug 21 3:21 PM
Hi
How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
I have created a method, with the following code:
......
LOOP AT me->business_document_lines INTO l_add_line.
CREATE OBJECT ot_line_owner
EXPORTING
i_user = l_add_line->add_line_data-line_owner
i_busdoc = me->business_document_id.
APPEND ot_line_owner TO e_line_owners.
ENDLOOP.
.....
e_line_owners are defined as a table containing only object references.
One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
How can do this?
Regards,
Morten Nielsen
2007 Aug 21 8:06 PM
Hello Morten
Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
SORT e_line_owners BY table_line->user.
DELETE ADJACENT DUPLICATES FROM e_line_owners
COMPARING table_line->user.However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
Alternative solution:
DATA:
ld_idx TYPE sy-tabix.
LOOP AT e_line_owners INTO ls_line.
ld_idx = syst-tabix + 1.
LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
WHERE ( table_line->user = ls_line->user ).
DELETE e_line_owners INDEX syst-tabix.
ENDLOOP.
ENDLOOP.Regards
Uwe
Hi
How can I delete duplicates from an internal table in ABAP OO based on the value of one of the attributes?
I have created a method, with the following code:
......
LOOP AT me->business_document_lines INTO l_add_line.
CREATE OBJECT ot_line_owner
EXPORTING
i_user = l_add_line->add_line_data-line_owner
i_busdoc = me->business_document_id.
APPEND ot_line_owner TO e_line_owners.
ENDLOOP.
.....
e_line_owners are defined as a table containing only object references.
One of the attribute of the object in the table is called USER. And I would like to do a "delete ADJACENT DUPLICATES FROM e_line_owners", based on that attribute.
How can do this?
Regards,
Morten Nielsen
2007 Aug 21 5:09 PM
Hello,
I think you will have to do it manually...
Store the value of the attrib of the first line of the table in a temp value lv_attrib_old.
LOOP starting a the second line INTO lv_line_new.
check if the value of the attrib in the same.
In this case delete the line.
else
lv_attrib_old = lv_line_new->attrib.
ENDLOOP.
Hope this help...
Or you can do it when you create your table so you don't add it when the attribute has the same value as the old one.
2007 Aug 21 5:17 PM
Hello
What about creating your internal table with index....so you wont be able to repeat elements inside the IT
Bye
Gabriel
2007 Aug 21 8:06 PM
Hello Morten
Assuming that the instance attribute is <b>public </b>you could try to use the following coding:
SORT e_line_owners BY table_line->user.
DELETE ADJACENT DUPLICATES FROM e_line_owners
COMPARING table_line->user.However, I am not really sure (cannot test myself) whether <b>TABLE_LINE</b> can be used together with SORT and DELETE.
Alternative solution:
DATA:
ld_idx TYPE sy-tabix.
LOOP AT e_line_owners INTO ls_line.
ld_idx = syst-tabix + 1.
LOOP AT e_line_owners TRANSPORTING NO FIELDS FROM ld_idx
WHERE ( table_line->user = ls_line->user ).
DELETE e_line_owners INDEX syst-tabix.
ENDLOOP.
ENDLOOP.Regards
Uwe
2007 Aug 21 9:15 PM
Thanks Uwe !
The first suggestion worked like a dream
Regards
Morten
2007 Aug 21 10:08 PM
Hello Morten
Thanks for this feedback. I have seen and used TABLE_LINE together with READ TABLE and LOOP AT yet it is good to know that it works for the other statements as well.
Best Regards
Uwe
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |