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
Normally how many and what files get created when a transaction program is written?
how to combine the transparent table with cluster table.
What is locking? : abap data dictionary
how to use the xk01 in realtime.can it apply the others. how it it will goes to first page and next page.
What is the process to enhance the Infotype
Can you delete data element, which is being used by table fields?
How to load data from ms excel sheet to sap by using bdc method ? : abap bdc
What is primary index?
What is the difference between open_form and close_form?
Can a domain, assigned to a data element be changed? : abap data dictionary
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 .....
What is sap abap tables?
If I forgot some command in sap script e.g.: Suppress zero display – how to do find it?
What are the advantages of logical databases?
WHY CLUSTER TABLE CALLED AS CLUSTER TABLE.