SELECT DISTINCT with JOIN

Hi,
how Do I write this select in rigth way in ABAP
SELECT ska1ktopl AS ktopl ska1saknr AS saknr
    t370k_t~eartx AS eartx
    INTO  TABLE lt_ska1 FROM ska1
    JOIN (SELECT DISTINCT damage_gl FROM  zzpm_cost_elem )  ON ska1saknr = zzpm_cost_elemdamage_gl.
The problem with the select "SELECT DISTINCT damage_gl FROM  zzpm_cost_elem " which I have to put table name instead of it
What should I do ?
Thx

Hi Friend ,
Please see this example  how you can use the select DISTINCT statement
DATA: ITAB TYPE STANDARD TABLE OF SPFLI,
      WA LIKE LINE OF ITAB.
DATA: LINE(72) TYPE C,
      LIST LIKE TABLE OF LINE(72).
LINE = ' CITYFROM CITYTO '.
APPEND LINE TO LIST.
SELECT DISTINCT (LIST)
       INTO CORRESPONDING FIELDS OF TABLE ITAB
       FROM SPFLI.
IF SY-SUBRC EQ 0.
  LOOP AT ITAB INTO WA.
    WRITE: / WA-CITYFROM, WA-CITYTO.
  ENDLOOP.
ENDIF.
Regards,

