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

bdc

Former Member
0 Likes
427

hi,

in my flat file am having duplicate entries ..

so i want to eliminate that duplicate entries using any method..

send me sample code asap.

advance thanks

3 REPLIES 3
Read only

Former Member
0 Likes
405

Hi,

Once if you get all the records into one internal table, you have to sort the internal table and use the DELETE statement so that you delete the all duplicate records.

reward with points if it is useful

Regards,

Vijay

Read only

Former Member
0 Likes
405

<b>Deleting Adjacent Duplicate Entries</b>

To delete adjacent duplicate entries use the following statement:

DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>

[COMPARING <f1> <f 2> ...

|ALL FIELDS].

The system deletes all adjacent duplicate entries from the internal table <itab>. Entries are duplicate if they fulfill one of the following compare criteria:

  • Without the COMPARING addition, the contents of the key fields of the table must be identical in both lines.

  • If you use the addition COMPARING <f1> <f 2> ... the contents of the specified fields <f

  • 1 > <f 2 > ... must be identical in both lines. You can also specify a field <f i > dynamically as the contents of a field <n i > in the form (<n i >). If <n i > is empty when the statement is executed, it is ignored. You can restrict the search to partial fields by specifying offset and length. If you use the addition COMPARING ALL FIELDS the contents of all fields of both lines must be identical.

You can use this statement to delete all duplicate entries from an internal table if the table is sorted by the specified compare criterion.

If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4.

Examples

Example

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.

DO 4 TIMES.

LINE-COL1 = SY-INDEX.

LINE-COL2 = SY-INDEX ** 2.

INSERT LINE INTO TABLE ITAB.

ENDDO.

LINE-COL1 = 1.

DELETE TABLE ITAB: FROM LINE,

WITH TABLE KEY COL1 = 3.

LOOP AT ITAB INTO LINE.

WRITE: / LINE-COL1, LINE-COL2.

ENDLOOP.

The output is:

2 4

4 16

The program fills a hashed table with a list of square numbers. The DELETE statement delete the lines from the table where the key field COL1 has the contents 1 or 3.

Example

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE I,

END OF LINE.

DATA ITAB LIKE HASHED TABLE OF LINE WITH UNIQUE KEY COL1.

DO 4 TIMES.

LINE-COL1 = SY-INDEX.

LINE-COL2 = SY-INDEX ** 2.

INSERT LINE INTO TABLE ITAB.

ENDDO.

DELETE ITAB WHERE ( COL2 > 1 ) AND ( COL1 < 4 ).

LOOP AT ITAB INTO LINE.

WRITE: / LINE-COL1, LINE-COL2.

ENDLOOP.

The output is:

1 1

4 16

The program fills a hashed table with a list of square numbers. The DELETE statement deletes the lines of the table where the content of field COL2 is greater than 1 and the content of field COL1 is less than 4.

Example

DATA OFF TYPE I.

DATA: BEGIN OF LINE,

COL1 TYPE I,

COL2 TYPE C,

END OF LINE.

DATA ITAB LIKE STANDARD TABLE OF LINE

WITH NON-UNIQUE KEY COL2.

LINE-COL1 = 1. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

LINE-COL1 = 1. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

LINE-COL1 = 1. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 2. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 3. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 4. LINE-COL2 = 'B'. APPEND LINE TO ITAB.

LINE-COL1 = 5. LINE-COL2 = 'A'. APPEND LINE TO ITAB.

OFF = 0. PERFORM LIST.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.

OFF = 14. PERFORM LIST.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING COL1.

OFF = 28. PERFORM LIST.

DELETE ADJACENT DUPLICATES FROM ITAB.

OFF = 42. PERFORM LIST.

FORM LIST.

SKIP TO LINE 3.

LOOP AT ITAB INTO LINE.

WRITE: AT /OFF LINE-COL1, LINE-COL2.

ENDLOOP.

ENDFORM.

The output is:

1 A 1 A 1 A 1 A

1 A 1 B 2 B 2 B

1 B 2 B 3 B 5 A

2 B 3 B 4 B

3 B 4 B 5 A

4 B 5 A

5 A

The example creates and fills a standard table. Here, the first DELETE statement deletes the second line from ITAB because the second line has the same contents as the first line. The second DELETE statement deletes the second line from the remaining table because the contents of the field COL1 is the same as in the first line. The third DELETE statement deletes the third and fourth line from the remaining table because the contents of the default key field COL2 are the same as on the second line. Although the contents of the default key are the same for the first and the fifth line, the fifth line is not deleted because it is not adjacent to the first line.

also refer

regards,

srinivas

<b>*reward for useful answers*</b>

Read only

varma_narayana
Active Contributor
0 Likes
405

Hi..

First you read the data from Flat file into INTERNAL TABLE .

FM gui_upload (local files)

OPEN DATASET, READ DATASET AND CLOSE DATASET for app server files

Then remove the Duplicate records in ITAB before processing it using BDC.

Sort itab by <fields>.

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING <FIELDS>.

<b>reward if Helpful</b>