How to find only duplicate records from table ?

Answer Posted / kkr

*****Keep duplicate records and delete unique records.********
TYPES:BEGIN OF TY_IT,
FIELD1 TYPE C,
FIELD2 TYPE C,
END OF TY_IT.
DATA:IT TYPE STANDARD TABLE OF TY_IT.
DATA:IT1 TYPE STANDARD TABLE OF TY_IT.
DATA:WA like line of IT.
DATA:WA1 like line of IT.
DATA:COUNT TYPE I.

*WA-FIELD1 = 'A'.WA-FIELD2 = 'b'.APPEND WA TO IT.
*WA-FIELD1 = 'A'.WA-FIELD2 = 'b'.APPEND WA TO IT.
*WA-FIELD1 = 'C'.WA-FIELD2 = 'b'.APPEND WA TO IT.
*WA-FIELD1 = 'P'.WA-FIELD2 = 'x'.APPEND WA TO IT.
*WA-FIELD1 = 'D'.WA-FIELD2 = 'b'.APPEND WA TO IT."Delete
*WA-FIELD1 = 'C'.WA-FIELD2 = 'b'.APPEND WA TO IT.
*WA-FIELD1 = 'B'.WA-FIELD2 = 'b'.APPEND WA TO IT."Delete
*WA-FIELD1 = 'P'.WA-FIELD2 = 'x'.APPEND WA TO IT.

SORT IT ASCENDING.

APPEND LINES OF IT[] TO IT1[].

WRITE:/'Before deleting Unique records'.
WRITE:/'------------------------------'.

LOOP AT IT[] INTO WA.
WRITE:/ WA-FIELD1,WA-FIELD2.
ENDLOOP.

DELETE ADJACENT DUPLICATES FROM IT1[] COMPARING ALL FIELDS.

LOOP AT IT1[] INTO WA1.
CLEAR COUNT.
LOOP AT IT[] INTO WA WHERE FIELD1 EQ WA1-FIELD1 AND FIELD2 EQ WA1-FIELD2. "Fields to compare uniqueness
ADD 1 TO COUNT.
CHECK COUNT EQ 2.
EXIT.
ENDLOOP.
CHECK COUNT EQ 1.
DELETE IT[] WHERE FIELD1 EQ WA1-FIELD1 AND FIELD2 EQ WA-FIELD2.
ENDLOOP.

SKIP 1.
WRITE:/'After deleting Unique records'.
WRITE:/'------------------------------'.
delete adjacent duplicates from it[]. "<---Newly added

LOOP AT IT[] INTO WA.
WRITE:/ WA-FIELD1,WA-FIELD2.
ENDLOOP.

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Normally how many and what files get created when a transaction program is written?

545


how to combine the transparent table with cluster table.

1092


What is locking? : abap data dictionary

617


how to use the xk01 in realtime.can it apply the others. how it it will goes to first page and next page.

1715


What is the process to enhance the Infotype

2879






Can you delete data element, which is being used by table fields?

793


How to load data from ms excel sheet to sap by using bdc method ? : abap bdc

716


What is primary index?

530


What is the difference between open_form and close_form?

613


Can a domain, assigned to a data element be changed? : abap data dictionary

540


the problem is that , while i am undergoing with my practice session, i am creating too many new programs.they are occupying much space in my hard-disk. how to delete un-necessary programs completely from my data- base........... plz help me with this .....

1559


What is sap abap tables?

616


If I forgot some command in sap script e.g.: Suppress zero display – how to do find it?

557


What are the advantages of logical databases?

614


WHY CLUSTER TABLE CALLED AS CLUSTER TABLE.

1630