To find the duplicate record in internal table

Hi,
i have a requirement to fine the duplicate record with 3 fields.
i am getting a flat file with 15 fields  .
i need to check the duplaicate records of  3 fields . if i get any 2nd same record of 3 fields , the records will go to other internal table.
for ex :
1. aaa  bbb ccc ddd  eee  fff  ggg   hhh
2. aaa  bbb ccf  dde edd  ffg ggh   hhj
3. aaa  bbb cce ddd  ees ffh  ggu  hhk
in that 1st record and 3rd record are same (aaa bbb ddd)
i need to find 3rd record
please help me
regrards
srinivasu

hi,
itab2[] = itab1[].
sort itab1 by f1 f2 f3.
sort itab2 by f1 f2 f3.
delete itab2 index 1.   "to delete the first record in itab2.
loop at itab1 into ws_itab1.
  loop at itab2 into ws_itab2.
   if ws_itab1-f1 = ws_itab2-f1 and
     ws_itab1-f2 = ws_itab2-f2 and
    ws_itab1-f3 = ws_itab2-f3.
     ws_itab3 = ws_itab2.
     append ws_itab3 into itab3.   "Third internal table.
   endif.
endloop.
delete itab2 index 1.   
endloop.
ITAB3 will have all the duplicate records.
Regards,
Subramanian

