‎2012 Mar 02 11:01 AM
Hi,
I want to trigger this kind of abap line code:
delete adjacent duplicates from my_itab comparing (lv_compare).
But it does not work.
Where in lv_compare, i have many fieds.
Before executing, I don't know neither the number of field nor names
‎2012 Mar 02 11:34 AM
When ABAP syntax does not offer dynamic options, like in this case, the last resort is to temporarily generate and execute code using the GENERATE SUBROUTINE POOL statement, see ABAP online help.
However using this statement can be subject to checks and questions by IT auditors, just so that you know
Thomas
‎2012 Mar 02 12:44 PM
‎2012 Mar 02 12:50 PM
Hi,
I have done dynamic comparision for delete adjacent duplicates for dynamic internal table, using the key fields of the table. Please find the sample code below. The maximum number of key fields is 7 for the tables that i will be accessing. So have used 7 fieldsymbols in my 'delete adjacent duplicate'.
<removed by moderator>
DATA : lv_index TYPE numc2.
DATA : lv_field_01 TYPE fieldname.
DATA : lv_field_02 TYPE fieldname.
DATA : lv_field_03 TYPE fieldname.
DATA : lv_field_04 TYPE fieldname.
DATA : lv_field_05 TYPE fieldname.
DATA : lv_field_06 TYPE fieldname.
DATA : lv_field_07 TYPE fieldname.
DATA : lv_key_fieldname TYPE char50.
DATA : lt_keyfields TYPE abap_sortorder_tab.
DATA : lwa_keyfields TYPE abap_sortorder.
FIELD-SYMBOLS : <lv_key_fieldname> TYPE ANY.
* Get the key fields of the table
SELECT fieldname FROM dd03l
INTO TABLE lt_tabkfields
WHERE tabname = pv_tabname
AND keyflag = 'X'.
LOOP AT lt_tabkfields INTO lwa_tabkfields.
lv_index = lv_index + 1.
lwa_keyfields-name = lwa_intlen-fieldname.
APPEND lwa_keyfields TO lt_keyfields.
CONCATENATE 'LV_FIELD' lv_index INTO lv_key_fieldname SEPARATED BY '_'.
ASSIGN (lv_key_fieldname) TO <lv_key_fieldname>.
IF sy-subrc EQ 0.
<lv_key_fieldname> = lwa_tabkfields-fieldname.
ENDIF.
ENDLOOP.
SORT <lfs_xdata_table> BY (lt_keyfields).
DELETE ADJACENT DUPLICATES FROM <lfs_xdata_table>
COMPARING (lv_field_01) (lv_field_02) (lv_field_03)
(lv_field_04) (lv_field_05) (lv_field_06) (lv_field_07).Thanks,
Priya
Edited by: Thomas Zloch on Mar 2, 2012
‎2012 Mar 02 12:57 PM
Dear Priya,
I have already try it but I was not really satisfied by this solution.
I'm sure it will probably work because I don't expect to have more than 7 fields to sort. but we never know...
Regards
Jacques
‎2012 Mar 02 1:28 PM
what is the structure of lv_compare?
At runtime how this is filled with name of fields? an example will be helpfull to understand the requiremnt.
‎2012 Mar 02 12:54 PM
Hi,
If it is feasible, you can give the names of all the fields in the Delete Adjacent statement.
DELETE ADJACENT DUPLICATES FROM i_table COMPARING (l_var1) (l_var2) (l_var3) (l_var4).......
At runtime you can assign values to these variables. If a variable is empty then it is ignored otherwise it will be considered.
Regards,
Harsh Bansal