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

Delete duplicates???

Former Member
0 Likes
1,271

Dear All,

I have one ITAB with content



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

I have one more itab with content



1 
2
3
4
5
6
7
8
9
10

Now, I want my final itab with


11
12
13
14
15
16
17
18
19
20

How can I do this without using loop statement ?

As of now I have both the tables data in one final tab.

Now, I've to delete the duplicates and originals which are having duplicates from this final table.

Any clues ?

FYI...


TYPES: BEGIN OF ty_tab,
        field1 TYPE char50,
       END OF ty_tab.

DATA: it_tab1  TYPE STANDARD TABLE OF ty_tab,
      it_tab2  TYPE STANDARD TABLE OF ty_tab,
      it_final TYPE STANDARD TABLE OF ty_tab.

DATA: lv_fname TYPE string.
      Data: r_field1 like RSDSSELOPT.

PARAMETERS: p_file1 TYPE rlgrap-filename,
            p_file2 TYPE rlgrap-filename.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file2.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file2.
  
r_field1-sign = 'I'.
  

START-OF-SELECTION.

  IF p_file1 IS NOT INITIAL.

    CLEAR lv_fname.
    lv_fname = p_file1.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = lv_fname
*   FILETYPE                      = 'ASC'
      TABLES
        data_tab                      = it_tab1
             .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.

  IF p_file2 IS NOT INITIAL.
    CLEAR lv_fname.
    lv_fname = p_file2.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = lv_fname
*   FILETYPE                      = 'ASC'
      TABLES
        data_tab                      = it_tab2
             .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.

  SORT: it_tab1,it_tab2.

  APPEND: LINES OF it_tab1 TO it_final,
          LINES OF it_tab2 TO it_final.

  SORT it_final by field1.
  " DELETE originals and duplicates with duplicates  ?????

* Download
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
*     BIN_FILESIZE                    =
      filename                        = 'C:\Temp\File1.txt'
    TABLES
      data_tab                        = it_final
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

Regards,

Deepu.K

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,237

Hi use delete adjacent duplicates to delete the duplicates, and then use delete with index to delete the originals. You can do it easily with loop statement. Dont know why you have this restriction. Orelse you have to have some extra field in internal table to mark duplicates and delete the internal table where field = 'X'.

10 REPLIES 10
Read only

Former Member
0 Likes
1,237

Hi,

DELETE ADJACENT DUPLICATES FROM ITAB COMPARING .... --> YOUR FIELD.

REGARDS,

R K.

Read only

former_member156446
Active Contributor
0 Likes
1,237
APPEND: LINES OF it_tab1 TO it_final,
          LINES OF it_tab2 TO it_final.
 
  SORT it_final by field1.
delete ADJACENT duplicates from it_final comparing field1.
Read only

0 Likes
1,237

Delete adjacent duplicates will delete only the duplicates but i want the originals also to be deleted.

Hope I'm clear !!!!

Read only

0 Likes
1,237
loop at itab.

read table jtab where f1 = itab-f1.
if sy-subrc eq 0.

delete itab.

endif.

endloop.
Read only

Former Member
0 Likes
1,237

If both of the itabs have the same structure, append the lines of one itab to another and then use the delete duplicate statement, else there is no way but to loop and compare.

regards,

Advait

Read only

Former Member
0 Likes
1,237

HI,

do in this manner it will solve your problem:

1) sort final tab

2) delete adjacent duplicates from final tab comparing field name

3) delete the rows 1 to 10 using index from final tab

syntax: DELETE <itab> [FROM <n1>] [TO <n2>]

all lines between <n1> and <n2> are deleted

hope it will help you

regards

rahul

Read only

Former Member
0 Likes
1,238

Hi use delete adjacent duplicates to delete the duplicates, and then use delete with index to delete the originals. You can do it easily with loop statement. Dont know why you have this restriction. Orelse you have to have some extra field in internal table to mark duplicates and delete the internal table where field = 'X'.

Read only

Former Member
0 Likes
1,237

suppose the first table is itab1 and second is itab2 with header and fields are f1 in both tables..

data: index type i,
loop at itab1.
  index = sy-tabix.
  read itab2 with key f1 = itab1-f1.
  if sy-subrc eq 0.
    delete itab1 index index.
  endif.
endloop.

Hope this satisfies your requirement.

Regards,

Lalit Mohan Gupta.

Read only

Former Member
0 Likes
1,237

suppose the first table is itab1 and second is itab2 with header and fields are f1 in both tables..

Loop at itab2.

delete itab1 where field = itab2-field.

endloop.

Kiran

Read only

Former Member
0 Likes
1,237

Hi,

Without any loop statement you may need to define 2 range like internal tables IR_TAB1 and IR_TAB2 corresponding to IT_TAB1 and IT_TAB2 and put entries of IT* to IR* (a function module for that ???) then do this.

DELETE it_final where <fieldvalue> IN ir_tab1 and <fieldvalue> IN ir_tab2.

This does not fully answer to your question but doing so may help you to find a way to solve your problem.

Issa