Similar Messages

  • How to find the longest record in a table?

    Hello,
    Is there a function to find the longest record in a table? Or is there a data dictionary that would tell you which record contains the longest data?
    I have a table with five columns and one million records. I want to find the record (5 columns combined) with the longest data. Thank you.

    Dear watson2000!
    The function "VSIZE" tells you the number of bytes in the internal representation of a column which means the size of a value within a column. An example of vsize can be found here:
    [http://www.adp-gmbh.ch/ora/sql/vsize.html]
    So I think you should try it with this query to get the size of the longest record:
    SELECT MAX(VSIZE(column1)) +
           MAX(VSIZE(column2))  +
           MAX(VSIZE(column3))  +
           MAX(VSIZE(column4))  +
           MAX(VSIZE(column5)) AS "Maximum Row"
    FROM your_table;To identify the longest record try like this:
    SELECT rowid
    FROM   your_table
    GROUP BY rowid
    HAVING  (MAX(VSIZE(column1)) +
             MAX(VSIZE(column2)) +
             MAX(VSIZE(column3)) +
             MAX(VSIZE(column4)) +
             MAX(VSIZE(column5))) = (SELECT MAX(VSIZE(column1)) +
                                          MAX(VSIZE(column2))  +
                                          MAX(VSIZE(column3))  +
                                          MAX(VSIZE(column4))  +
                                          MAX(VSIZE(column5))
                                   FROM your_table;)I hope that these two queries could be of help to you.
    yours sincerely
    Florian W.
    Edited by: Florian W. on 23.04.2009 20:53

  • How to delete the duplicate records in a table without promary key

    I have a table that contains around 1 million records and there is no promary key or auto number coulums. I need to delete the duplicate records from this table. what is the simple effective way to do this.

    Please see this link:
    Remove duplicate records ...
    sqldevelop.wordpress.com

  • To delete duplicate records from internal table

    hi friends,
    i have to delete records from internal table based on following criterion.
    total fields are 7.
    out of which  if 4 fields are same and 5th field is different,then both records must be deleted.
    in case all five fields are same,the program should do nothing.
    for example.
    if there are 3 records as follows
    a1 b1 c1 d1 e1 f g
    a1 b1 c1 d1 e2 w r
    a1 b1 c1 d1 e1 j l
    then first two records should be deleted as four fields are same but fifth(e) field differs.
    but third record should remain as it is evenif first five fields are same for first and third record.
    values of last two fields need not to be consider for deleting the records.

    LOOP AT ITAB.
      V_FILED5 = ITAB-F5. "to compare later
      V_TABIX = SY-TABIX. "used to delete if condition not matches
      READ TABLE ITAB WITH KEY F1 = ITAB-F1
                               F2 = ITAB-F2
                               F3 = ITAB-F3
                               F4 = ITAB-F4.
      IF SY-SUBRC = 0.
        IF ITAB-F5 <> V_FIELD5.
    *--both the records to be deleted,as Field5 is different.
          DELETE ITAB INDEX SY-TABIX. "deletes that record
          DELETE ITAB INDEX V_TABIX. "deletes the current record
        ENDIF.
      ENDIF.
    ENDLOOP.
    Message was edited by: Srikanth Kidambi
    added comments
    Message was edited by: Srikanth Kidambi

  • Duplicate records in Internal table

    Hi All,
    I want to find out the duplicate entry in the internal table. I have used,
    Delete Adjacent duplicates from itab.
    It is straight away deleting the record.
    I want the user to correct that duplicate record.
    May be some error message.
    I have tried, with read,
    Read table itab with key bzirk = itab-bzirk vkorg = itab-vkorg kunnr = itab-kunnr
    matnr = itab-matnr comparing bzirk vkorg kunnr matnr.
    But it's giving sy-subrc = 0 for the first record also.
    Even, I have tried like, but it's giving syntax error.
    Loop at itab where bzirk = itab-bzirk vkorg = itab-vkorg kunnr = itab-kunnr
    matnr = itab-matnr.
    Endloop.
    Any method in case on Table control entries.
    Thanks & Regards,
    Kalyan Chandramouli
    SAP Consultant

    Hi,
    Create a new internal table and assign the all the records of itab1 to itab2.
    1.Sort Itab2.
    2.delete adjacent duplicates.
    3. loop at itab2.
         loop at itab1 where <conditon you want....>
         count = count + 1.
         endloop.
          if count GT 1.
            append the iatb2 records for user correction....
          endif.
       endloop.
    If the hint is useful… Say thanks by reward….
    Regards,
    Prabhu Rajesh

  • Find the difference between two internal table

    how can i see the difference between two interal tables?
    The requirement is as follows
    1. We have a transparent table, which stores the employee data with EMP ID as key.
    2. We load the transp table data into a interal table (B).
    3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).
    Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).
    We want to do followign things
    I = A - B
    D = B - A
    Both A and B will have around 40k records. Hence we are trying to avoid the looping.
    Please suggest the best option for us.
    Thank you in advance.
    Raghavendra

    >
    RAGHAV URAL wrote:
    > how can i see the difference between two interal tables?
    > The requirement is as follows
    >
    > 1. We have a transparent table, which stores the employee data with EMP ID as key.
    > 2. We load the transp table data into a interal table (B).
    > 3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).
    >
    > Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).
    >
    > We want to do followign things
    > I = A - B
    > D = B - A
    >
    > Both A and B will have around 40k records. Hence we are trying to avoid the looping.
    >
    > Please suggest the best option for us.
    >
    > Thank you in advance.
    > Raghavendra
    Hi Raghavendra,
      Currently as of my knowledge, these operations are only possible through LOOPs. But LOOPign can be really fast here if you properly utilize the SORTING, READ with BINARY SEARCH and FIELD-SYMBOLS usage. I would say:-
    Steps for Insert:-
    SORT: A, B.
    LOOP AT A ASSIGNING <WA_A>.
      READ TABLE B WITH TABLE KEY key = <WA_A>-key BINARY SEARCH.
      IF SY-SUBRC NE 0.
        APPEND <WA_A> TO I.
      ENDIF.
    ENDLOOP.
    Steps for Delete:-
    SORT: A, B.
    LOOP AT B ASSIGNING <WA_B>.
      READ TABLE A WITH TABLE KEY key = <WA_B>-key BINARY SEARCH.
      IF SY-SUBRC NE 0.
        APPEND <WA_B> TO D.
      ENDIF.
    ENDLOOP.
    Regards,
    Ravi.

  • How to find the duplicate in the table

    i have a table with the 3 columns
    table name - employee
    empcode firstname lastname
    123 xyz pk
    456 yzz pk
    101 kkk jk
    ALTER TABLE employee
    ADD (CONSTRAINT employee_PK PRIMARY KEY
    (empcode , firstname , lastname))
    all the three columns make as porimary key, we are migrating the data there are issues with the data as the cobination of all the three resulting in duplicate, the last column is expected to have the duplicates but first two columns will not have the duplicate and one full row in the table (combintation will not have duplicates)
    need a query find the duplicates for the full row validation

    Assuming that there may be other columns in the table;
    with t as (
      select 123 empcode, 'xyz' firstname, 'pk' lastname, 10 col4 from dual union all
      select 456, 'yzz', 'pk', 20 from dual union all
      select 456, 'yzz', 'pk', 30 from dual union all
      select 101, 'kkk', 'jk', 40 from dual)
    select empcode, firstname, lastname, col4
    from (select t.*,
                 count(*) over(partition by empcode, firstname, lastname) num_rows
          from t)
    where num_rows > 1;
       EMPCODE FIRSTNAME LASTNAME       COL4
           456 yzz       pk               30
           456 yzz       pk               20

  • How to find the unmatched records between the two tables?

    We have to tables in SQL Server database.
    But unable to find the unmatched record betwwen these two tables.
    There 12 records are unmatched. But unable to get those records.
    I am using the below sql:
    select c1,c2,c3,c4,c5,c6 from Table1
    except select c1,c2,c3,c4,c5,c6 from Table2
    Please help. Thanks in advance.

    Hi knra,
    Please try the following codes:
    select c1,c2,c3,c4,c5,c6 from Table1 t1
    where not exists
    (select * from Table2 t2
    where t1.c1= t2.c1
    and t1.c2= t2.c2
    and t1.c3= t2.c3
    and t1.c4= t2.c4
    and t1.c5= t2.c5
    and t1.c6= t2.c6)
    Best Regards,
    Allen Li
    Allen Li
    TechNet Community Support
    This is what I would've said, but it would make life much easier for you if you have a reference or ID for each entry, this is why we use keys.

  • How to find out duplicate record contained in a flat file

    Hi Experts,
    For my project I have written a program for flat file upload.
    Requirement 1
    In the flat file there may be some duplicate record like:
    Field1   Field2
    11        test1
    11        test2
    12        test3
    13        test4
    Field1 is primary key.
    Can you please let me know how I can find out the duplicate record.
    Requirement 2
    The flat file contains the header row as shown above
    Field1   Field2
    How our program can skip this record and start reading / inserting records from row no 2 ie
    11        test1
    onwards.
    Thanks
    S
    FORM upload1.
    DATA : wf_title TYPE string,
    lt_filetab TYPE filetable,
    l_separator TYPE char01,
    l_action TYPE i,
    l_count TYPE i,
    ls_filetab TYPE file_table,
    wf_delemt TYPE rollname,
    wa_fieldcat TYPE lvc_s_fcat,
    tb_fieldcat TYPE lvc_t_fcat,
    rows_read TYPE i,
    p_error TYPE char01,
    l_file TYPE string.
    DATA: wf_object(30) TYPE c,
    wf_tablnm TYPE rsdchkview.
    wf_object = 'myprogram'.
    DATA i TYPE i.
    DATA:
    lr_mdmt TYPE REF TO cl_rsdmd_mdmt,
    lr_mdmtr TYPE REF TO cl_rsdmd_mdmtr,
    lt_idocstate TYPE rsarr_t_idocstate,
    lv_subrc TYPE sysubrc.
    TYPES : BEGIN OF test_struc,
    /bic/myprogram TYPE /bic/oimyprogram,
    txtmd TYPE rstxtmd,
    END OF test_struc.
    DATA : tb_assum TYPE TABLE OF /bic/pmyprogram.
    DATA: wa_ztext TYPE /bic/tmyprogram,
    myprogram_temp TYPE ziott_assum,
    wa_myprogram TYPE /bic/pmyprogram.
    DATA : test_upload TYPE STANDARD TABLE OF test_struc,
    wa2 TYPE test_struc.
    DATA : wa_test_upload TYPE test_struc,
    ztable_data TYPE TABLE OF /bic/pmyprogram,
    ztable_text TYPE TABLE OF /bic/tmyprogram,
    wa_upld_text TYPE /bic/tmyprogram,
    wa_upld_data TYPE /bic/pmyprogram,
    t_assum TYPE ziott_assum.
    DATA : wa1 LIKE test_upload.
    wf_title = text-026.
    CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
    window_title = wf_title
    default_extension = 'txt'
    file_filter = 'Tab delimited Text Files (*.txt)'
    CHANGING
    file_table = lt_filetab
    rc = l_count
    user_action = l_action
    EXCEPTIONS
    file_open_dialog_failed = 1
    cntl_error = 2
    OTHERS = 3. "#EC NOTEXT
    IF sy-subrc 0.
    EXIT.
    ENDIF.
    LOOP AT lt_filetab INTO ls_filetab.
    l_file = ls_filetab.
    ENDLOOP.
    CHECK l_action = 0.
    IF l_file IS INITIAL.
    EXIT.
    ENDIF.
    l_separator = 'X'.
    wa_fieldcat-fieldname = 'test'.
    wa_fieldcat-dd_roll = wf_delemt.
    APPEND wa_fieldcat TO tb_fieldcat.
    CALL FUNCTION 'MESSAGES_INITIALIZE'.
    CLEAR wa_test_upload.
    Upload file from front-end (PC)
    File format is tab-delimited ASCII
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = l_file
    has_field_separator = l_separator
    TABLES
    data_tab = i_mara
    data_tab = test_upload
    EXCEPTIONS
    file_open_error = 1
    file_read_error = 2
    no_batch = 3
    gui_refuse_filetransfer = 4
    invalid_type = 5
    no_authority = 6
    unknown_error = 7
    bad_data_format = 8
    header_not_allowed = 9
    separator_not_allowed = 10
    header_too_long = 11
    unknown_dp_error = 12
    access_denied = 13
    dp_out_of_memory = 14
    disk_full = 15
    dp_timeout = 16
    OTHERS = 17.
    IF sy-subrc 0.
    EXIT.
    ELSE.
    CALL FUNCTION 'MESSAGES_INITIALIZE'.
    IF test_upload IS NOT INITIAL.
    DESCRIBE TABLE test_upload LINES rows_read.
    CLEAR : wa_test_upload,wa_upld_data.
    LOOP AT test_upload INTO wa_test_upload.
    CLEAR : p_error.
    rows_read = sy-tabix.
    IF wa_test_upload-/bic/myprogram IS INITIAL.
    p_error = 'X'.
    MESSAGE s153 WITH wa_test_upload-/bic/myprogram sy-tabix.
    CONTINUE.
    ELSE.
    TRANSLATE wa_test_upload-/bic/myprogram TO UPPER CASE.
    wa_upld_text-txtmd = wa_test_upload-txtmd.
    wa_upld_text-txtsh = wa_test_upload-txtmd.
    wa_upld_text-langu = sy-langu.
    wa_upld_data-chrt_accts = 'xyz1'.
    wa_upld_data-co_area = '12'.
    wa_upld_data-/bic/zxyzbcsg = 'Iy'.
    wa_upld_data-objvers = 'A'.
    wa_upld_data-changed = 'I'.
    wa_upld_data-/bic/zass_mdl = 'rrr'.
    wa_upld_data-/bic/zass_typ = 'I'.
    wa_upld_data-/bic/zdriver = 'yyy'.
    wa_upld_text-langu = sy-langu.
    MOVE-CORRESPONDING wa_test_upload TO wa_upld_data.
    MOVE-CORRESPONDING wa_test_upload TO wa_upld_text.
    APPEND wa_upld_data TO ztable_data.
    APPEND wa_upld_text TO ztable_text.
    ENDIF.
    ENDLOOP.
    DELETE ADJACENT DUPLICATES FROM ztable_data.
    DELETE ADJACENT DUPLICATES FROM ztable_text.
    IF ztable_data IS NOT INITIAL.
    CALL METHOD cl_rsdmd_mdmt=>factory
    EXPORTING
    i_chabasnm = 'myprogram'
    IMPORTING
    e_r_mdmt = lr_mdmt
    EXCEPTIONS
    invalid_iobjnm = 1
    OTHERS = 2.
    CALL FUNCTION 'MESSAGES_INITIALIZE'.
    **Lock the Infoobject to update
    CALL FUNCTION 'RSDG_IOBJ_ENQUEUE'
    EXPORTING
    i_objnm = wf_object
    i_scope = '1'
    i_msgty = rs_c_error
    EXCEPTIONS
    foreign_lock = 1
    sys_failure = 2.
    IF sy-subrc = 1.
    MESSAGE i107(zddd_rr) WITH wf_object sy-msgv2.
    EXIT.
    ELSEIF sy-subrc = 2.
    MESSAGE i108(zddd_rr) WITH wf_object.
    EXIT.
    ENDIF.
    *****Update Master Table
    IF ztable_data IS NOT INITIAL.
    CALL FUNCTION 'RSDMD_WRITE_ATTRIBUTES_TEXTS'
    EXPORTING
    i_iobjnm = 'myprogram'
    i_tabclass = 'M'
    I_T_ATTR = lt_attr
    TABLES
    i_t_table = ztable_data
    EXCEPTIONS
    attribute_name_error = 1
    iobj_not_found = 2
    generate_program_error = 3
    OTHERS = 4.
    IF sy-subrc 0.
    CALL FUNCTION 'MESSAGE_STORE'
    EXPORTING
    arbgb = 'zddd_rr'
    msgty = 'E'
    txtnr = '054'
    msgv1 = text-033
    EXCEPTIONS
    OTHERS = 3.
    MESSAGE e054(zddd_rr) WITH 'myprogram'.
    ELSE.
    CALL FUNCTION 'MESSAGE_STORE'
    EXPORTING
    arbgb = 'zddd_rr'
    msgty = 'S'
    txtnr = '053'
    msgv1 = text-033
    EXCEPTIONS
    OTHERS = 3.
    ENDIF.
    *endif.
    *****update Text Table
    IF ztable_text IS NOT INITIAL.
    CALL FUNCTION 'RSDMD_WRITE_ATTRIBUTES_TEXTS'
    EXPORTING
    i_iobjnm = 'myprogram'
    i_tabclass = 'T'
    TABLES
    i_t_table = ztable_text
    EXCEPTIONS
    attribute_name_error = 1
    iobj_not_found = 2
    generate_program_error = 3
    OTHERS = 4.
    IF sy-subrc 0.
    CALL FUNCTION 'MESSAGE_STORE'
    EXPORTING
    arbgb = 'zddd_rr'
    msgty = 'E'
    txtnr = '055'
    msgv1 = text-033
    EXCEPTIONS
    OTHERS = 3.
    ENDIF.
    ENDIF.
    ELSE.
    MESSAGE s178(zddd_rr).
    ENDIF.
    ENDIF.
    COMMIT WORK.
    CALL FUNCTION 'RSD_CHKTAB_GET_FOR_CHA_BAS'
    EXPORTING
    i_chabasnm = 'myprogram'
    IMPORTING
    e_chktab = wf_tablnm
    EXCEPTIONS
    name_error = 1.
    IF sy-subrc 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ****Release locks on Infoobject
    CALL FUNCTION 'RSDG_IOBJ_DEQUEUE'
    EXPORTING
    i_objnm = 'myprogram'
    i_scope = '1'.
    ENDIF.
    ENDIF.
    PERFORM data_selection .
    PERFORM update_alv_grid_display.
    CALL FUNCTION 'MESSAGES_SHOW'.
    ENDFORM.

    Can you please let me know how I can find out the duplicate record.
    you need to split the records from flat file structure into your internal table ans use a delete ADJACENT duplicates comparing fields
    split flat_str into wa_f1 wa_f2 wa_f2 at tab_space.

  • Duplicate Entries in Internal table

    Hi All,
    As per my requirement
    1. The internal table is the input.
    2. I need the duplicate records of the internal table with the combination of 2 key fields.
    3. I should not use SORT because i need the index number in order as per in the table .
    EX : Take Table MSEG.
    Take key fields as MBLNR and WERKS.
    I want the duplicate records of the combination of these 2 key fields.
    The *Index Number * should not to be changed as per the table entry. ( So i avoided sorting the internal table)
    Kindly give some solutions.
    Thanks,
    Pradeep.
    Moderator message : Duplicate post locked,follow forum Rules of Engagement. Thread locked.
    Edited by: Vinod Kumar on Mar 1, 2012 4:59 PM

    Hi Pradeep,
    Try this...
    first you copy your internal table to another temporary table of same type.
    itab_temp[] = itab[].
    sort itab_temp[].
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING MBLNR WERKS.
    LOOP AT ITAB_TEMP INTO WA_ITAB1.
    DO.
        READ TABLE ITAB INTO WA_ITAB2 WITH KEY MBLNR = WA_ITAB1-MBLNR AND  WERKS = WA_ITAB1-WERKS.
        IF SY-SUBRC EQ 0.
             APPEND WA_ITAB2 TO ITAB_NEW.
        ELSE.
             EXIT.
        ENDIF.
    ENDDO.
    ENDLOOP.
    you may get the duplicate records in itab_new.

  • Any option is there to find the error record in loop for huge amount of rec

    Hi Guru's,
    In our production system we got a error. While debugging we found one of our loop getting 1 lakh records. One of the record from the internal table having some wrong values because of that its giving a error message. But we are not getting any proper message.
    Now our problem is its very difficult to debug all the records one by one. Even its not possible to give Watchpoint. bze in what situations its giving this error that also not predictable. So how to find the error record?
    Kindly suggest.
    Ananadhan

    Need a lot more info.
    To start with is this CR Designer or some other product?
    I suspect it's classic SAP products like Business One etc., if so please mark as answered and post your question int the correct forum.
    Thank you
    Don

  • Comparing Duplicates in an internal table

    Hi ,
    Can anyone let me know , how to compare two duplicate records in an internal table.
    is there any Function Module or Command for it.
    Please let me know .
    Thank you ,
    Regards,
    Roby

    Check this logic works:
    REPORT  yspra_sample89.
    TYPES: BEGIN OF ty_data,
              column1 TYPE char10,
              column2 TYPE char10,
           END OF ty_data.
    DATA: i_data TYPE ty_data OCCURS 0 WITH HEADER LINE,
          i_data_repeat TYPE ty_data OCCURS 0 WITH HEADER LINE.
    DATA: wa_data TYPE ty_data,
          wa_data1 TYPE ty_data.
    DATA: lines TYPE sy-tabix.
    i_data-column1 = '10'.
    i_data-column2 = '20'.
    APPEND i_data.
    i_data-column1 = '10'.
    i_data-column2 = '20'.
    APPEND i_data.
    i_data-column1 = '10'.
    i_data-column2 = '20'.
    APPEND i_data.
    i_data-column1 = '10'.
    i_data-column2 = '20'.
    APPEND i_data.
    SORT i_data BY column1 column2.
    LOOP AT i_data INTO wa_data.
      lines = sy-tabix + 1.
      READ TABLE i_data INTO wa_data1 INDEX lines.
      IF sy-subrc = 0.
        IF wa_data = wa_data1.
          APPEND wa_data1 TO i_data_repeat.
        ENDIF.
      ENDIF.
      CLEAR: lines, wa_data, wa_data1.
    ENDLOOP.
    LOOP AT i_data_repeat.
      WRITE: / i_data_repeat-column1 , i_data_repeat-column2.
    ENDLOOP.
    Sort ur table first and read the next row if it duplicate append it to some internal. In this way u can take all the duplicate records.
    Regards,
    Prakash.

  • Counting duplicate records in a table

    Hi,
    I have to display duplicate records in a table,but the table name and column should be passed dynamically(In procedure). Please let me know the query for this.

    Try this one, is used to find the duplicate value from table
    Type: I
    SELECT * FROM employees e1 WHERE rowid> (SELECT min(rowid)
    FROM employees e2 WHERE e1.department_id=e2.department_id);
    Type: II
    SELECT * FROM my_table t1 WHERE EXISTS (SELECT 'x' FROM my_table t2
    WHERE t2.key_value1 = t1.key_value1
    AND t2.key_value2 = t1.key_value2
    AND t2.rowid > t1.rowid);
    Type: III
    SELECT count(*), empn FROM empmast_dum
    GROUP BY empn HAVING count(*) >1 ORDER BY empn;
    Type: IV
    SELECT dep, name,net,RANK() OVER (PARTITION BY dep ORDER BY net) rank
    FROM empmast_dump
    WHERE dep=04;
    Type: V
    SELECT empn FROM empmast_dump
    WHERE empn NOT IN(SELECT MIN(empn)
    FROM empmast_dump GROUP BY NAME;
    I have to display duplicate records in a
    table,but the table name and column should be passed
    dynamically(In procedure). Please let me know the
    query for this.When you need to pass table name dynamically in your procedure ,
    just enter table name as substitution variable or bind variable, if u want to know about
    this, read here
    venki
    http://venki-hb.blogspot.com/2008/02/basic-sql-query-tips.html

  • Duplicate records in a table

    i need to find duplicate records in a table that have the same name but a different id number.
    only fields i am using is the id, first name, last name, middle name
    any help would be great
    thanks

    Well, to just find the duplicate names, you can:
    select first_name, middle_name, last_name, count(*)
      from t
    group by first_name, middle_name, last_name
    having count(*) > 1;If you want to find the ids that are linked to these dupes, then:
    select *
      from t
    where (first_name, middle_name, last_name) in
       (select first_name, middle_name, last_name
          from t
         group by first_name, middle_name, last_name
        having count(*) > 1);

  • Duplicate Entries in Internal Tables

    Hallo Friends,
    It Would be nice if some one let me know, if there is a way in ABAP to select the duplicates records in an internal tables.
    Lets say I have two internal tabels, itabA have following structure:
    BNAME  |          WORKAREA   |   ROLES
    abc |             wa1 |          ro1
    cde  |            wa1 |          ro1
    cde  |      wa3 |          rol..
    abc  |      wa2 |          rol2
    xyz |       wa1 |          rol3
    xyz  |      wa3  |         rol2..
    the itabB have the following structure:
    WORKAREA |      ROLES|  
    wa1   |         rol1
    wa2  |        rol1
    wa3  |          rol1
    wa4  |          rol1
    Now problem is, I need to select the common WorkAreas from itabA ( which is commom in all BNAME ) in above example it will be workarea wa1. as it is commom in all i.e ( abc ,cde and xyz). I need to select this commom workarea, and then mark it with some flage in itabB ( to display that this workarea is common among the users...)
    Would be nice if some one let me know, is there any way I can select the duplicate rows in an internal table or I have to go one by one and then do some kind of comparision.
    Many thanks,
    Thx in advance....
    Haider

    Hi marek,
    below information might help you.
    The first criterion for comparing internal tables is the number of lines they contain. The more lines an internal table contains, the larger it is. If two internal tables contain the same number of lines, they are compared line by line, component by component. If components of the table lines are themselves internal tables, they are compared recursively. If you are testing internal tables for anything other than equality, the comparison stops when it reaches the first pair of components that are unequal, and returns the corresponding result.
    DATA: BEGIN OF LINE,
    COL1 TYPE I,
    COL2 TYPE I,
    END OF LINE.
    DATA: ITAB LIKE TABLE OF LINE,
    JTAB LIKE TABLE OF LINE.
    DO 3 TIMES.
    LINE-COL1 = SY-INDEX.
    LINE-COL2 = SY-INDEX ** 2.
      APPEND LINE TO ITAB.
    ENDDO.
    MOVE ITAB TO JTAB.
    LINE-COL1 = 10. LINE-COL2 = 20.
    APPEND LINE TO ITAB.
    IF ITAB GT JTAB.
    WRITE / 'ITAB GT JTAB'.
    ENDIF.
    APPEND LINE TO JTAB.
    IF ITAB EQ JTAB.
    WRITE / 'ITAB EQ JTAB'.
    ENDIF.
    LINE-COL1 = 30. LINE-COL2 = 80.
    APPEND LINE TO ITAB.
    IF JTAB LE ITAB.
    WRITE / 'JTAB LE ITAB'.
    ENDIF.
    LINE-COL1 = 50. LINE-COL2 = 60.
    APPEND LINE TO JTAB.
    IF ITAB NE JTAB.
    WRITE / 'ITAB NE JTAB'.
    ENDIF.
    IF ITAB LT JTAB.
    WRITE / 'ITAB LT JTAB'.
    ENDIF.
    The output is:
    ITAB GT JTAB
    ITAB EQ JTAB
    JTAB LE ITAB
    ITAB NE JTAB
    ITAB LT JTAB
    This example creates two standard tables, ITAB and JTAB. ITAB is filled with 3 lines and copied to JTAB. Then, another line is appended to ITAB and the first logical expression tests whether ITAB is greater than JTAB. After appending the same line to JTAB, the second logical expression tests whether both tables are equal. Then, another line is appended to ITAB and the third logical expressions tests whether JTAB is less than or equal to ITAB. Next, another line is appended to JTAB. Its contents are unequal to the contents of the last line of ITAB. The next logical expressions test whether ITAB is not equal to JTAB. The first table field whose contents are different in ITAB and JTAB is COL1 in the last line of the table: 30 in ITAB and 50 in JTAB. Therefore, in the last logical expression, ITAB is less than JTAB.
    reward with points and close the thread if your question is solved
    regards,
    venu.

Maybe you are looking for