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

deleting duplicates

Former Member
0 Likes
1,365

in my report at one point they are collecting all the records into one internal table using the syntax

collect rrb_tab.

but im getting double records in some cases . so i want to avoid that.

so after this collect statement can i use delete adjacent duplicate syntax as follows

collect rrb_ab.

DELETE ADJACENT DUPLICATES FROM RRB_TAB.

plz suggest me if i an use like this

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,331

Hi

its better 2 use the comparing option...

DELETE ADJACENT DUPLICATES FROM RRB_TAB COMPARING field1field2.

or

DELETE ADJACENT DUPLICATES FROM RRB_TAB COMPARING ALL FIELDS.

the former will compare the fileds n if ny duplicated in dose fields, only den it will delete dose records.

the latter,it will compare all de fields...if ny 2 records, with all fields same, it wil delete.

Regards

Winnie

Hi

its better 2 use the comparing option...

DELETE ADJACENT DUPLICATES FROM RRB_TAB COMPARING field1field2.

or

DELETE ADJACENT DUPLICATES FROM RRB_TAB COMPARING ALL FIELDS.

the former will compare the fileds n if ny duplicated in dose fields, only den it will delete dose records.

the latter,it will compare all de fields...if ny 2 records, with all fields same, it wil delete.

Regards

Winnie

10 REPLIES 10
Read only

Former Member
0 Likes
1,331

you need to sort internal table first.

Read only

sachin_mathapati
Contributor
0 Likes
1,331

Hi ,

First Sort the fields..and then delete adjacent duplicates comparing sorted fields..

Regards,

Sachin M M

Read only

Former Member
0 Likes
1,331

use Addition

... COMPARING {comp1 comp2 ...}|{ALL FIELDS}

with delete adjus.....

Read only

Former Member
0 Likes
1,331

ya you can try using that.

delete adjacent duplicates from rrb_tab based on the field which you want to comapre by adding

delete adjacent duplicates from rrb_tab comparing(fields)

Edited by: Rahul Kumar Sinha on Dec 3, 2008 10:06 AM

Read only

Former Member
0 Likes
1,332

Hi

its better 2 use the comparing option...

DELETE ADJACENT DUPLICATES FROM RRB_TAB COMPARING field1field2.

or

DELETE ADJACENT DUPLICATES FROM RRB_TAB COMPARING ALL FIELDS.

the former will compare the fileds n if ny duplicated in dose fields, only den it will delete dose records.

the latter,it will compare all de fields...if ny 2 records, with all fields same, it wil delete.

Regards

Winnie

Read only

0 Likes
1,331

SORT IT_TAB1 by matnr DATS DESCENDING.

then use delete adjacent duplicates from it_itab1 comparing matnr.

Read only

Former Member
0 Likes
1,331

Hi pavan,

you should first sort your internal table before deleting duplicates and then you can use the delete statement as below:

SORT it_cawn BY atinn atzhl

adzhl.

DELETE ADJACENT DUPLICATES FROM rrb_tab COMPARING < the fields that were used for sorting seperated by spaces/ or the key fields>.

Regards,

Nikita

Read only

Former Member
0 Likes
1,331

Hi,

Sort the internal table by key fields and then delete it.

SORT itab BY <keyfield>.

DELETE ADJACENT DUPLICATES FROM itab COMPARING <keyfield>

Regards,

K.Tharani.

Read only

Former Member
0 Likes
1,331

Hi,

To avoid getting duplicates in the table RRB_TAB you can define the fields that are duplicating as key fields of the internal table. That way the duplicates will be avoided when doing the collect itself. Thus avoiding the use of the statment delete adjacent duplicates..

regards,

Advait

Read only

0 Likes
1,331

Here is a simple example for the collect based on my reply above :


REPORT  z_collect_table                         .

TYPES : BEGIN OF t1,
          col1(20) TYPE c,
          col2 TYPE i,
        END OF t1.

DATA gt_tab  TYPE STANDARD TABLE OF t1.
DATA gt_tab_collect TYPE STANDARD TABLE OF t1 WITH KEY col1.

DATA : gwa_tab TYPE t1.

gwa_tab-col1 = 'Sam'.
gwa_tab-col2 = 1000.
APPEND gwa_tab TO gt_tab.

gwa_tab-col1 = 'Sam'.
gwa_tab-col2 = 1000.
APPEND gwa_tab TO gt_tab.

gwa_tab-col1 = 'Sam'.
gwa_tab-col2 = 1000.
APPEND gwa_tab TO gt_tab.

gwa_tab-col1 = 'Sam'.
gwa_tab-col2 = 1000.
APPEND gwa_tab TO gt_tab.

LOOP AT gt_tab INTO gwa_tab.

  COLLECT gwa_tab INTO gt_tab_collect.

ENDLOOP.

LOOP AT gt_tab_collect INTO gwa_tab.
  WRITE : / gwa_tab-col1, 10 gwa_tab-col2.
ENDLOOP.

"Output of the report is :

Collect statement                  
                                   
Sam           4.000                

regards,

Advait