Need clarification on select query Urgent!!!!!

Hi ,
i want clarification about this query , because i want improve performence to report in ST05 it is showing 1,40,250 time so i need to do some thing on this please any body help me out.
SELECT  matnr  werks  dispo
             FROM   marc
             INTO   TABLE  it_marc
                    WHERE  matnr  IN  s_matnr  AND
                           werks  IN  s_werks  AND
                           dispo  EQ  p_dispo.
    DESCRIBE TABLE it_marc  LINES w_lines.
    IF  w_lines  IS INITIAL.
      MESSAGE e518(zv) WITH p_dispo.
    ENDIF.
  ENDIF.
thanks,
murali.

SELECT matnr
  FROM mara
  INTO TABLE it_mara
  WHERE matnr IN s_matnr.
IF sy-subrc eq 0.
  SELECT matnr werks dispo
    FROM marc
    INTO TABLE it_marc
    FOR ALL ENTRIES IN it_mara
    WHERE matnr = it_mara-matnr
      AND werks IN s_werks
      AND dispo EQ p_dispo.
  DESCRIBE TABLE it_marc LINES w_lines.
  IF w_lines IS INITIAL.
    MESSAGE e518(zv) WITH p_dispo.
  ENDIF.
ENDIF.
I am sorry, but I comment also bad recommendations, if I find any. And the above example such
a bad recommendation.
SELECT matnr
  FROM mara
  INTO TABLE it_mara
  WHERE matnr IN s_matnr.
The first select selects much more than you really need, while there is only a select single necessary.
  DESCRIBE TABLE it_marc LINES w_lines.
  IF w_lines IS INITIAL.
It is also not necessary to count 1000 of lines, if you want to know whether there was at least one records, a check
of a sy-subrc is much better. This should also be done in the original coding.
As said above, check what is in s_matnr and s_werks and what is suppossed to come back.
Siegfried