Similar Messages

  • Need help with select distinct with group by

    RDBMS 10gr2
    I am trying achieve having a select distinct with a order by and after looking on the internet and trying different examples, I have been unsucessful.
    Here is the code working (not sorting - I wish to sort by pps.last_name however I can't seem to get it to work).
    select distinct pps.last_name || ', ' ||pps.first_name || ' ' ||pps.middle_initial || '.' d,
           emple_no r
      from cobr.vw_pps_payroll pps,
           projman pm
    where term_date is null
       and department = '0004400000'
       and pm.eid != pps.emple_no

    SQL> SELECT   ename || '-' || empno, sal
      2      FROM emp_test
      3  ORDER BY ename;
    ENAME||'-'||EMPNO                                                                         SAL
    BLAKE-7698                                                                              20000
    CLARK-7782                                                                              20000
    DAVID-7699                                                                              20000
    FORD-7902                                                                                6000
    JONES-7566                                                                               5950
    KING-7839                                                                               10000
    SCOTT-7788                                                                               6000
    7 ligne(s) sélectionnée(s).
    SQL>

  • Select Distinct and join in ODI

    Hi,
    I have following task to perform: I am loading metadata into Planning dimension from Oracle database. I have two tables
    1. "Sales"
    Columns: Name, Number, Value
    Sample Data:
    Product 1, 10, 200
    Product 2, 30, 100,
    Product 1, 15, 500
    2. P&R
    Columns:
    Name, Alias
    Product 1, SampleSoda1
    Product 2, SampleSoda2,
    Resource 1, CanForSoda,
    Resource 2, CO2
    What I need to do is: I have to select name and alias from second table of all products that were sold.
    So I need to select distinct Name from Table 1, naxt join it with Table 2 (so I have Name and Alias) and load it to planning.
    I am a little confused how to do it.
    Any help would be great!
    Best regards,
    Greg

    Hi Greg,
    What you can do is either :
    - Create a yellow interface with your table Sales as source. Map the name column directly in the target. In the flow tab, click on your target and select "Distinct rows".
    - Create a second interface, with your first interface as source. Select the "Use Temporary Interface as Derived Table (Sub-Select)" checkbox.
    - Add your second datastore and join it. Or you can use a lookup table.
    OR
    - Create an interface with Sales and P&R as source (or set P&R as a lookup table).
    - Go on the flow tab and select "Distinct rows".
    If you've a lot a data in the first table, I would go for the first solution.
    Hope it helps.
    Regards,
    JeromeFr
    Edited by: JeromeFr on Feb 14, 2013 9:52 AM
    To be more clear in the first step of solution 1

  • SELECT DISTINCT With OPEN cursor FOR

    Hello.
    I have the following procedure. All it does is open a cursor for an SQL string passed into it, and return the open cursor.
    PROCEDURE sp_execute_dynamic (hold_input_string IN CLOB,
    hold_cursor OUT hold_cursor_type) IS
    BEGIN
    OPEN hold_cursor FOR TO_CHAR(hold_input_string);
    END sp_execute_dynamic;
    It works fine except when I perform SELECT DISTINCT. I get the following error.
    SQL> declare
    2 TYPE hold_cursor_type IS REF CURSOR;
    3 hold_cursor hold_cursor_type;
    4 hold_object_name VARCHAR2(1024);
    5 hold_object_type VARCHAR2(1024);
    6 begin
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    10 exit when hold_cursor%NOTFOUND;
    11 dbms_output.put_line('Object Name = '||hold_object_name||' Object Type = '||hold_object_type);
    12 end loop;
    13 end;
    14 /
    declare
    ERROR at line 1:
    ORA-01007: variable not in select list
    ORA-06512: at line 9
    It does the same thing with SELECT UNIQUE or SELECT with a GROUP BY. Can anyone tell me why this happens and what I could to to work around it?
    Thanks
    Chris

    see at line 7 you are selecting only one column and at line 9you are fetching into two variables
    7 dynamic_sql_pkg.sp_execute_dynamic('select distinct object_name from user_objects where object_
    name in (''PLAN_TABLE'',''DBA_OBJECTS'')',hold_cursor);
    8 loop
    9 fetch hold_cursor into hold_object_name, hold_object_type;
    HTH

  • SELECT DISTINCT with LINQ

    Hey,
    I am trying to perform a SELECT DISTINCT COL1, COL2, COL3 FROM VIEW WHERE CONDITION using LINQ with ODAC 112030 but I get different results.
    C#:
    var s1 = context.Select(v=>new { v.COL1, v.COL2, v.COL3}).Where(...).Distinct();
    Any ideas?

    Hey,
    I think this way works - with anonymous types:
    context.Entity.Where(...).Select(ent => new { col1 = ent.COL1, ... }).Distinct();.
    You can also do context.Entity.Select("distinct it.COL1, it.COL2").Where("..."); but one should be careful to add all necessary columns in select statement.
    Edited by: 917334 on Jun 7, 2012 7:11 AM

  • Ho to do a select distinct with many colums

    Hi,
    How can I do a select distinct from many colums so that I get only one result for each case.
    e.g if I want to select from employees table.
    Hire_date,salary,job_id,department_id

    This could be one of the solutions !
    SQL> SELECT * FROM DS;
    DEPTNO JOB             ID
        101 MANAGER        500
        101 ANALYST        520
        105 ANALYST        520
        101 MANAGER        501
        102 MANAGER        501
        102 PROGRAMMER     605
        102 PROGRAMMER     501
        103 CLERK          605
    8 rows selected.
    SQL> select case when row_number() over(partition by deptno order by deptno)>1
      2  then null else deptno end "DEPTNO",
      3  case when row_number() over(partition by job order by job) >1
      4  then null else job    end "JOB",
      5  case when row_number() over(partition by id  order by id )>1
      6  then null else id  end "ID" from ds;
    DEPTNO JOB             ID
        101 ANALYST        520
            MANAGER        500
                           501
        102
                           605
            PROGRAMMER
        103 CLERK
        105
    8 rows selected.

  • Select Problem with Joined tables

    Hello everyone I have the following Query
    SELECT
        OBJEKTI.OBJEKAT_ID OBJEKAT_ID,
        OBJEKTI.ADRESA ADRESA,
        OBJEKTI.POVRSINA POVRSINA,
        OBJEKTI.BROJ_IZVRSILACA BROJ_IZVRSILACA,
        OPREMLJENOSTI.OPREMLJENOST_ID OPREMLJENOST_ID,
        OPREMLJENOSTI.PULT PULT,
        OPREMLJENOSTI.REKLAMA REKLAMA,
        OPREMLJENOSTI.MOKRI_CVOR MOKRI_CVOR,
        OPREMLJENOSTI.WC_ZA_IGRACE WC_ZA_IGRACE,
        OPREMLJENOSTI.WC_ZA_OSOBLJE WC_ZA_OSOBLJE,
        OPREMLJENOSTI.VENTILATOR VENTILATOR,
        OPREMLJENOSTI.OSVJETLJENJE OSVJETLJENJE,
        OPREMLJENOSTI.VRSTA_BROJILA VRSTA_BROJILA,
        OPREMLJENOSTI.ELEKTRO_INSTALACIJE ELEKTRO_INSTALACIJE,
        OPREMLJENOSTI.VODO_INSTALACIJE VODO_INSTALACIJE,
        OPREMLJENOSTI.TELEFONSKE_INSTALACIJE TELEFONSKE_INSTALACIJE,
        OPREMLJENOSTI.GRIJANJE_ID GRIJANJE_ID,
        OPREMLJENOSTI.POD_ID POD_ID,
        OPREMLJENOSTI.PROZORI_VRATA_ID PROZORI_VRATA_ID,
        OPREMLJENOSTI.OBJEKAT_ID OBJEKAT_ID1,
        TEHNICKE_OPREMLJENOSTI.TEH_OPR_ID TEH_OPR_ID,
        TEHNICKE_OPREMLJENOSTI.ONLINE_KLADIONICA ONLINE_KLADIONICA,
        TEHNICKE_OPREMLJENOSTI.PANO PANO,
        TEHNICKE_OPREMLJENOSTI.NOSACI NOSACI,
        TEHNICKE_OPREMLJENOSTI.TV_LCD TV_LCD,
        TEHNICKE_OPREMLJENOSTI.TV_TELETEXT TV_TELETEXT,
        TEHNICKE_OPREMLJENOSTI.APARATI_IGRE APARATI_IGRE,
        TEHNICKE_OPREMLJENOSTI.EVONA EVONA,
        TEHNICKE_OPREMLJENOSTI.NOVOMATIC NOVOMATIC,
        TEHNICKE_OPREMLJENOSTI.RULET RULET,
        TEHNICKE_OPREMLJENOSTI.BILIJAR BILIJAR,
        TEHNICKE_OPREMLJENOSTI.KLIMA KLIMA,
        TEHNICKE_OPREMLJENOSTI.OBJEKAT_ID OBJEKAT_ID2,
        PONUDE.PONUDA_ID PONUDA_ID,
        PONUDE.ONLINE_TERMINAL ONLINE_TERMINAL,
        PONUDE.SRECKE SRECKE,
        PONUDE.ONLINE_KLADIONICA ONLINE_KLADIONICA1,
        PONUDE.APARATI_IGRE APARATI_IGRE1,
        PONUDE.RULET RULET1,
        PONUDE.BILIJAR BILIJAR1,
        PONUDE.OBJEKAT_ID OBJEKAT_ID3
    FROM
        OBJEKTI,
        OPREMLJENOSTI,
        TEHNICKE_OPREMLJENOSTI,
        PONUDE
    WHERE
    (PONUDE.OBJEKAT_ID=OBJEKTI.OBJEKAT_ID AND TEHNICKE_OPREMLJENOSTI.OBJEKAT_ID=OPREMLJENOSTI.OBJEKAT_ID) OR (OPREMLJENOSTI.OBJEKAT_ID=OBJEKTI.OBJEKAT_ID AND TEHNICKE_OPREMLJENOSTI.OBJEKAT_ID=OPREMLJENOSTI.OBJEKAT_ID)
    ORDER BY OBJEKTI.OBJEKAT_IDThe problem I get is no matter what WHERE clause I use I get doubled values which makes no sense. I checked in the tables and I don't have any doubled values. Each Opremljenost has 1 objekat (there are 2 rows each with its own Objekat) and the same applies to the other 2 tables (PONUDE and TEHNICKE OPREMLJENOSTI) but for some reason they double up the values. If I run it without a where clause at all I get some values repeat itself up to 4 times. Does anyone have a clue what is wrong with my query?

    You are joining a parent table (OBJEKTI) with three child tables (the other three: PON, TEH, OPR).
    Whenever you do that, you will always get duplication of child-rows, if there are multiple child-rows for a parent-row in any of the three child tables.
    For example, let P be a parent table, with two child tables, say C1 and C2.
    Contents:
    Table P:
    p1
    Table C1 (has two rows for row p1):
    1 p1
    2 p1
    Table C2 (has three rows for row p1):
    10 p1
    20 p1
    30 p1If you now do this:
    select P.*,C1.*,C2.*
    from P, C1, C2
    where [join P with C1]  and [join P with C2]Then your result set will look like this:
    P.p1  C1.1  C1.p1  C2.10  C2.p1
    P.p1  C1.1  C1.p1  C2.20  C2.p1
    P.p1  C1.1  C1.p1  C2.30  C2.p1
    P.p1  C1.2  C1.p1  C2.10  C2.p1
    P.p1  C1.2  C1.p1  C2.20  C2.p1
    P.p1  C1.2  C1.p1  C2.30  C2.p1As you can see every C1 row is duplicated three times in the resultset (due to join with C2).
    And every C2 row is duplicated two times in the resultset (due to join with C1).
    This is simply what happens if you join a parent table with multiple child tables...
    Question now is: what is the expected result that you are looking for?

  • Help! Howto use the join function in a query with select distinct ?

    Hi!
    I have 2 tables. I want to select only 1 painting of each artists.
    select distinct idartist
    from tbl_artworks
    where blah blah blah
    order by rand()
    how does the "join" function work for add: name, lastname, title, image and much more... i try... but i fail...
    tbl_artists
    idartist
    name
    lastname
    1
    Paul
    Gaugain
    2
    Vincent
    Van Gogh
    3
    Pablo
    Picasso
    tbl_artworks
    idartwork
    idartist
    title
    image
    1
    1
    days of gods
    image1.jpg
    2
    2
    sunflower
    image2.jpg
    3
    3
    Dora maar au chat
    image3.jpg
    4
    2
    Sky
    image4.jpg
    5
    3
    La vie
    image5.jpg

    Getting a single random image for each probably requires a combination of sql and cf.  It would take someone smarter than me to do it with sql alone.  I would probably try something like this:
    1.  Run a database query that gets all the images from all the artists.
    2.  Run a Q of Q that gets a distinct list of artist ids.
    3.  Loop through that list and run a Q of Q to get all the images for that artist.
    4.  Still in that loop, use randrange (1 to the recordcount) to select a random record from your Q of Q

  • Select distinct problem with muliple join tables, help needed

    Hi,
    I have two main tables. Each has its of sub joined tables.
    guest_id_for_reservation connects two major tables. This has
    to be that way
    because my guest may change the room status from single to
    double (and the
    similar exceptional requests).
    guests reservation
    guest_id_for_reservation
    countrytable hoteltable
    delegationtable roomtype
    I form a query. I want to select distinct those results. But
    it does not
    work.
    If I do not include any table related to reservation table
    and its sub
    joined tables (disregarding guest_id_for_reservation), it
    works.
    Is there a specific syntax for select distinct of this type
    or any
    workaround.?
    Thank you
    Hakan

    Hi I'm still battling with this - have connected the AX to my Imac via ethernet and it shows up fine in Airport Utility. Status light is green and it says its set up to connect to my existing wireless network using wireless connection. Security in Network Preferences is the same for both: WPA2 Personal.
    So I don't think there's a problem with the AX, and my current wireless network (BT Home Hub) is working fine.
    And when I restore factory settings Airport Utility can see the AX before updating settings so the wireless side of AX must work too.
    I'm figuring it must be something about the settings that mean AU can't see it anymore. But I can't work out what, since security is the same.
    Any ideas would be great!

  • Ambigious Column Not Detected In SELECT with JOIN

    I wrote the following SELECT query.
    SELECT TRANS.ID, TRANS.INVISIBLE
    FROM TRANS
    JOIN TRANSCAT TC ON TC.ID = TRANS.TRANSCATID
    JOIN TRANSTYPE TT ON TT.ID = TRANS.TRANSTYPEID
    WHERE INVISIBLE = 0
    AND ID IN (SELECT DISTINCT TRANSID FROM XTRANS WHERE XTRANS.DESCR LIKE '%Geri%' )
    The four table are as follows.
    CREATE TABLE "DBO"."TRANSCAT"
    (     "ID" NUMBER(19,0) NOT NULL ENABLE,
         "NAME" VARCHAR2(16 CHAR),
         CONSTRAINT "pTransCat" PRIMARY KEY ("ID") ENABLE NOVALIDATE
    CREATE TABLE "DBO"."TRANSTYPE"
    (     "ID" NUMBER(19,0) NOT NULL ENABLE,
         "NAME" VARCHAR2(16 CHAR),
         "MESSAGE" NUMBER(1,0) NOT NULL ENABLE,
         CONSTRAINT "pTransType" PRIMARY KEY ("ID") ENABLE NOVALIDATE
    CREATE TABLE "DBO"."TRANS"
    (     "ID" NUMBER(19,0) NOT NULL ENABLE,
         "REFERENCE" NUMBER(10,0) NOT NULL ENABLE,
         "TRANSCATID" NUMBER(19,0) NOT NULL ENABLE,
         "NAME" VARCHAR2(48 CHAR),
         "TRANSTYPEID" NUMBER(19,0) NOT NULL ENABLE,
         "SIZE" VARCHAR2(8 CHAR),
         "KEYWORD" VARCHAR2(64 CHAR),
         "PARAMCOUNT" NUMBER(3,0) NOT NULL ENABLE,
         "PARAMHELP" CLOB,
         "INVISIBLE" NUMBER(1,0) NOT NULL ENABLE,
         "SELECTFLAG" NUMBER(1,0) NOT NULL ENABLE,
         "STAMP" NUMBER(5,0) NOT NULL ENABLE,
         CONSTRAINT "pTrans" PRIMARY KEY ("ID") ENABLE NOVALIDATE,
         CONSTRAINT "fTrans_TransCatId" FOREIGN KEY ("TRANSCATID")
         REFERENCES "DBO"."TRANSCAT" ("ID") ENABLE,
         CONSTRAINT "fTrans_TransTypeId" FOREIGN KEY ("TRANSTYPEID")
         REFERENCES "DBO"."TRANSTYPE" ("ID") ENABLE
    CREATE TABLE "DBO"."XTRANS"
    (     "ID" NUMBER(19,0) NOT NULL ENABLE,
         "TRANSID" NUMBER(19,0) NOT NULL ENABLE,
         "LANGUAGEID" NUMBER(19,0) NOT NULL ENABLE,
         "DESCR" CLOB,
         "REMARK" CLOB,
         "HELP" CLOB,
         "STAMP" NUMBER(5,0) NOT NULL ENABLE,
         CONSTRAINT "pXTrans" PRIMARY KEY ("ID") ENABLE NOVALIDATE,
         CONSTRAINT "uXTrans_TransId_LanguageId" UNIQUE ("TRANSID", "LANGUAGEID") ENABLE,
         CONSTRAINT "fXTrans_LanguageId" FOREIGN KEY ("LANGUAGEID")
         REFERENCES "DBO"."LANGUAGE" ("ID") ENABLE,
         CONSTRAINT "fXTrans_TransId" FOREIGN KEY ("TRANSID")
         REFERENCES "DBO"."TRANS" ("ID") ENABLE
    CREATE UNIQUE INDEX "DBO"."uXTrans_TransId_LanguageId" ON "DBO"."XTRANS" ("TRANSID", "LANGUAGEID") ;
    As you can see every table has an ID column as primary key. When I run this query in SQLDeveloper, the result was zero rows. In the detail plan, Oracle seems to match TransId column of XTrans with TransType's Id column.
    I am new to Oracle. In Sql Server 2005 i get an ambigious column error. Why doesn't Oracle give such an error? Is this a bug?

    My intention is to match XTRANS.TRANSID with TRANS.ID not TRANSTYPE.ID. But oracle matches it with TRANSTYPE.ID. Also TRANSTYPE is not in the FROM clause, why is it the default table? I couldn't understand.
    As you said, I get the expected error with following SELECT
    SELECT TRANS.ID, TRANS.INVISIBLE
    FROM TRANS, TRANSCAT TC, TRANSTYPE TT
    WHERE INVISIBLE = 0
    AND TC.ID = TRANS.TRANSCATID
    AND TT.ID = TRANS.TRANSTYPEID
    AND ID IN (SELECT DISTINCT TRANSID FROM XTRANS WHERE XTRANS.DESCR LIKE '%Geri%' )

  • Dynamic select list with display,return val & join condition issue.

    hello,
    I am having a dynamic select list with display, return value
    say for example my select statement is
    select distinct dname d, deptno r
    from dept dt
    right join emp e on (e.deptno=dt.deptno)
    where (condition)
    when i tried this query for my select list, it is not working. It saying that
    " LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query. "
    I am not able to understand the problem. Can anyone help me out with this issue?
    thanks.

    Shouldn't your join have dept as the driving table?
    select distinct dname d, deptno r
    from dept dt
    right join emp e on (dt.deptno = e.deptno)
    where (condition)
    Or using older Oracle standard join
    select distinct dname d, deptno r
    from dept dt, emp e
    where (dt.deptno (+) = e.deptno) AND (OTHER WHERE condition)
    OR
    (Since a right join is just getting the values from the driving table that are NOT in the associated table)
    select distinct dname d, deptno r
    from dept dt
    WHERE dt deptno NOT IN (SELECT deptno FROM emp) AND (OTHER where condition)
    Thank you,
    Tony Miller
    Webster, TX

  • Absolute dynamic select query with dynamic join and where

    Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
    I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
    Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
        SELECT (FIELDS) INTO TABLE IT_TABLES
          FROM ( (ME->TABLE1)  inner join ( me->table2 )
          on ( on_condition ) )
          WHERE (me->where_fields).
    Ags.

    It worked for me in a following way:
    select * into corresponding fields of table <result_table>
            from (join_string)
            where (l_where).
    Where the contents of join_string were dynamically build using concatenation. So it will be something like
    concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
    <...>
    add here matching/reference colums, something like
    concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
    concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
    concatenate join_string temp1 '=' temp2 into join_string separated by space.
    <...>
    concatenate join_string ')' into join_string separated by space.
    And then use similar approach for l_where variable.

  • SELECT Query design with JOINS

    Dear Users,
    In one of our requirements, we have a SELECT query which joins a few tables together and selects a few fields from each table.
    Example: Fields 1,2 and 3 from Table 1
             Fields 4 and 5 from Table 2.
    These fields are later displayed in the form of an ALV. However, the end user wants more fields on the output, let's say field 6 from Table 2. Due to this requirement, I have to amend the SELECT query to add field 6 of Table 2.
    The above example is simple since it only involves 2 tables. However, in reality, we have a SELECT query with INNER JOINS on more than 6 tables and we don't want to change the code when someone asks for an additional field from one of these tables. Is there any way by which I can design my SELECT query (Using field symbols or dynamic selections etc) such that I don't have to amend the SELECT query and instead I should be able to maintain the field required by the user and it's source table name in a Z-Table and the SELECT automatically picks it up ? Thanks!
    Vijay

    better you can create a view on your 6 or more tables and select the fields .
    Use Select *  from <view name> every time in a select statement.
    If you need a additional column then just change the view , there is no need to change of your select query.
    with regards
    Edited by: Avenai on Jun 28, 2010 2:09 PM

  • ODI: Way to select Distinct data while doing Join of tables at Source

    HI,
    Our requirement is to do a join on multiple tables selecting distinct data from those table at source.
    But we are not able to see the Distinct Box in flow tab.
    Any thoughts to resolve our problem
    Pratik

    You can not put DISTINCT clause selectively .
    If you choose to opt for DISTINCT then Oracle will apply the distinct to all columns present in the select list .
    So at your IKM level just click the distinct check box .. run your interface and find out the query generated .
    See if your requirement is getting fullfilled or not .
    Thank,
    Sutirtha

  • Select distinct and 2 inner joins in same select statement

    can anyone guide me how to write the below query for higher performance. can I use for all entires or shall i split this,
    please let me know your opinions.
    SELECT DISTINCT werks matnr b~stlal idnrk postp d~aennr
       sortf potx1 c~lkenz b~stlty stlst
       INTO TABLE ltab_one
       FROM mast AS a INNER JOIN stko AS b
         ON  a~stlnr = b~stlnr
         AND a~stlal = b~stlal
         INNER JOIN stas AS c
         ON  b~stlnr = c~stlnr
         AND b~stlal = c~stlal
         AND b~stlty = c~stlty
         INNER JOIN stpo AS d
         ON  c~stlnr = d~stlnr
         AND c~stlkn = d~stlkn
         AND c~stlty = d~stlty
      WHERE a~werks IN s_werks
         AND ( ( d~andat IN s_datum
            OR d~aedat IN s_datum
            OR a~andat IN s_datum
            OR a~aedat IN s_datum
            OR b~andat IN s_datum
            OR b~aedat IN s_datum
            OR c~andat IN s_datum
            OR c~aedat IN s_datum
            ) AND d~datuv >= lv_effdt )
         AND a~stlan = '1'
         AND matnr IN s_matnr.

      WHERE a~werks IN s_werks
         AND ( ( d~andat IN s_datum
            OR d~aedat IN s_datum
            OR a~andat IN s_datum
            OR a~aedat IN s_datum
            OR b~andat IN s_datum
            OR b~aedat IN s_datum
            OR c~andat IN s_datum
            OR c~aedat IN s_datum
            ) AND d~datuv >= lv_effdt )
         AND a~stlan = '1'
         AND matnr IN s_matnr.
    This part determines your performance, not the DISTINCT and not the joins.
    What is in s_werks, s-datum, s_matnr typically? I guess there are better and worse conditions.

Maybe you are looking for

  • Plug-in for Mime files for QuickTime missing.

    I've been trying to view certain videos and listen to streaming music and sometimes it works (never that well) and other times it doesn't. I'm using QT not WM and when it works the videos don't play in the viewer. They usually download to the desktop

  • Problems with ordering data

    Hello to all the forum, I have a database named one agenda, and have a table called registration, this table has countless fields, such as name, address, telephone etc ... I also have 3 fields in the same table called tracking, company, contact. My p

  • "AddressBookSourceSync" and iCal keeps asking for login keychain

    So, every 30 minutes or so AddressBookSourceSync and iCal asks me for my login keychain password. It is extermely annoying and I constantly have to type my login password. Clicking 'Cancel' causes it to reappear immediately... How to stop this? Thank

  • Attachments for FI documents

    Hi Experts, Could you please give me some idea how to attach documents, with FI documents? My problem is, there are some FI docs with which some attachments exist, But for some others it's missing. No body (FI consultants in our project!!) could not

  • Material quantity in CJ20N

    Hello, I have a reuirement that when attacjing a material to in CJ20N, the quantuty should be defaulted to 1 for particula materials. How can this be done? Any inputs will be appriciated. Thanks & Regards, Grego