Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Using: Delete Adjacent Duplicates

Former Member
0 Likes
1,124

Hi,

How can we use Delete Adjacent Duplicates where comparing clause is dynamic.

The the number of comparison characteristics are dependent on some other conditions and are decided at runtime. Also can this be used with Field-Symbols.

Arunava

4 REPLIES 4
Read only

athavanraja
Active Contributor
0 Likes
767

Hi Arunava,

The following were taken from ABAP key word documentation.

1. The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.

2. <b>If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.</b>

3. You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.

Regards

Raja

Read only

0 Likes
767

Hi Raja,

I know that we can specify the fieldname dynamically. But there is a limitation I am facing. I have more that 1 field that are to be compared at one moment...somewhat like

COMPARING (K1 K2 K3)...now the system throws a dump when i try to generate this COMPARING clause by concatinating the elements.

So How can we use the Delete Adjacent Duplicate when there are more that one comparison Characteristics at are to be made at the same time.

I tried to use a table and pass that in the COMPARINg clause. It doesnot throw a dump but also the duplicates are not deleted.

Arunava

Regards,

Arunava

Read only

0 Likes
767

Hi Arunava?

Look at the sample code below , i think you are looking for this.


REPORT  Y_TEST_DELETE                           .

tables: csks .

data: itab like csks occurs 0 with header line .

data: name1(40) ,
      name2(40) .

start-of-selection .
clear: itab, name1 , name2 .
refresh itab .

move: 'KOSTL' to name1 ,
      'BUKRS' to name2 .

select * from csks into table itab where kostl eq '0000353540' .

delete adjacent duplicates from itab comparing (name1) (name2) .

Regards

Raja

Read only

0 Likes
767

Hi Arunava,

You can put the maximum number of fields (That is possible) in the comparing clause.If at run time there is no value in that then it will not take any value and will not be considered. if some value then it will be taken in to consideration at run time.

Regards,

Amit