Similar Messages

  • Need clarification regarding select query

    Hi,
    I need a little clarification regrding a Select senario
    I want to select data from table which have been minupulated between a certian date like between 1-DEC-10 to 31-DEC-10 and note that table does not have any time/date column. I've applied the following query to do this.
    select * from TABLE_NAME where sysdate between to_date('01-DEC-10') AND to_date('31-DEC-10');
    Would it work fine because I've tried it against a table and it returned me nothing however DML occur between time period.
    Regards,
    Abbasi

    Abbasi wrote:
    Hi,
    I need a little clarification regrding a Select senario
    I want to select data from table which have been minupulated between a certian date like between 1-DEC-10 to 31-DEC-10 and note that table does not have any time/date column. I've applied the following query to do this.
    select * from TABLE_NAME where sysdate between to_date('01-DEC-10') AND to_date('31-DEC-10');
    Would it work fine because I've tried it against a table and it returned me nothing however DML occur between time period.
    Regards,
    AbbasiAFAIK without log mining and auditing this is not possible.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/logminer.htm

  • I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    I need to add a single field from with_item table . need to write select query with reference to company code , account doc no , fiscal year

    Hi Arun ,
    Can you explain little bit more ??
    what is account doc no? 
    what are the transactions should be displayed in your output??
    -Rajesh N

  • MANDT in Select Query  ---- Urgent

    Hi,
    Will the passing of MANDT field in a select query makes the difference performance wise??
    i.e, if I pass the MANDT (key field in all the tables) while querying a table, Will it give me a different result performance wise??
    Can you attach some SAP document as a proof for this answer??
    With Regards
    Jiku

    Hi,
    There is no need to include this field in the select query and it has nothing to do with improving performance.
    I don't think you can find any SAP document for same but you will find same answer from everyone
    Reward points if useful.
    Regards,
    Atish

  • Need help in Select Query

    Hello,
    I am using oracle 9i and windows XP:
    Please help me to making a query to get output as mentioned below:
    create table myt(col1 varchar2(10));
    insert into myt values('TABLE1');
    insert into myt values('TABLE2');
    insert into myt values('TABLE3');
    COMMIT;
    create table table1(name varchar2(10),amount number);
    create table table2(name varchar2(10),amount number);
    create table table3(name varchar2(10),amount number);
    insert into table1 values('James',1000);
    insert into table1 values('David',1500);
    insert into table1 values('James',2000);
    insert into table1 values('David',1735);
    insert into table2 values('Menon',500);
    insert into table2 values('Martin',700);
    COMMIT;
    Required Output:
    Table Name
    Table1
        James: 3000
        David: 3235
        Sum:   6235
    Table2
        Menon:  500
        Martin: 700
        Sum:   1200
             -------Regards

    In your solution i added some modifications and got the output:
    declare
    cr_lf varchar2(2) := chr(13) || chr(10);
    the_cursor sys_refcursor;
    the_sql varchar2(4000) := 'select * from ' || cr_lf || '(' || cr_lf;
    a_table varchar2(10);
    ln varchar2(10);
    a_name varchar2(10);
    an_amount number:=0;
    tan_amt number:=0;
    i number;
    j varchar2(4000);
    begin
    for the_row in (select col1 from myt) loop
    the_sql := the_sql || 'select ''' || the_row.col1 || ''',name,sum(amount) from ' || the_row.col1 || ' group by name ' || cr_lf;
    the_sql := the_sql || 'union all' || cr_lf;
    end loop;
    the_sql := substr(the_sql,1,length(the_sql) - 11) || ')' || cr_lf;
    i := 1;
    j := instr(the_sql,cr_lf,i);
    while i > 0 loop
    exit when j = 0;
    dbms_output.put_line(substr(the_sql,i,j - i));
    i := j + 2;
    j := instr(the_sql,cr_lf,i);
    end loop;
    dbms_output.put_line(substr(the_sql,i));
    --dbms_output.put_line(the_sql);
    open the_cursor for the_sql;
    dbms_output.put_line('--------------------------------------------------------------------------');
    dbms_output.put_line(rpad('TABLE',20) || ' ' || rpad('NAME',20) || ' ' || rpad('AMOUNT',20));
    dbms_output.put_line('--------------------------------------------------------------------------');
    loop
    ln:= a_table;
    fetch the_cursor into a_table,a_name,an_amount;
    exit when the_cursor%notfound;
    if ln<>a_table then
    dbms_output.put_line('--------------------------------------------------------------------------');
    dbms_output.put_line(rpad('SUM',40) || lpad(to_char(tan_amt),10));
    dbms_output.put_line('--------------------------------------------------------------------------');
    tan_amt:=0;
    end if;
    tan_amt:= tan_amt+an_amount;
    dbms_output.put_line(rpad(a_table,20) || ' ' || rpad(a_name,20) || ' ' || rpad(an_amount,20));
    end loop;
    dbms_output.put_line('--------------------------------------------------------------------------');
    --dbms_output.put_line(rpad('SUM',45) || to_char(tan_amt));
    dbms_output.put_line(rpad('SUM',40) || lpad(to_char(tan_amt),10));
    dbms_output.put_line('--------------------------------------------------------------------------');
    close the_cursor;
    end;
    select * from
    select 'TABLE1',name,sum(amount) from TABLE1 group by name
    union all
    select 'TABLE2',name,sum(amount) from TABLE2 group by name
    union all
    select 'TABLE3',name,sum(amount) from TABLE3 group by name
    TABLE                  NAME                  AMOUNT
    TABLE1                 David                  6470
    TABLE1                 James                  6000
    SUM                                          12470
    TABLE2                 Martin                 1400
    TABLE2                 Menon                  1000
    SUM                                           2400
    --------------------------------------------------------------------------So many thanks for providing solution to me.
    Regards

  • Need Clarification where SQL query is parsed either in Server or in Drivers

    hi all,
    i'm using OracleXEUniversal database and using Type4(thin) drivers to get communicate from Java.
    the queries what i'm giving programmatically, where it will get parse.
    either Server will parse, execute them and send back the results
    or thin drivers will parse query and the parsed query will send to Server and execute there and return the results.
    which one is correct.
    if it parsing at Server side only, what is the need of Cleint software.
    plz, clarify this doubt.
    regards
    pavan

    Parsing will be done in server side. Need of client software is to see the result.

  • Need help on select query

    Hi,
    I have a query which will produce me the below data:
    DataTime SLA Met Time
    20101212 12/13/2010 12:48:29 PM
    20101211 12/12/2010 4:50:38 PM
    20101210 12/11/2010 2:07:02 PM
    20101209 12/11/2010 9:46:30 AM
    20101208 12/10/2010 4:46:19 AM
    Now with the above data I want to find "sla status". Below is the condition:
    1. if datatime is 20101212 (yyyymmdd) and if sla is met on or before 20101212 6pm then it has to print sla status as "MET", by any chance if sla is met after 6pm then it has to print as "Not Met".
    2. So we dont have any static data in table and we have around 20k rows in the table.
    3. Datatime is a Number column.
    Please help me on this. Thanks

    user497267 wrote:
    Hi,
    I have a query which will produce me the below data:
    DataTime SLA Met Time
    20101212 12/13/2010 12:48:29 PM
    20101211 12/12/2010 4:50:38 PM
    20101210 12/11/2010 2:07:02 PM
    20101209 12/11/2010 9:46:30 AM
    20101208 12/10/2010 4:46:19 AM
    Now with the above data I want to find "sla status". Below is the condition:
    1. if datatime is 20101212 (yyyymmdd) and if sla is met on or before 20101212 6pm then it has to print sla status as "MET", by any chance if sla is met after 6pm then it has to print as "Not Met".
    2. So we dont have any static data in table and we have around 20k rows in the table.
    3. Datatime is a Number column.
    Please help me on this. ThanksDatatime is a number column? {noformat}*shudders*{noformat} Why?! Why is it not just DATE format? What's the difference between 20100101 and 20091231? 1 day if we're talking dates and 8870 if we're talking numbers. By taking out the fact that you're talking about dates in that column, you restrict the information available to the optimizer, and you open yourself up to poorly performing SQL.
    As it is, if you're looking to check the sla met time is before 6pm on the datatime, then you need to have a case statement, convert the datatime to a date (to_date() ) and then add 18 hours to that time and compare it with the sla_met_time.

  • SELECT QUERY-URGENT!!!

    Hi,
    Please respond on this ASAP.
    SELECT SINGLE PRODH FROM MVKE INTO MVKE-PRODH WHERE
    MATNR = VBDPR-MATNR.
    IF SY-SUBRC EQ 0.
    IF MVKE-PRODH NE SPACE.
    IF MVKE-PRODH(5) EQ '00003'.
    V_WINDSHIELDS = V_WINDSHIELDS + V_INV_QTY.
    V_WINDSHIELDS_TOTAL = V_WINDSHIELDS_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00004'.
    V_TEMPERED = V_TEMPERED + V_INV_QTY.
    V_TEMPERED_TOTAL = V_TEMPERED_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00005'.
    V_MOLDINGS = V_MOLDINGS + V_INV_QTY.
    V_MOLDINGS_TOTAL = V_MOLDINGS_TOTAL + V_INV_QTY.
    ENDIF.
    ENDIF.
    ENDIF.
    this is the logic
    i want to know if we are using sel single and
    if there are more entries in MVKE
    then too it will pick 1st always
    then what is the alternate,

    Hi
    When you use select single ,it's always will bring only one result (first that corresponds to selection criteria (in this case MATNR number).
    you can make it for example (make performance modifiation later):
    data:itab type mvke.
    SELECT SINGLE *
    FROM MVKE
    INTO table ITAB
    where MATNR = VBDPR-MATNR.
    IF SY-SUBRC EQ 0
    loop at itab.      (instead of MVKE put ITAB)
    IF MVKE-PRODH NE SPACE.
    IF MVKE-PRODH(5) EQ '00003'.
    V_WINDSHIELDS = V_WINDSHIELDS + V_INV_QTY.
    V_WINDSHIELDS_TOTAL = V_WINDSHIELDS_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00004'.
    V_TEMPERED = V_TEMPERED + V_INV_QTY.
    V_TEMPERED_TOTAL = V_TEMPERED_TOTAL + V_INV_QTY.
    ELSEIF MVKE-PRODH(5) EQ '00005'.
    V_MOLDINGS = V_MOLDINGS + V_INV_QTY.
    V_MOLDINGS_TOTAL = V_MOLDINGS_TOTAL + V_INV_QTY.
    ENDIF.
    ENDIF.
    endloop.
    so you will get all occurrences which corresponds for the matnr number
    Regards
    Yossi

  • Formatted Select Query

    The following select query returns data in green.  How do I format to return the way it is formatted in red?
    Basically, If FIELD1 is 'Customer A' and FIELD2 is 'Gas' then I want to return 'New Customer' in FIELD1 and 'Gas' in FIELD2.  If FIELD1 is 'Customer E' and FIELD2 is 'Total' then it should return 'E Discharge' in FIELD1 and 'Prod_Discharge' in FIELD2.
    Please let me know if my question doesn't make sense or need clarification.
    SELECT
    DECODE(FIELD1, 'New', 'A', 'Old', 'E', 'Term', 'F', FIELD1)
    ,DECODE(FIELD2, 'Prod', 'Gas', FIELD2)
    FROM Customers
    FIELD1                  FIELD2   
    Customer A           Gas          
    Customer A           Oil     
    Customer E           Total          
    Customer F           Total   
    Need to format as follows:
    FIELD1                  FIELD2       
    New Customer       Gas          
    New Customer       Oil      
    E Discharges         Prod_Discharged          
    F Discharges         Prod_Discharged

    I have added two fields, CustID and Status, to the query and get an error  "FROM keyword not found where expected"
    SELECT
    CustID,
    CASE WHEN field1 = 'Customer A' AND field2 = 'Gas'   THEN 'New Customer'
                WHEN field1 = 'Customer E' AND field2 = 'Total' THEN 'E Discharge'
              ELSE field1
           END AS FIELD1
         , CASE WHEN field1 = 'Customer E' AND field2 = 'Total' THEN 'Prod_Discharge'
              ELSE field2
           END AS FIELD2
    'Status
    FROM Customers

  • Upto how many characters will accept in SELECT query  SENDER JDBC (PI 7.1)

    Hi Friends,
    I have to use Sender JDBC adapter in SAP PI 7.1, I need to use SELECT query only.
    I have a SELECT query is around 2 pages. Is this will accepet in SENDER JDBC in PI 7.1
    Thanks in advance.

    Hi Challarapu,
    You can check it out and if it is not accepted by the same then you need to check the maximal length @ DB settings or JDBC Settings whether it is limited. If not then you are allowed.
    Hope this helps.
    Regards
    Pothana

  • SELECT query performance : One big table Vs many small tables

    Hello,
    We are using BDB 11g with SQLITE support. I have a query about 'select' query performance when we have one huge table vs. multiple small tables.
    Basically in our application, we need to run select query multiple times and today we have one huge table. Do you guys think breaking them into
    multiple small tables will help ?
    For test purposes we tried creating multiple tables but performance of 'select' query was more or less same. Would that be because all tables will map to only one database in backed with key/value pair and when we run lookup (select query) on small table or big table it wont make difference ?
    Thanks.

    Hello,
    There is some information on this topic in the FAQ at:
    http://www.oracle.com/technology/products/berkeley-db/faq/db_faq.html#9-63
    If this does not address your question, please just let me know.
    Thanks,
    Sandra

  • Concatenate name in select query...

    Hi Pals,
    I was wondering how to directly concetenate client name in the select query itself...
    Currently the code says :
    SELECT SINGLE NAME1 NAME2
               INTO (V_NAME1,V_NAME2)
               FROM KNA1
               WHERE KUNNR = I_PROJ-ZZCLIENT.
    CONCATENATE V_NAME1 V_NAME2 INTO I_PROJ-CLNAME SEPARATED BY SPACE.
    Can we say some thing like...
    SELECT SINGLE ( NAME1 + ' ' + NAME2 ) AS CLNAME
               INTO I_PROJ-CLNAME
               FROM KNA1
               WHERE KUNNR = I_PROJ-ZZCLIENT.
    But its giving error...
    Basically i need a single select query which would give me  space seperated clientname in I_PROJ directly
    Please help me...
    Regards,
    Abhishek B.

    Hi Abhishek,
    OPEN SQL.
    1. Sap works on the concept of Open Sql.
       ie. Sql  is database independent.
    2. ABAP Syntax does not have provision for
       using such EXPRESSIONS (like concatenate)
       directly in SQL.
    3. However u may use them in Native Sql.
    4. In open sql one can use aggregate functions
       like SUM COUNT etc.
       But Concatenate is not allowed.
    Hope u find the answer useful.
    (To newbees)
    U may please award points (if u find the reply useful)
    by clicking on the STAR on the left of the reply.
    Regards,
    Amit M.

  • Problem is select query.

    Hello SDNites,
    I have a req where I need to use select query to fetch data. But the conditions which is to be placed in this select query has 3 checkboxes corresponding to the same field. Either of them can be selected at a time. Please let me know how can we put this condition effectively in one select query.
    Thanks,
    Abhishek

    Hi Abhishek,
    Depending on your check box selection u can concatenate the string for where ckause....
    For eg:-
    concatenate `'` 'A' `'` into fs.
    concatenate `'` 'F' `'` into fs1.
    if cb1 = 'X' and CB2 = 'X'.
    CONCATENATE  'bstyp' '='   FS  'OR' 'bstyp' '='  FS1  INTO FS SEPARATED BY SPACE.
    endif.
    select * from dbtab into table itab where (fs).
    depending on ur check box selection u can change ur VARIABLE FS to be used in where clause....... But u just need to use single select query.

  • SQL SELECT Query Help   ..Please its very Urgent!!

    Hi All,
    I am having Oracle Database whice is storing 1000's of records daily.
    I need to select some information based on date and time.
    I am having two coloumns for Date and time. The first column(testDate) of type Date stores date as MM/DD/YY format and the second column(testTime)of type Numeric stores the time in seconds.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    How can i write a SELECT Query to get the records of specific date and seconds to next day specific date and seconds.I mean i want all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    If any one helps me in this regard iam very thank full to them.Its very urgent for me.
    Thanks

    Hi m7nra,
    I used the query as
    SELECT * FROM table
    WHERE testDate + (testTime/(24*60*60)) BETWEEN TO_DATE('MM/DD/YYYY','12.11.2002') AND TO_DATE('MM/DD/YYYY','14.11.2002')
    its giving DATE FORMAT NOT RECOGNIZED error.
    The Example data is :
    testDate ------=-- testTime
    11/12/2002 --- 35000
    11/12/2002 --- 43000
    11/12/2002 --- 45000
    11/12/2002 --- 75000
    11/13/2002 --- 2000
    11/13/2002 --- 3500
    11/13/2002 --- 4300
    11/13/2002 --- 9800
    11/13/2002 --- 23000
    11/14/2002 --- 5000
    11/14/2002 --- 10000
    11/14/2002 --- 15000
    infact i need all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
    Please help me to find a full query beacuse iam very new to Oracle.
    Thanks,
    S R Mannava

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

Maybe you are looking for