How to make this select statement faster?

this statement is really taking long time to process.
in bseg table as vbeln is not primary key or seconday key, i guess thz the reason it is taking so much time ,,,
can anyone help me to sort this out... ??
any fun mod to get the data of bseg cluster table by giving vbeln?/
or any other conditions to reduce the processing time?
clear t_vbrkvbrp.
sort t_vbrkvbrp by vbeln.
loop at t_vbrkvbrp.
at new vbeln.
select bukrs belnr vbeln
       from bseg
       into corresponding fields of table t_temp
       where bukrs = t_vbrkvbrp-bukrs
        and vbeln = t_vbrkvbrp-vbeln.
endat.
endloop.
SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
       FROM bseg
       INTO TABLE t_bseg
       for all entries in t_temp
       WHERE hkont IN s_hkont
       AND bukrs = t_temp-bukrs
       AND belnr = t_temp-belnr
       AND buzid = ' '
       AND koart = 'S'
       AND shkzg = 'H'.
i need to get the g/l account number for the above condition type so i have to use bseg table
Message was edited by:
        shahid mohammed syed

Shahid,
Usually BSEG SELECTs are slow as it is a Clu8ster table. More over you are not passing the PKeys in the WHERE condition. That's alcso one reason for slow retrieval. You can also use the table BSIS (Accounting: Secondary Index for G/L Accounts) for the G/L accounts. But first of all, I suggest you cnange your where condition as below:
SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
FROM bseg
INTO TABLE t_bseg
for all entries in t_temp
WHERE  bukrs = t_temp-bukrs
AND belnr = t_temp-belnr
AND buzid = ' '
AND koart = 'S'
AND shkzg = 'H'
<b>AND hkont IN s_hkont.</b>
Not much diff. I just re-ordered the condition based on the order of BSEG fields... Lemme know if it helps.
Regards,
Karthik
Message was edited by:
        Karthik

Similar Messages

  • How to optimize this select statement  its a simple select....

    how to optimize this select statement  as the records in earlier table is abt i million
    and this simplet select statement is not executing and taking lot of time
      SELECT  guid  
                    stcts      
      INTO table gt_corcts
      FROM   corcts
      FOR all entries in gt_mege
      WHERE  /sapsll/corcts~stcts = gt_mege-ctsex
      and /sapsll/corcts~guid_pobj = gt_Sagmeld-guid_pobj.
    regards
    Arora

    Hi Arora,
    Using Package size is very simple and you can avoid the time out and as well as the problem because of memory.  Some time if you have too many records in the internal table, then you will get a short dump called TSV_TNEW_PAGE_ALLOC_FAILED.
    Below is the sample code.
    DATA p_size = 50000
    SELECT field1 field2 field3
       INTO TABLE itab1 PACKAGE SIZE p_size
       FROM dtab
       WHERE <condition>
    Other logic or process on the internal table itab1
    FREE itab1.
    ENDSELECT.
    Here the only problem is you have to put the ENDSELECT.
    How it works
    In the first select it will select 50000 records ( or the p_size you gave).  That will be in the internal table itab1.
    In the second select it will clear the 50000 records already there and append next 50000 records from the database table.
    So care should be taken to do all the logic or process with in select and endselect.
    Some ABAP standards may not allow you to use select-endselect.  But this is the best way to handle huge data without short dumps and memory related problems. 
    I am using this approach.  My data is much more huge than yours.  At an average of atleast 5 millions records per select.
    Good luck and hope this help you.
    Regards,
    Kasthuri Rangan Srinivasan

  • How to make this code go faster?

    Hi,
    I have this code and its really slow. My question is how to make it faster since its taking about 10 hours.
    Code:
      loop at ti_equi.
        select matnr sernr lief_nr kunde datum uzeit bwart posnr
    appending corresponding fields of table ti_ser01
          from z_objk_ser01
         where sernr eq ti_equi-sernr
           and matnr eq ti_equi-matnr.
      endloop.
      delete ti_ser01 where not ( kunde in s_kunnr and
                                  bwart = '631' ).
      sort ti_ser01 by matnr sernr datum descending uzeit descending.
      delete adjacent duplicates from ti_ser01 comparing matnr sernr.
    What this code does is fetch all these fields and then just keeps the one that's been modified at last.
    I have created an index by sernr and matnr in table objk which makes it just a little bit faster.
    Any helpful answer will be appreciated.
    Regards,
    Roberto
    Edited by: Julius Bussche on Jan 27, 2009 4:29 PM
    Code tags added. Please use more meaningfull subject titles

    Hi roberto
    please avoid select statment inside loop.
    use code
    data: index type sy-tabix.
    data : ti-ser011 type standard table of zobjk-ser01 with header line.
    select matnr sernr lief_nr kunde datum uzeit bwart posnr
          from z_objk_ser01 into table ti_ser01.
    sort ti_ser01 by sernr matnr.
    sort ti_equi by sernr matnr.
    index = 1.
    loop at ti_equi.
        loop at ti_ser01 from index
         if  ti_ser01-sernr = ti_equi-sernr
              and ti_ser01-matnr = ti_equi-matnr.
            move-corresponding ti_ser01 to ti_ser011.
            append ti_ser011.
            index = sy-tabix.
            exit.  
         endif.
        endloop.
    endloop.
    here i have used one more internal table ti_ser011.
    you can delete specific record from ti_ser01 internal table on condition. at that time u don't need to create any other internal table like ti-ser011.
    in place of loop select statement---endloop.
    you can use this code. I think it will help you.
    please find if it is udeful.

  • How to convert this select statement into update

    Hai All
    I have two table Namely Daily_attend , Train_mast
    Daily_attend Consist Of fields are Train_mast consist Of fields are
    Name varchar Train no var
    Empcode Num T_date date
    Intime Date Train_name var
    Outtime date Late_hrs var
    IND_IN Number
    IDE_OUT Number
    Attend_date date
    I need to update IDE_IN In Daily_attend table Depend upon late_hrs in the Train_mast table
    I have got Through in select statement This is my select statement
    select to_number(TO_DATE(TO_CHAR(Intime,'DD-MON-YYYY')||' '||
    TO_CHAR(0815,'0000'),'DD-MON-YYYY HH24:MI')+late_hrs/(24*60)-intime
    ) * 24*60 from dail_Att,train_mast;
    How can i convert it to update
    Any help is highly appricateable
    Thanks In Advance
    Regards
    Srikkanth.M

    Srikkanth,
    Try this code. And 1 more thing, i can't see any WHERE condition to join between the 2 tables DAIL_ATT, TRAIN_MAST.
    UPDATE DAIL_ATT A SET A.IDE_IN = (SELECT TO_NUMBER(TO_DATE(TO_CHAR(INTIME, 'DD-MON-YYYY')|| ' ' || TO_CHAR(0815, '0000'), 'DD-MON-YYYY HH24:MI') + LATE_HRS / (24 * 60) - INTIME) * 24 * 60 FROM TRAIN_MAST B WHERE <condition>);Regards,
    Manu.
    If my response or the response of another was helpful or Correct, please mark it accordingly

  • How to make this query go faster

    Hi ,
    I have the following query :
    select a.* from
    tbl1 a , tbl2 b
    where a.id = b.id
    substr(b.id , 3, 2) <> 'XX'
    and b.date1 is not null
    and b.date1 >= sysdate - 90 ;
    tbl1 - 21 million rows
    tbl2 - 2 millions
    i specify this hints /*+ INDEX(idxa_1 , idxa_2) INDEX(ixdb_1)
    where idxa_1 --> b.lotid
    idxa_2 --> b.date1
    idxb_1 --> a.lotid
    IF i DO NOT include b.date1 is not null and b.date1 >= sysdate - 90 ,
    from explain plan i could see it using a FAST FULL SCAN which really returns very fast
    HOWEVER if i include b.date1 is not null and b.date1 >= sysdate - 90
    , from explain plain it uses row index and then there's a range scan and its slow
    how can i improve the performance of this query ?
    pls advise
    tks & rdgs

    Don't create the temporary table.
    Create a function based index on table two
    substr(id , 3, 2)Make sure you have gathered statistics on the tables.
    Remove the hint.
    select a.* from
    tbl1 a , tbl2 b
    where a.id = b.id
    and substr(b.id , 3, 2) <> 'XX'
    and b.date1 >= sysdate - 90;If you still have performance problems, post the formatted explain plan from sqlplus.
    Read the Performance Tuning Guide.
    Unfortunately this is not urs advice.

  • Re: How to make this forum run fast

    I counted till eleven, but since I'm a rather quick counter, I'd say about 7 seconds as well.
    Could it be that y'all are using Firefox? I'm on IE7.
    &reg;
    (suspecting commie influence since '77)

    sabre150 wrote:
    kajbj wrote:
    CeciNEstPasUnProgrammeur wrote:
    I counted till eleven, but since I'm a rather quick counter, I'd say about 7 seconds as well.
    Could it be that y'all are using Firefox? I'm on IE7.
    &reg;
    (suspecting commie influence since '77)Strange. I tried with IE 7. Loading the main page, about 45 seconds, loading this thread about 30 seconds, getting to the reply page about 3-4 seconds.I find the site blindingly fast! Certainly less than 45 seconds to load the man page and very very much less that 30 seconds for this page. Both typically 1 second with the login page taking about 3 seconds.
    Now if only I could access ALL the pages without Server Error
    This server has encountered an internal error which prevents it from fulfilling your request. The most likely cause is a misconfiguration. Please ask the administrator to look for messages in the server's error log.
    What forum? id 5?

  • How to Correct this Select Statement...?

    hi all
    i wrote a select as follows
    select datediff('HH',to_date(job_start,'hh24:mi:ss'),to_date('15:29:59','hh24:MI:ss')) from shift
    requirement is to calculate the hours used in a shift, the job_start column is date type and having value '23/08/2007 07:00:00' , and the second one is the shift end time. so it should give 8.5 hrs as the result. but it is throwing error ORA--1858 non-numeric char found where a numeric expected. datediff function is taken from Ask Tom discussion forums.
    any idea...?
    regards
    Kris

    I think i cant, this is to be done for every day...so
    is there any way i can set the time of the current
    date to '15:29:59'..?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('23/08/2007 08:30:00','dd/mm/yyyy hh24:mi:ss') as start_time from dual)
      2  -- end of test data
      3  select (to_date(to_char(sysdate,'dd/mm/yyyy')||'  15:29:59','dd/mm/yyyy hh24:mi:ss')-start_time)*24 as hrs
      4* from t
    SQL> /
           HRS
    6.99972222
    SQL>

  • Make this select query to Select Insert query

    Hi,
    How to make this select query to select Insert query..
    ;WITH DateDim AS
    SELECT CAST('1900-01-01' AS DATETIME) StartDate
    UNION ALL
    SELECT StartDate + 1
    FROM DateDim
    WHERE StartDate + 1 <= '2099-12-31'
    SELECT CAST(CONVERT(CHAR(8),CAST(StartDate AS DATETIME),112) AS INT) AS DateKey
    , StartDate
    , DATEPART(dw, StartDate) AS DayNumberOfWeek
    , DATENAME(dw, StartDate) AS EnglishDayNameOfWeek
    , DAY(StartDate) AS DayNumberOfMonth
    , (CASE WHEN MONTH(StartDate)>=1 AND MONTH(StartDate) <=6 THEN 1 ELSE 2 END) AS CalendarSemester
    FROM DateDim 
    OPTION (MAXRECURSION 0) 
    GO

    The final solution is                            
     ;WITH DateDim AS
    SELECT CAST('1900-01-01' AS DATETIME) StartDate
    UNION ALL
    SELECT StartDate + 1
    FROM DateDim
    WHERE StartDate + 1 <= '2099-12-31'
    SELECT CAST(CONVERT(CHAR(8),CAST(StartDate AS DATETIME),112) AS INT) AS DateKey
    , StartDate
    , DATEPART(dw, StartDate) AS DayNumberOfWeek
    , DATENAME(dw, StartDate) AS EnglishDayNameOfWeek
    , DAY(StartDate) AS DayNumberOfMonth
    , (CASE WHEN MONTH(StartDate)>=1 AND MONTH(StartDate) <=6 THEN 1 ELSE 2 END) AS CalendarSemester
    Into new_tablenameFROM
    DateDim 
    OPTION (MAXRECURSION 0) 
    GO

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • In how many ways we can filter this select statement to improve performance

    Hi Experts,
    This select statement taking 2.5 hrs in production, Can we filter the where condition, to improve the performance.Plz suggest with coding ASAP.
    select * from dfkkop into  table t_dfkkop
               where   vtref   like 'EPC%'        and
                   ( ( augbd      =  '00000000'   and
                       xragl      = 'X' )
                               or
                     ( augbd between w_clrfr and  w_clrto )  )  and
                       augrd      ne '03'         and
                       zwage_type in s_wtype .
    Regards,
    Sam.

    if it really takes 2.5 hours, try the followingtry to run the SQL trace and
    select *
              into table t_dfkkop
              from dfkkop
              where vtref like 'EPC%'
              and augbd = '00000000' and xragl
             and augrd ne '03'
             and zwage_type in s_wtype .
    select *
              appending table t_dfkkop
              from dfkkop
              where vtref like 'EPC%'
             and augbd between w_clrfr and w_clrto 
             and augrd ne '03'
             and zwage_type in s_wtype .
    Do a DESCRIBE TABLE after the first SELECT and after the second,
    or run an SQL Trace.
    What is time needed for both parts, how many records come back, which index is used.
    Siegfried

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

  • How to make a SELECT LIST READONLY

    Hi,
    I have a form to update the existing values in a table. Primary column is based on a Select List.
    So when user goto update screen they SHOULD NOT BE ABLE TO CHANGE the primary filed(means the value display in the Select List).
    SO to make this one I have make that select list read only. But not like other items even when we make select list read only it still allow user to change the value. So basically read only property not working for select text.
    There are many post in this regading same issue. Some of them recomended to make it disabled. But when we make a item disabled then when user POST that form, Apex not POST any disabled item values. Basically disabled items values not passing next form. So making item dissable also not a solution.
    I have read almost 20 post in here regarrding this and didnt get any solution for this. So please let me know if anyone knows how to make a select list read only (which is working same as read only text boxes, means that value pass when user POST the form).
    Thanks in advance...
    mc

    You define a function(this is based aorund jQuery selectors) in the page header like
    <script>
      var makereadonly = function(selector, makeReadonly) {
          $(selector).filter("select").each(function(i){
              var select = $(this);
              //remove any existing readonly handler
              if(this.readonlyFn) select.unbind("change", this.readonlyFn);
              if(this.readonlyIndex) this.readonlyIndex = null;
              if(makeReadonly) {
                  this.readonlyIndex = this.selectedIndex;
                  $(this).css('background-color','#CDCDCD'); //Adds a background colour to readonly item
                  this.readonlyFn = function(){
                      this.selectedIndex = this.readonlyIndex;
                  select.bind("change", this.readonlyFn);
          //For input items
          $(selector).filter("input,textarea").attr('readOnly','readOnly');
          $(selector).filter("input,textarea").css('background-color','#CDCDCD');
    </script>and apply it using a jQuery selector (call it in the "execute on page load" or any other JS code)
      makereadonly('#ITEMNAME1,#ITEMNAME2,#ITEMNAME3',true);Not that all of these methods(that act at the client side) will only prevent the user from modifying it 'normally', they could manipulate these readonly items using Javascript(or using firebug or any tool like that). So its better to make sure that your don't use the item value(from the page) for processing.

  • How to speed a select statement with the NOT EXISTS where condition ?

    Hi all,
    I created a view : create or replace view view_name as select * from table_1,table_2 where join_condition and some conditions.
    Now I have added in the view "where" clause two NOT EXISTS conditions based on one another different table respectively.
    Before I added these two conditions the response time was fast ; but after I added these two conditions then the response time deteriorated.
    So how to optimize the select statement ? Hints and so on ...
    Thank you very much indeed
    Message was edited by:
    andrianiaina

    Just run the script :
    SQL> explain plan for select * from dual;
    Explained.
    SQL> @$ORACLE_HOME/rdbms/admin/utlxpls.sql
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |       |       |       |
    |   1 |  TABLE ACCESS FULL   | DUAL        |       |       |       |
    Note: rule based optimization
    9 rows selected.
    SQL>Nicolas.

  • How to make this work with Firefox, HELP!

    Downloading for Real-player, after watching the full movie, I click download and it has to reread the movie from the internet. When using explorer, after downloading the movie, it reads it from memory, which makes it a fast download. How to make this work with Firefox, I like not to use Microsoft products, and I really like Firefox 7.0.1!!!! HELP!

    -> click '''Firefox''' button and click '''Options''' (OR File Menu -> Options)
    * Advanced panel -> Network tab
    * place Checkmark on '''Override Automatic Cache Management''' -> under '''Limit Cache''' specify a large size of space
    * Remove Checkmark from '''Tell me when websites asks to store data for offline use'''
    * click OK on Options window
    * Restart Firefox
    Check and tell if ts working.

  • How to make it selected when clicked and open popup

    Hi,
    I 've a form in the parent page with many form elements.
    I've 2 radio buttons with values "Yes" and "No". I am opening a modal popup when clicked on "Yes" radio button. The modal popup is opening fine.
    But when I click "Yes", it' s not selected. After modal popup is closed, when I return to parent page, the option "Yes" is still not selected.
    How to make it selected when clicked and open popup?

    Perhaps try moving the application to your preferred desktop and then right-click it's dock icon > options > Assign to This Desktop.

Maybe you are looking for