2008 Mar 04 7:38 AM
Hi,
How can I delete adjacent duplicates from a dynamic table using the table keys.
I have concatenated the table keys to a string variable.
When I try to delete the duplicates I receive a dump.
Does anyone knows a way to overcome it ?
Thanks.
Hi,
How can I delete adjacent duplicates from a dynamic table using the table keys.
I have concatenated the table keys to a string variable.
When I try to delete the duplicates I receive a dump.
Does anyone knows a way to overcome it ?
Thanks.
2008 Mar 04 8:51 AM
try to use :
Delete adjacent duplicates from itab COMPARING ALL FIELDS
A.
2008 Mar 04 9:08 AM
you can use a function GET_COMPONENT_LIST to get all the fields' name after the dynamic table generated. then you can use the field name in the statement "DELETE....COMPARE "
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = SY-REPID
fieldname = THE_NAME_OF_THE_DYNAMIC_INTERNAL_TABLE
tables
components = ITAB
.
LOOP AT ITAB.
*ASSIGN THE ITAB-COMPNAME TO SOME VARIANTS:FIELD1,FIELD2,FIELD3.
ENDLOOP.
SORT THE_NAME_OF_THE_DYNAMIC_INTERNAL_TABLE BY FIELD1 FIELD2 FIELD3.
DELETE ADJACENT DUPLICATES FROM THE_NAME_OF_THE_DYNAMIC_INTERNAL_TABLE COMPARING FIELD1 FIELD2 FIELD3.
2008 Mar 04 10:21 AM
I wont delete the duplicates depending on the table keys - and I don't know the number of keys.
2022 Jul 19 3:50 PM
Try this approach:
DATA:
tabname TYPE tabname, "db table name from DDIC
lt_key_fields TYPE abap_sortorder_tab,
lv_key1 TYPE fieldname,
lv_key2 TYPE fieldname,
lv_key3 TYPE fieldname,
lv_key4 TYPE fieldname,
lv_key5 TYPE fieldname,
lo_tabletype TYPE REF TO data,
lo_table_descr TYPE REF TO cl_abap_tabledescr.
FIELD-SYMBOLS: <lt_cust_data> TYPE STANDARD TABLE.
CREATE DATA lo_tabletype TYPE STANDARD TABLE OF (tabname).
lo_table_descr ?= cl_abap_tabledescr=>describe_by_data_ref( p_data_ref = lo_tabletype ).
DATA(lt_keys) = lo_table_descr->get_keys( ).
lt_key_fields = CORRESPONDING #( lt_keys[ 1 ]-components ). "sorted ascending, not as TEXT
CLEAR: lv_key1, lv_key2, lv_key3, lv_key4, lv_key5.
LOOP AT lt_key_fields ASSIGNING FIELD-SYMBOL(<ls_field>).
IF <ls_field>-name NE 'MANDT' AND "Skip the client field!
<ls_field>-name NE 'CLIENT'.
IF lv_key1 IS INITIAL.
lv_key1 = <ls_field>-name.
ELSEIF lv_key2 IS INITIAL.
lv_key2 = <ls_field>-name.
ELSEIF lv_key3 IS INITIAL.
lv_key3 = <ls_field>-name.
ELSEIF lv_key4 IS INITIAL.
lv_key4 = <ls_field>-name.
ELSEIF lv_key5 IS INITIAL.
lv_key5 = <ls_field>-name.
ENDIF.
ENDIF.
ENDLOOP.
ASSIGN <ls_cust_reg>-data->* TO <lt_cust_data>. "that is a standard table of "tabname"
APPEND LINES OF <lt_insertable_data> TO <lt_cust_data>. "that are some new table entries...
SORT <lt_cust_data> STABLE BY (lt_key_fields).
DELETE ADJACENT DUPLICATES FROM <lt_cust_data> COMPARING (lv_key1) (lv_key2) (lv_key3) (lv_key4) (lv_key5).
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |