Delete adjacent duplicates how to use in the below select statement

hi i have a problem
i am suing the below select statement
SELECT    a~extno
          a~guid_lclic       " for next select
          e~ctsim
          e~ctsex
*revised spec 3rd
          f~guid_pobj
          f~amnt_flt
          f~amcur
          f~guid_mobj
          e~srvll     "pk
          e~ctsty     "PK
          e~lgreg  "PK
  INTO TABLE gt_sagmeld
  FROM /SAPSLL/LCLIC  as a
  INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
  inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic   " for ccngn1 selection
  inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
                           where   a~extno in s_extno.
  sort gt_sagmeld by guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ.
  delete adjacent duplicates from gt_sagmeld comparing guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ .
now i am confused how to use delete adjacent dupliacate and on which fields
as first table /sal../lclic primary key is guid_lclic
and it is joined to table
legcon by guid_lclci ( not a primary key here)
legcon primary key is guid_legcon
and table 3 legsv by lgreg (pk here)
table 3 has tow more primary key srvll and ctsty also
NOW MY QUESTIO IS TAHT IS I USE ABOVE DELETE ADJACENT STATMENT IT FETCHES 20 LAKH RECORDS
I WANT TO REDUCE IS LET ME KNOW ON WHAT fields i need to use delete adjacen duplicates
or use comparing all fields?
regards
Arora

hi sudha
if u see my select statement is contains four Primary keys
srvll
lgreg
ctsty
guid_lclic
but the next table connected to this table legcon is by guid_pobj and anothe table by guid_mobj
and if i take this gt_sagmeld to another temp table and i find abt 10 lakh uniques guid_pobj
similary 6 lakh guid_mobj so the next slect is hanpering because of this
not COMING TO OUR POINT IF I SORT ONLY BY OUR PRIMARY KEYS NOT TAKING INTO ACCOUNT TEH GUID_POBJ AND GUID_MOBJ
THE ENTRIES ARE VERY LESS BUT IF I TAKE INOT ACCCOUNT IN GT_SAGMELD THE ENTRIES ARE ABT 20 LAKH
SO I AM NOT SURE WHETHER TO TAKNE GUID_POBJ AND GUID_MOBJ INOT ACCOUNT FOR DELECTING ADJACENT DUPLICATES?
HENCE THE QUESTION OF ON WHICH FIRLD DELETE OR COMPARING ALL FIELDS I USE?

Similar Messages

  • How to use SET ID in select statement of SQ02

    Hi,
    I have a infoset, where for one of my Zfield, i have writen a select statement in order to get my ouput.
    if aufk-aufnr = 'XYZ'.
      select sum( FKBTR ) from fmifiit into zfmifiit
      where fikrs = aufk-kokrs
      and fipex IN capex
      and wrttp NE '51'.
    endif.
    For the above statement, i have created (with 10 single values, table name FMCI, field name FIPEX)  a SET id named CAPEX and used with IN operator.
    But when i generating the infoset i am getting error like below
    The IN operator with "CAPEX" is followed neither by an internal table nor by a value list
    I was using IN opeartor for set ids during validation / substitutions, where if i have to validate multiple single values.
    What to do here?
    Regards,
    Srinu

    [OPEN-SQL|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_GENERAL.htm] set of statement, [SELECT|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] statement, [WHERE|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm] addition requires a selection table (type range, [WHERE - IN seltab |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]) of parameter and not a set. We are in Abap here, not in a Customizing screen
    You have to convert the set to a selection table in an ABAP coding before using it in a SELECT statement.
    (Check FM like G_SET_TREE_IMPORT to import definition of set (values and intervals) and map them to a select-table, or ask a developper to perform it, look at G_SET_TREE_IMPORT -> select statement)
    Regards,
    Raymond

  • How to use  'is null' in select statement of ABAP program

    hi,
    I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data.
    SELECT * FROM mara INTO TABLE it_mara
          WHERE volum IS NULL .
    Can anyone resolve this.

    Hi PKB,
    Check the below thread for NULL and Space value in ABAP . It will help you
    NULL and Space value in ABAP
    Regards,
    Pawan

  • [php+mysql] how to use variables in a select statement?

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

    Hi all,
    I'm searching for a way to use a variable in the select
    statement of mysql
    query.
    I have this variable that can contain:
    $var=field_1 field_2 field5
    or
    $var=field3 field4 field8
    so, the variable content is not always the same.
    I would like to filter a table selecting only the columns
    specified by the
    current $var content.
    Is this possible to do something like this?
    $var=field1 field5 field10
    SELECT string_to_array($var)
    FROM mytable
    ORDER BY mysortfield ASC
    Or, is there another way to select columns dynamically?
    Thanks for any suggestion.
    tony

  • How to use anonymous block in select statement

    Hello Experts.
    I have one requirement which i can resolve using anonymous block in plsql. But i want implement it in select query only.
    Database: Oracle 11.2.0
    select count(*) from emp where name='xyz' and sal=50
    if count(*)>0
    then
    select dept,sector from emp where name='xyz' and sal=50
    here i dont have any primary key.
    How can i achieve above using sql query not plsql. Here is one sloution which i have got but its not satisfying above requiremnt as i dont have any primary key columns
    select toll_number from toll_details
    where toll_id =(select toll_id from toll_details where toll_new_id='5263655214' group by toll_id having count(*)>0)
    here toll_id is primary key, so used group by. But how to do this in my above requirement as i dont have primary key.
    Appreciate any help on this.
    Thank you

    897112 wrote:
    Hello Experts.
    I have one requirement which i can resolve using anonymous block in plsql. But i want implement it in select query only.
    Database: Oracle 11.2.0
    select count(*) from emp where name='xyz' and sal=50
    if count(*)>0
    then
    select dept,sector from emp where name='xyz' and sal=50
    here i dont have any primary key.
    How can i achieve above using sql query not plsql. Here is one sloution which i have got but its not satisfying above requiremnt as i dont have any primary key columns
    select toll_number from toll_details
    where toll_id =(select toll_id from toll_details where toll_new_id='5263655214' group by toll_id having count(*)>0)
    here toll_id is primary key, so used group by. But how to do this in my above requirement as i dont have primary key.
    Appreciate any help on this.
    Thank youTry this
    SQL> create table plch_test(id number,name varchar2(20),sal number);
    Table created.
    SQL> insert into plch_test values(1,'XYZ',50);
    1 row created.
    SQL> insert into plch_test values(2,'AAA',100);
    1 row created.
    SQL> insert into plch_test values(3,'BBB',200);
    1 row created.
    SQL> insert into plch_test values(4,'CCC',400);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from plch_test;
            ID NAME                        SAL
             1 XYZ                          50
             2 AAA                         100
             3 BBB                         200
             4 CCC                         400
    SQL> ed
    Wrote file afiedt.buf
      1  select id,name
      2  from plch_test a
      3  where 1=(select count(*) from plch_test b where a.id=b.id)
      4* and id=&id
    SQL> /
    Enter value for id: 2
    old   4: and id=&id
    new   4: and id=2
            ID NAME
             2 AAA
    SQL> /
    Enter value for id: 0
    old   4: and id=&id
    new   4: and id=0
    no rows selectedHope this helps!!!
    Regards,
    Achyut

  • How to use unique values in select queries

    For the a particular variant this select query gives a dump.here matnr and werks have been taken as unique combination for table it_mat_lifnr. i have tried with delete adjacent duplicates but still it is not working.can you suggest me with a possible solution. iam providing you with the  part of code which gives error
    select matnr werks lifnr ebeln
      from eord
      into table it_mat_lifnr
      for all entries in it_mat
      where matnr = it_mat-matnr and
              werks = it_mat-werks and
              vdatu <= sy-datum and
              bdatu >= sy-datum and
             flifn = 'X' or febel = 'X'.

    Hi,
           You can use distinct or delete adjacent duplicate from internal table.
    For ex.,
    select distinct kunnr into table it_kna1 from kna1 where kunnr in s_kunnr.
    or
    select kunnr into table it_kna1 from kna1 where kunnr in s_kunnr.
    sort it_kna1 by kunnr.
    delete adjacent duplicates from it_kna1.
    Thanks and Regards,
    Thirukumaran. R

  • How to use a function in select clause

    hi gems...good evening...
    I want to write a select clause from a function. The scenario is like below:
    function parameters
    CREATE OR REPLACE FUNCTION FUNCTION_DEMO(p_pid IN NUMBER,
    p_bankerNum IN NUMBER,
    p_banker_name IN VARCHAR2,
    p_business_num IN NUMBER,
    p_businesses IN table_typ_businesses)
    return table_typ_bankers
    as .......
    global object and table types
    CREATE OR REPLACE TYPE obj_typ_businesses AS OBJECT (businesses NUMBER);
    CREATE OR REPLACE TYPE table_typ_businesses AS TABLE OF obj_typ_businesses;
    CREATE OR REPLACE TYPE obj_typ_bankers AS OBJECT (banker_num NUMBER(10,0));
    CREATE OR REPLACE TYPE table_typ_bankers IS TABLE OF obj_typ_bankers;
    The select query
    select * from
    table(cast(FUNCTION_DEMO(1,
    2,
    'ALEX',
    2,
    table(cast(select businesses_id from reference_businesses) as table_typ_businesses) as table_typ_bankers)But it is giving error with Missing expression.
    My function is compiled successfully. I just want to make the select query to view the output given by the function i.e the table type "table_typ_bankers".
    Please help...thanks in advance..

    Hi ,
    You can check this and change your code by taking this as an example. I just noted down with simple one input and return as collection type
    and how to use/call it in select statement.
    SQL> CREATE OR REPLACE TYPE obj_typ_businesses AS OBJECT (businesses NUMBER)
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE table_typ_businesses AS TABLE OF obj_typ_businesses
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE obj_typ_bankers AS OBJECT (banker_num NUMBER(10,2))
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE table_typ_bankers IS TABLE OF obj_typ_bankers
      2  /
    Type created.
    /* Now creating a demo function and just focusing on your one input as collection type  */
    SQL> create or replace function f11 ( tab_rec  IN table_typ_businesses)
      2  return table_typ_bankers
      3  is
      4  t_val table_typ_bankers:= table_typ_bankers();
      5  begin
      6        dbms_output.put_line('tab_rec count -'||tab_rec.count);
      7
      8  for i in 1..tab_rec.count
      9              loop
    10               dbms_output.put_line ('tab_rec value ('||i||')'||tab_rec(i).businesses);
    11                       t_val.EXTEND;
    12                    t_val(i) := obj_typ_bankers(tab_rec(i).businesses * 12.50);
    13              end loop;
    14              return t_val;
    15  end;
    16  /
    Function created.
    /* To run your function by a select statement */
    SQL> SELECT * FROM TABLE(f11(table_typ_businesses(obj_typ_businesses(5),
      2                          obj_typ_businesses(12),
      3                                         obj_typ_businesses(18))
      4                                             ) )
      5  /
    BANKER_NUM
          62.5
           150
           225
    tab_rec count -3
    tab_rec value (1)5
    tab_rec value (2)12
    tab_rec value (3)18Hope this will help you... :)
    Thanks!
    Ashutosh

  • How to use 'DELETE ADJACENT DUPLICATES FROM' for deleting as some field

    How to use 'DELETE ADJACENT DUPLICATES FROM' for deleting as some field
    eg:
    I have a inner table ,it contains a field named ast_guid,now,I search ten records,contains some duplicate records in the field of ast_guid.but I can not delete the duplicate records as ast_guid.

    If the type of  inner table is standard table,  you should sort the inner table  by the fields before user 'DELETE ADJACENT DUPLICATES  ', and use COMPARING addtion.
    Edited by: Justin on Jun 28, 2009 9:48 AM

  • Problem using DELETE ADJACENT DUPLICATES with dynamic table

    Hello All,
       In my program i have to delete duplicate records from dynamic table.
    I tried using  DELETE ADJACENT DUPLICATES FROM <DYN_TABLE> COMPARING <fieldname1> <fieldname2> but it fails in syntax check, then i tried like below:
      DATA string type string.
      string = '<fieldname1> <fieldname2>.........'.
      DELETE ADJACENT DUPLICATES FROM <DYN_TABLE> COMPARING (string).
    It also got failed at runtime.
    Please suggest how can i achieve this....
    Regards
    Munish Garg

    Hi,
    this code is worked truly.
    You can try this.
    Regards.
    DATA itab LIKE STANDARD TABLE OF mard.
    SELECT * FROM mard INTO TABLE itab UP TO 100 ROWS.
    * You define max number of the field that you need
    data : cmp01  TYPE string,
    cmp02 TYPE string,
    cmp03 TYPE string,
    cmp04 TYPE string,
    cmp05 TYPE string.
    * You fill the fields that you need, others is clear.
    cmp01  = 'MATNR'.
    cmp02 = 'WERKS'.
    CLEAR : cmp03,cmp04,cmp05.
    SORT itab BY (cmp01) (cmp02) (cmp03) (cmp04) (cmp05).
    DELETE ADJACENT DUPLICATES FROM itab COMPARING (cmp01) (cmp02) (cmp03)
    (cmp04) (cmp05).

  • Using: Delete Adjacent Duplicates

    Hi,
    How can we use Delete Adjacent Duplicates where comparing clause is dynamic.
    The the number of comparison characteristics are dependent on some other conditions and are decided at runtime. Also can this be used with Field-Symbols.
    Arunava

    Hi Arunava,
    The following were taken from ABAP key word documentation.
    1. The DELETE ADJACENT DUPLICATES statement works particularly well if you have sorted the internal table itab according to the fields that you want to compare when looking for duplicates. In this case, deleting adjacent duplicates is the same as deleting all duplicates. The direction of the sort is irrelevant.
    2. <b>If you do not know a comparison expression until runtime, you can specify it dynamically as the contents of the field name in the expression COMPARING ... (name) .... If name is empty at runtime, the comparison expression is ignored. If name contains an invalid component name, a runtime error occurs.</b>
    3. You can further restrict comparison expressions - both static and dynamic - by specifying offset and length.
    Regards
    Raja

  • Delete adjacent duplicates from dynamic table

    Hi all,
    How to do delete adjacent <tab> comparing f1 f2 f3 for a dynamic table.
    Thx in advance
    Edited by: Misha Denis on Feb 14, 2010 9:28 AM
    Moderator message - Cross post locked
    Edited by: Rob Burbank on Feb 14, 2010 3:45 PM

    you can use a function   GET_COMPONENT_LIST to get all the fields' name  after the dynamic table generated. then you can use the field name in the statement "DELETE....COMPARE "
         CALL FUNCTION 'GET_COMPONENT_LIST'
             EXPORTING
               program          = SY-REPID
               fieldname        = THE_NAME_OF_THE_DYNAMIC_INTERNAL_TABLE
             tables
               components       = ITAB
    LOOP AT ITAB.
    *ASSIGN THE ITAB-COMPNAME TO SOME VARIANTS:FIELD1,FIELD2,FIELD3.
    ENDLOOP. 
    SORT THE_NAME_OF_THE_DYNAMIC_INTERNAL_TABLE BY FIELD1  FIELD2  FIELD3.
    DELETE ADJACENT DUPLICATES FROM THE_NAME_OF_THE_DYNAMIC_INTERNAL_TABLE COMPARING FIELD1 FIELD2 FIELD3.

  • Delete adjacent duplicates

    hi,
      SORT itab ASCENDING BY xxx.
      DELETE ADJACENT DUPLICATES FROM itab COMPARING xx.
    1)can i do in a loop as i need to throw in error file for those repeated record.
    2)the itab without header record is ok rite? our standard is not to use occurs but to define another working area. our standard is loop itab into wa
    thanks

    Hi,
    You can solve your prob using below code:
    DATA: ind(1), p_val like itab-field1.
    SORT itab ASCENDING field1.
    LOOP AT itab INTO wa_itab.
    CLEAR: p_val, ind.
    ON CHANGE OF field1.
    p_val = itab-field1.
    ind = 'X'.
    ENDON.
    IF itab-field1 = p_val AND NOT ind IS INITIAL.
    DELETE itab INDEX sy-tabix.
    ENDIF.
    ENDLOOP.
    Thanks.

  • Extract - Delete Adjacent Duplicates

    Hi Experts,
    As in internal tables is it possible to delete adjacent duplicate records from an extract ?
    Thanks in advance.
    Ramesh.

    Hi,
    Deleting Adjacent Duplicate Entries
    To delete adjacent duplicate entries use the following statement:
    DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
    [COMPARING <f1> <f2> ...
    |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> <f2> ... the contents of the specified fields <f1> <f2> ... must be identical in both lines. You can also specify a field <fi> dynamically as
    the contents of a field <ni> in the form (<ni>). If <ni> 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.
    Ex.
    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.
    Regards,
    Bhaskar

  • Regarding SELECT FOR ALL ENTRIES AND DELETE ADJACENT DUPLICATES

    Hi,
    i got few doubts.....
        1) Is it necessary to DELETE ADJACENT DUPLICATES when we perform a SELECT FOR ALL ENTRIES ? because for all entries itself eliminates the duplicate entries?
       2) Wat Sy-subrc returns after a SELECT FOR ALL ENTRIES statement?
       I found some code where these are used
               SORT ITAB[] BY NEWKO[].
              DELETE ADJACENT DUPLICATES FORM ITAB[].
      SELECT buknr
                   kunnr
    FORM KNB1
        into table ITAB_KNB1
      FOR ALL ENTRIES IN ITAB
        where kunnr eq itab-newko.
    Regards.
    Maehsh.

    Hi Mahesh,
    To be more specific, first you should delete "adjacent duplicates" using the sorting key ( here : NEWKO ), if Itab contains other fields.
    SORT ITAB[] BY NEWKO[].
    DELETE ADJACENT DUPLICATES FORM ITAB COMPARING NEWKO.
    You can delete or not the duplicates, but, you must know that if you don't delete them in the Itab, you will retrieve them in the ITAB_KNB1.
    Concerning the return code, it works like for the "SELECT"  ( 0 = entries found / 4 = no entrie found )
    => One more thing, it's better check :
    Check not ITab[] is initial
    because, if the Itab is empty, you'll retrieve all the record of KNB1 !
    Hope this helps,
    Erwan.
    Message was edited by:
            Erwan LE BRUN

  • Probelm with DELETE ADJACENT DUPLICATES

    Hi Guys!
    Here's the scenario, I have this syntax in my report..
    delete adjacent duplicates from it_itab comparing matkl sptag+0(6)
    The values inside the it_tab is as follows..
    20080301|01010402
    20080301|02024301
    20080305|01010402
    20080310|01010402
    when I debug it, and used the syntax delete adjacent duplicates from it_itab comparing matkl sptag+0(6),
    the output will be like this....
    20080301|01010402
    20080301|02024301
    20080305|01010402
    I dont know why this output showed up. I'm expecting do have this output
    20080301|01010402
    20080301|02024301
    Could someone explain why this happened? Is there a problem or loop hole in delete adjacent duplicate?
    Please help! thanks so much!
    Regards,
    Mackoy

    hi
    do this:
    sort it_itab by matkl sptag.
    delete adjacent....
    delete adjacent will always look for the adjacent entries, and if a dupliacte is found then it deletes the 2nd records.
    for ex , u have,
    var1
    123
    123
    124
    125
    123
    in this case....2nd record is deleted and the output will be
    123
    124
    125
    123 . if it was sorted by var1 and then delete adjacent duplicates was used then it will have unique records.
    regards,
    madhumitha

Maybe you are looking for

  • Error while running adpreclone on Database Tier

    Hii.. im getting following error while running adpreclone on database Tier, This is Error Message coming, D:\APPSORA\proddb\10.2.0\appsutil\scripts\PROD_diwaf-prd-erpdb>perl adpreclone.pl dbTier Running Rapid Clone with command... perl D:\APPSORA\pro

  • Importing a single dumpfile in multiple databases at a time

    Hi Folks, I got request from my client side like follows, They have a dump file of one schema called belin(schema name). With that dump file i need to import to three databases called 1. gelixu1 2. gelixu2 3. gelixu3 in parallel manner (it means at a

  • Sales Representative Commission Report

    Hi, Is there any standard report for Sales Representative Commission Report for Professional services. regards ravi

  • Camera Card slot shows up as network sharepoint

    I work in a mac environment, five computers running osx 10.5 throught 10.8. they all show one camera card slot on the HP 6500 as a bloody sharepoint! Is there any way to make this card plug stop broadcasting on the network short of ripping out the et

  • RFC user logon failed R3077

    Hello RFC user logon failed. Can anybody help me out for R3077 Its occuring regularly Thanks And Regards Akash Gupta