Small doubt in select query

i want to count the no. of employees whose endda = '31/12/9999' and stat2 = '3'.
tables are pa0000.
can anyone tell me the select query?

DATA: w_noemp TYPE i.
SELECT COUNT(*) INTO w_noemp FROM  pa0000
       WHERE  endda  = '99991231'
       AND    stat2  = '3'.

Similar Messages

  • Doubts in Select query

    Hai,
    I have problem in my select query,
    My previous select query:
      SELECT  rrcty 
            ryear 
            rbukrs
            rzzpspid 
            SUM( hslvt )
            SUM( hsl01 )
            SUM( hsl02 )
            SUM( hsl03 )
            SUM( hsl04 )
            SUM( hsl05 )
            SUM( hsl06 )
            SUM( hsl07 )
            SUM( hsl08 )
            SUM( hsl09 )
            SUM( hsl10 )
            SUM( hsl11 )
            SUM( hsl12 )
            SUM( mslvt )
            SUM( msl01 )
            SUM( msl02 )
            SUM( msl03 )
            SUM( msl04 )
            SUM( msl05 )
            SUM( msl06 )
            SUM( msl07 )
            SUM( msl08 )
            SUM( msl09 )
            SUM( msl10 )
            SUM( msl11 )
            SUM( msl12 )
             FROM zzsl5t
           INTO TABLE it_erbproj
             WHERE rldnr       EQ  c_rldnr        AND
                rrcty      EQ  c_rrcty        AND
                ryear       EQ  v_srr_fyear    AND
                rbukrs      EQ  v_srr_ccode    AND
                racct      EQ  v_racct        AND
                rzzpspid  IN r_zzpspid         
             GROUP BY  RRCTY ryear RBUKRS rzzpspid.
    now i want change the above select query as,
    If user enters input period 03 means,
    i have to select
    SELECT  rrcty 
            ryear 
            rbukrs
            rzzpspid 
            SUM( hslvt )
            SUM( hsl01 )
            SUM( hsl02 )
            SUM( hsl03 )
            SUM( mslvt )
            SUM( msl01 )
            SUM( msl02 )
            SUM( msl03 )
    only, not to select all the periods.
    how can i give fields dynamically.
    please suggest me.
    Elamaran

    Duplicate message. Please close this one and look at my answer Doubt in Select query.

  • Doubt in SELECT query (11.2.0.2.0)

    I have 3 tables
    1. ADBO.SECMASTER_DTL_EXT_HST_TBL
    2. BDBO.SECMASTER_DETAIL_EXT_HIST
    3. ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL
    ADBO.SECMASTER_DTL_EXT_HST_TBL and BDO.SECMASTER_DETAIL_EXT_HIST have exactly the same table structure.
    Now, I need to find out the records from table BDO.SECMASTER_DETAIL_EXT_HIST with the max effective_date
    which do not match to the effective_date in ADBO.SECMASTER_DTL_EXT_HST_TBL. In the results table I need to report the diff effective dates from the 2 tables if they do not match.
    Also, SRC_INTFC_INST has to be 140 in both 1 and 2 tables. Further security_alias of table 1 has to match with spoke_sec of table 3
    and security_alias of table 2 has to match with hub_sec of table 3.
    For the data I have , I am getting 2 rows whereas I am expecting only 1 row. Can anyone suggest why this is so??
       SELECT
             B.SECURITY_ALIAS,
              TO_CHAR (C.SPOKE_PAID),
              A.SECURITY_ALIAS,
              TO_CHAR (C.HUB_PAID),
              'SECMASTER_DETAIL_EXT_HIST',
              'EFFECTIVE_DATE',
              NVL ( (CAST (B.EFFECTIVE_DATE AS VARCHAR2 (100))),
                   'No Records Found'),
              NVL ( (CAST (A.EFFECTIVE_DATE AS VARCHAR2 (100))),
                   'No Records Found')
         FROM ADBO.SECMASTER_DTL_EXT_HST_TBL  A,
              (SELECT SECURITY_ALIAS, EFFECTIVE_DATE, SRC_INTFC_INST
                 FROM [email protected]) B,
              ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL C
        WHERE     A.SRC_INTFC_INST = 140
              AND B.SRC_INTFC_INST = 140
              AND A.SECURITY_ALIAS = C.spoke_sec
              AND b.security_alias = C.HUB_SEC
              AND TO_CHAR (a.effective_date,'DD-MON-YYYY')
               <> TO_CHAR((SELECT MAX (h.effective_date)
                        FROM [email protected] H                    
                         where h.security_alias = b.security_alias
                             AND h.src_intfc_inst = b.src_intfc_inst), 'DD-MON-YYYY')
            and a.security_alias='6313';
    Insert into ADBO.SECMASTER_DTL_EXT_HST_TBL
       (SECURITY_ALIAS, SRC_INTFC_INST, EFFECTIVE_DATE)
    Values
       (6313, 140, TO_DATE('05/15/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into BDBO.SECMASTER_DETAIL_EXT_HIST
       (SECURITY_ALIAS, SRC_INTFC_INST, EFFECTIVE_DATE)
    Values
       (327667, 140, TO_DATE('05/20/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into BDBO.SECMASTER_DETAIL_EXT_HIST
       (SECURITY_ALIAS, SRC_INTFC_INST, EFFECTIVE_DATE)
    Values
       (327667, 140, TO_DATE('05/15/2013 00:00:00', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL
       (SPOKE_PAID, SPOKE_SEC, LAST_HELD_DATE, PREV_HELD_DATE, HUB_PAID, HUB_SEC)
    Values
       ('L3083                                                                                        ', 6313, TO_DATE('07/18/2013 22:15:46', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('07/15/2013 22:15:30', 'MM/DD/YYYY HH24:MI:SS'), 'L3083                                                                                        ',
        327667);
    CREATE TABLE ADBO.SECMASTER_DTL_EXT_HST_TBL
      SECURITY_ALIAS                  NUMBER        NOT NULL,
      SRC_INTFC_INST                  NUMBER        NOT NULL,
      EFFECTIVE_DATE                  DATE          NOT NULL
    CREATE TABLE BDBO.SECMASTER_DETAIL_EXT_HIST
      SECURITY_ALIAS                  NUMBER,
      SRC_INTFC_INST                  NUMBER,
      EFFECTIVE_DATE                  DATE
    CREATE TABLE ADBO.SPOKE_TO_HUB_SEC_MTCH_TBL
      SPOKE_PAID      VARCHAR2(100 BYTE),
      SPOKE_SEC       NUMBER,
      LAST_HELD_DATE  DATE,
      PREV_HELD_DATE  DATE,
      HUB_PAID        VARCHAR2(100 BYTE),
      HUB_SEC         NUMBER

    Hi,
    one suggestion. Don't include schema in the table.
    I have created your tables in my db with the following names:
    a_secmaster_dtl_ext_hst_tbl
    b_secmaster_detail_ext_hist
    spoke_to_hub_sec_mtch_tbl
    You query may be solved in this way maybe, according to what I have understood in the previous post.
    with table_a as
       select a.security_alias
            , c.spoke_paid
            , c.hub_paid
            , a.effective_date
         from a_secmaster_dtl_ext_hst_tbl  a
              join spoke_to_hub_sec_mtch_tbl c
                 on (a.security_alias=c.spoke_sec)
        where a.src_intfc_inst = 140
          and a.effective_date = (select max(a2.effective_date)
                                    from a_secmaster_dtl_ext_hst_tbl a2
                                   where a.security_alias=a2.security_alias
                                     and a.src_intfc_inst=a2.src_intfc_inst)
    , table_b as
       select b.security_alias
            , c.spoke_paid
            , c.hub_paid
            , b.effective_date
         from b_secmaster_detail_ext_hist  b
              join spoke_to_hub_sec_mtch_tbl c
                 on (b.security_alias=c.hub_sec)
        where b.src_intfc_inst = 140
          and b.effective_date = (select max(b2.effective_date)
                                    from b_secmaster_detail_ext_hist b2
                                   where b.security_alias=b2.security_alias
                                     and b.src_intfc_inst=b2.src_intfc_inst)
    select b.security_alias
         , a.spoke_paid
         , a.security_alias
         , b.hub_paid
         , 'SECMASTER_DETAIL_EXT_HIST' txt1
         , 'EFFECTIVE_DATE'            txt2
         , nvl(to_char(b.effective_date,'dd-mon-yyyy'), 'No Records Found') b_eff_date
         , nvl(to_char(a.effective_date,'dd-mon-yyyy'), 'No Records Found') a_eff_date   
      from table_a a full outer join table_b b on(a.spoke_paid=b.hub_paid)
    where a.effective_date!=b.effective_date;
    I have used full outer join to join the table to cover the case where records are present in table a and not in table b and the opposite.
    Regards.
    Alberto

  • Doubt in Select Query

    Hi,
    I want to get data from 2 table which query is effeicient one
    by seeing performance...
    1. using for all entries statement
    2. Get data using join query.
    Thanks in advance

    FOR ALL ENTRIES is better for some reasons,
    --> If the data is huge , then some times JOIN may end up in TIME OUT error
    --> FOR ALL ENTRIES will use the INDEXEs of the tables and improves the performance

  • Select query is correct or not

    hai to all iam software trainee in core java
    i have doubt on select query please give gudiance
    select * from StudentDetails where Admnno=' "
    i connected my application with ms-access db using jdbc-odbc
    my question is i want retrieve data from ms-access so i use this select query is it correct or not
    because
    select * from StudentDetails this query working but it's working with where condition please help and try to understand my question
    In advanced
    thanks

    ("select * from StudentDetails where Admnno ='' "+Admnno+"'")Is Admnno a numeric or character field? Either way, that syntax looks wonky.
    For a numeric field:("select * from StudentDetails where Admnno = " + Admnno)and for a character field("select * from StudentDetails where Admnno = '" + Admnno + "'")db
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the tags that appear.

  • Doubt In a Select Query..

    Hi..
    I have a Doubt in a simple Query from the table NAST.
    My query is as follows:--
    Select kappl
           objky
           kschl
           parnr
           parvw
           nacha
           vsztp
    from nast into table vit_nast
    where kappl =   p_kappl
    and   kschl in s_kschl
    and   parnr in s_parnr
    and   nacha =   p_nacha
    and   vsztp in s_vsztp.
    Now I want to select all the NAST records which are either not processed (NAST-VSTAT = 0) or incompletely processed (NAST-VSTAT = 2)(the field in the table NAST is VSTAT which denotes the Processing status of message)
    So Can I add both the conditions in the WHERE clause of the the above Select Query?
    Is there any other optimised way I can do that?
    Thanks

    ranges: r_stat for nast-vstat.
    r_stat-low = '0'.
    r_stat-option = 'EQ'.
    r_stat-sign = 'I'.
    append r_stat.
    clear r_stat.
    r_stat-low = '2'.
    r_stat-option = 'EQ'.
    r_stat-sign = 'I'.
    append r_stat.
    clear r_stat.
    Select kappl
    objky
    kschl
    parnr
    parvw
    nacha
    vsztp
    from nast into table vit_nast
    where kappl = p_kappl
    and kschl in s_kschl
    and parnr in s_parnr
    and nacha = p_nacha
    and vsztp in s_vsztp
    <b>and vstat in r_stat.</b>
    check this..
    Regards
    vijay

  • 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

  • Splitting complex SQL select query in to independent sequence of small queries.

    =====================
    Problem Description
    =====================
    Consider I have the following table structures with approx no. of records in each.
    Employee Table
    emp_id:
    name :
    dept_id:
    #Approx no. of rows in the table: 1 million
    Department Table
    dept_id:
    dept_name:
    #Approx no. of rows in the table: 1 Hundred
    =====================
    Target Result: is to get the employee name who's id is '100' and the department name he belongs to.
    =====================
    =====================
    Ideal Query : Consider it as COMPLEX QUERY
    =====================
    select emp.name,dept.name
    from     employee emp, department dept
    where      
         emp.dept_id = dept.dept_id
         and
         emp.emp_id = '100';
    =====================
    Optimized Independent Queries : Consider it as SIMPLE QUERIES
    =====================
    Now i want to split the above query in to two independent queries.
    Query #1
    select emp.name
    from     employee emp
    where emp.id = '100';
    :: Returns one row as emp.id is unique.
    Query #2
    select dept.dept_id, dept.name
    from department dept
    :: Returns 100 rows as there are only 100 rows.
    =====================
    Need Your Suggestions Here
    =====================
    If you compare the COMPLEX QUERY against SIMPLE QUERIES, i prefer to use SIMPLE QUERIES, get the results
    and compare department id against two results programmatically and then get the final result. I know the database
    query engines will do similar query optimization like dividing COMPLEX QUERY to SIMPLE QUERIES and run them
    in some specific order to get results faster.
    Now is it possible to get the exact sub queries which the database query engine (ANY database query engine) generates
    out of complex select query? I mean i don't want to do the splitting manually but i still need those sub-queries.
    Can any one help me out please?

    Why on earth would you want to keep the queries separate? As Tom Kyte would say, databases are born to join!
    Providing emp_id has an index on it (and it should, assuming it's the table's primary key!) your "complex" (or, what I would call simple*), it'll most likely be faster than doing it separately. You've not got the context switches for one thing.
    If you want to see what the optimizer does with your query, you should run a trace on the query. An explain plan would give you an idea of what it's going to do, too.
    In general, doing something like this procedurally is going to almost certainly be worse than doing it in SQL (and by worse, I mean slower).
    * I'd hate to see what you'd call some of the monster queries I work with, if you think that query is complex!

  • Select query doubt

    hello all,
    i am writting this code .....first select is working fine for me as i am getting 5 entires in  table itab which i am expecting...
    but for second when i loop itab itab then at that time i should get one record  in table itab2 out of second select query........
    but as i can see while debugging  i am getting that entry at third time when i am in loop.....but it again i think it overwrites with next enter and making itab2 entry as 0 at the end.....
    what might be problem.
    even i write append itab2.
                        clear itab2.
    same error i am getting...(here CDPOS is cluster table..is this because of this??)..pease help
    selection-screen:begin of block test with frame title new.
    select-options: s_ddate for vbak-vdatu.
    selection-screen:end of block test.
    select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab
        from vbak as a inner join vbap as b on avbeln = bvbeln where
           b~matnr = 'AUP-501'
        and a~vdatu in s_ddate.
    LOOP AT ITAB.
    select *  from CDPOS into table itab2 where
      OBJECTID = ITAB-VBELN AND
      TABNAME = 'VBAP' AND
      FNAME = 'NETPR'.
    ENDLOOP.

    Hi,
    You are completely into wrong performance..
    as per your query
    selection-screen:begin of block test with frame title new.
    select-options: s_ddate for vbak-vdatu.
    selection-screen:end of block test.
    select avbeln avdatu bnetpr bnetwr b~matnr into corresponding fields of table itab
    from vbak as a inner join vbap as b on avbeln = bvbeln where
    b~matnr = 'AUP-501'
    and a~vdatu in s_ddate.
    LOOP AT ITAB.
    select * from CDPOS into table itab2 where
    OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND
    FNAME = 'NETPR'.
    ENDLOOP.
    The second query is inside loop and its moving data into itab2 for every record in internnale table ITAB and
    finally itab2 contains the last records of ITAB data if CDPOs has the data for itab-vbeln(last records).
    To over come you need to write the select as beloew
    select * from CDPOS APPENDING table itab2 where
    OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND
    FNAME = 'NETPR'.
    But I suggest you to write for all entries
    select <the filed you need> from CDPOS
    into table itab2
    for all entries in itab
    where OBJECTID = ITAB-VBELN AND
    TABNAME = 'VBAP' AND FNAME = 'NETPR'.
    Then
    loop at ITAB.
    Read table itab2 with key vbeln = itab-vbeln binary search.
    If sy-subrc = 0.
    <Write your code, functions etc>.
    endif.
    endloop.
    regards,
    Nazeer

  • Select query is not executing

    Hi Friends,
    my code is :
    itab-vbeln = bseg-vbeln.
    if not itab-vbeln is initial.
    select single vbeln inco1 inco2 into ( itab-vbeln itab-inco1 itab-inco2)
    from vbrk where vbeln = itab-vbeln.
    appned itab.
    note : here inco1 inco2 are incoterms
    my question is  can we direct move the values of bseg-vbeln into itab-vbeln. ???
    and i am generating the report with one varient , when i debug this report the
    there is no value in bseg-vbeln. it is showing null value.thats why my select query is not working..but i want execute this select query final.
    in output i want display the inco1 inco2 data.(incoterms)
    any help please.
    urgent.
    regards,
    vijay.

    Hi Vijay,
    First you need to check it out whether <b>itab-vbeln = bseg-vbeln</b> is in with in LOOP or not (<b>if ITAB is intenal table</b>)
    if itab is internal table you should write above statement with in loop, and also check it out in debug mode why bseg-vbeln value is not coming.
    and one more thing you need to make small correction in ur code use ',' .
    select single vbeln inco1 inco2 into ( <b>itab-vbeln, itab-inco1, itab-inco2</b>)
    from vbrk where vbeln = itab-vbeln
    Note: when ever use select single u should pass values into work area, dont use internal table .
    <b>if you have more doubts just send your entire code then i will rewrite it.</b>
    <b>Reward with points if useful.</b>
    Regards,
    Vijay Krishna

  • Improving a SELECT query

    I have an interactive application that periodically feeds a legacy batch transaction application with data to keep it in sync with my app. For demonstrating my problem I am using a similar but much simpler example here, using two tables only: CUST and ORD. The CUST table contains customer specific data and the ORD table contains orders placed by each customer. The primary key of CUST table is the CU_CODE that is also a foreign key (OR_CU_CODE) in the ORD table. The PK of ORD table is the OR_CODE column. See their description below:
    Table: CUST
    Name               Null?     Type
    CU_CODE          NOT NULL     VARCHAR2(6)
    CU_TYPE          NOT NULL     VARCHAR2(2)
    CU_NAME          NOT NULL     VARCHAR2(80)
    CU_ADDR                    VARCHAR2(120)
    Table: ORD
    Name               Null?     Type
    OR_CODE          NOT NULL     VARCHAR2(8)
    OR_CU_CODE          NOT NULL     VARCHAR2(6)
    OR_DATE          NOT NULL     DATE
    OR_TERMS               VARCHAR2(40)
    The legacy app needs to get both a customer and an order transaction for any order whose date is more recent than a given date. To create those transactions, I run a SELECT query like this:
    SELECT 'UPD,CUST='||CU_CODE||',TYPE='||CU_TYPE||',NAME='||CU_NAME
    ||',ADDR='||CU_ADDR
    FROM (SELECT DISTINCT CU_CODE, CU_TYPE, CU_NAME, CU_ADDR
    FROM CUST, ORD WHERE OR_CU_CODE = CU_CODE
    AND OR_DATE > SOME_DATE
    ORDER BY 1)
    UNION ALL
    SELECT 'UPD,ORD='||OR_CODE||',CUST='||OR_CU_CODE||',DATE='
    ||TO_CHAR(OR_DATE, 'YYYYMMDD')||',TERMS='||OR_TERMS
    FROM (SELECT OR_CODE, OR_CU_CODE, OR_DATE, OR_TERMS
    FROM ORD WHERE OR_DATE > SOME_DATE
    ORDER BY 2, 1);
    This produces a batch update transaction file similar to the following:
    UPD,CUST=CU1111,TYPE=COM,NAME=ACME,ADDR=ACME Address
    UPD,CUST=CU2222,TYPE=RES,NAME=John Q,ADDR=John Q Address
    UPD,CUST=CU3333,TYPE=GOV,NAME=IRS,ADDR=IRS Address
    UPD,ORD=OR001234,CUST=CU1111,DATE=20061204,TERMS=Term1
    UPD,ORD=OR001235,CUST=CU1111,DATE=20061206,TERMS=Term1
    UPD,ORD=OR001236,CUST=CU1111,DATE=20061207,TERMS=Term1
    UPD,ORD=OR002234,CUST=CU2222,DATE=20061205,TERMS=Term2
    UPD,ORD=OR002235,CUST=CU2222,DATE=20061207,TERMS=Term2
    UPD,ORD=OR003237,CUST=CU3333,DATE=20070102,TERMS=Term3
    Both transaction types are sorted by the customer code first but customer update transactions also need a DISTINCT clause because we only want to send one custumer update per customer even if there were more orders placed by that customer.
    This thing has been working fine in most cases except when a large transaction file is generated because the legacy app can only handle input files of only certain max. size. In such cases the operators need to manually split up the file into several smaller ones but still making sure that each file segment has customer and order transactions belonging to the same customers only. This can be really tedious with hundreads of customers and their orders. The file splitting would be much easier if I could rewrite the original SELECT statement to produce the transaction data in the following order:
    UPD,CUST=CU1111,TYPE=COM,NAME=ACME,ADDR=ACME Address
    UPD,ORD=OR001234,CUST=CU1111,DATE=20061204,TERMS=Term1
    UPD,ORD=OR001235,CUST=CU1111,DATE=20061206,TERMS=Term1
    UPD,ORD=OR001236,CUST=CU1111,DATE=20061207,TERMS=Term1
    UPD,CUST=CU2222,TYPE=RES,NAME=John Q,ADDR=John Q Address
    UPD,ORD=OR002234,CUST=CU2222,DATE=20061205,TERMS=Term2
    UPD,ORD=OR002235,CUST=CU2222,DATE=20061207,TERMS=Term2
    UPD,CUST=CU3333,TYPE=GOV,NAME=IRS,ADDR=IRS Address
    UPD,ORD=OR003237,CUST=CU3333,DATE=20070102,TERMS=Term3
    Here a given customer update transaction would be followed by all orders for that customer and so on.
    I want the new query also in pure SQL, not in PL SQL. As dealing with DB and Oracle is only a small part of my job, I just can't figure out a solution to this problem. I suspect many of the regulars here can help me.
    Thanks,
    Joe
    PS: Sorry, the table descriptions looked much better in the edit screen but I hope you can still figure it out from the display window.

    Try something like the following (not tested)
    SELECT transaction FROM (
    SELECT CU_CODE,1,'UPD,CUST='||CU_CODE||',TYPE='||CU_TYPE||',NAME='||CU_NAME
    ||',ADDR='||CU_ADDR transaction
    FROM (SELECT DISTINCT CU_CODE, CU_TYPE, CU_NAME, CU_ADDR
    FROM CUST, ORD WHERE OR_CU_CODE = CU_CODE
    AND OR_DATE > SOME_DATE)
    UNION ALL
    SELECT OR_CU_CODE,2,'UPD,ORD='||OR_CODE||',CUST='||OR_CU_CODE||',DATE='
    ||TO_CHAR(OR_DATE, 'YYYYMMDD')||',TERMS='||OR_TERMS transaction
    FROM (SELECT OR_CODE, OR_CU_CODE, OR_DATE, OR_TERMS
    FROM ORD WHERE OR_DATE > SOME_DATE)
    ORDER BY 1,2;Basically, I added some columns to your query for sorting purposes then used that query as an inline view to only get the data you are interested in. Hope it runs. If not, let me know and I'll create the table and actually test it.

  • Select query in case of Multiple line items

    Hi Gurus ,
                  I've a doubt in general SQL select query. I want to know , if suppose I've an internal table - itab . I've fetched G/L Account numbers 1st, based on the input selections . Next , I want to loop on those G/L accounts. However, if the G/L account has multiple line items, then I personally use this select query -- >
    loop at itab.
    select <field> from <table> appending corresponding fields of  <itab1> where hkont eq itab-hkont.
    endloop.
    Now, the execution time for this query is longer than expected. The biggest problem here is, i've to sum up the totals as well. So totaling is an added load. I want to reduce the execution time of this. Kindly suggest me some good method in case u have any.
    I've pasted the code which I've written , for u ppl to understand--
    SELECT DISTINCT HKONT BELNR
      FROM BSIS
       INTO CORRESPONDING FIELDS OF TABLE OTAB
        WHERE HKONT IN S_RACCT
    *      AND PRCTR IN P_PRCTR
          AND MONAT IN S_POPER
          AND BUKRS EQ P_BUKRS
          AND GJAHR EQ P_GJAHR
          AND PRCTR IN S_PRCTR.
    ***The code below takes a lot of time to execute.***
    LOOP AT OTAB .
      SELECT DMBTR HKONT
      FROM BSIS APPENDING CORRESPONDING FIELDS OF TABLE CREDITS
        WHERE HKONT EQ OTAB-HKONT
          AND BELNR EQ OTAB-BELNR
          AND MONAT IN S_POPER
          AND BUKRS EQ P_BUKRS
          AND GJAHR EQ P_GJAHR
          AND PRCTR IN S_PRCTR
          AND SHKZG EQ 'H'.
      COLLECT CREDITS.
    ENDLOOP.

    Hi,
    First of all try to avoid doing select into corresponding fields. THis would improve the performance of the program.
    Try to do a single fetch from the BSIS table . fetch the hkont, belnr, dmbtr fields in to a master internal table. Manipulate and play with the data as required.  Don't hit the data base table more than once (unless it is required) . This would improve the performance of your code.
    Try to code this way.
    types: begin of ty_bsis,
                 hkont type hkont,
                 belnr type  belnr_d,
                 dmbtr type dmbtr,
              end of ty_bsis.
    data: it_bsis type standard table of ty_bsis,
             wa_bsis type ty_bsis,
    select hkont belnr dmbtr
              from bsis
              into table it_bsis
              WHERE HKONT IN S_RACCT
            AND PRCTR IN P_PRCTR
              AND MONAT IN S_POPER
             AND BUKRS EQ P_BUKRS
             AND GJAHR EQ P_GJAHR
              AND PRCTR IN S_PRCTR.
    Using the data availabe in the it_bsis, you can manipulate as required.
    Hope this would be helpful
    Regards
    Ramesh Sundaram

  • Select query in not working for Count(*)

    Hi,
    Our batch team running one query that is selecting one table TSFHEAD and this query is hanging. Below are diffrent shenario in which the select query is running on this table.
    select * from tsfhead where create_id = 'BATCH' and create_date = '26-OCT-12';
    --not returning any rows and hanging
    select * from tsfhead where create_id = 'BATCH' ---returning rows
    select * from tsfhead where create_date = '26-OCT-12'; --- returning rows
    select count(*) from tsfhead ----not returning rows and hanging
    This table TSFHEAD has 59000 rows.
    SQL> explain plan for select * from tsfhead where create_id = 'BATCH' and create_date = '26-OCT-12';
    Explained.
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 415503093
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 67 | 215 (1)| 00:00:03 |
    |* 1 | TABLE ACCESS FULL| TSFHEAD | 1 | 67 | 215 (1)| 00:00:03 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
    1 - filter("CREATE_ID"='BATCH' AND "CREATE_DATE"='26-OCT-12')
    I don't know why this query behaving in this manner.Please help.

    RanVijai_dba wrote:
    Thanks for your reply. But +"select count(*) from tsfhead"+ is hanging and +"select * from tsfhead where create_date = '26-OCT-12' "+ is showing records.It might be showing records, but not necessarily the correct records.
    As sb points out, you are treating dates as strings rather than the DATE datatype. That means you could be querying the wrong data, and your query is also not safe in different environments. It could also effect the query execution plan. Also, as pointed out, you should be ideally using 4 digit years. There were many headaches caused by the use of 2 digit years that most companies corrected as part of the millenium bug fixes prior to the year 2000... well over a decade ago, and most good designs now ensure that 4 digit years are used as standard.
    So your query would be better written as:
    select * from tsfhead where create_date = TO_DATE('26-OCT-2012','DD-MON-YYYY')When you say:
    select count(*) from tsfhead... is hanging, you say the table has around 59000 rows in it, and in reality that's a small amount of records, so a count(*) shouldn't take long at all, even doing a full table scan.
    Post the explain plan for that simple count(*) query for us. (and ensure you use {noformat}{noformat} tags to keep the formatting on the forum, as described in {message:id=9360002})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Select query written on view giving dump

    Hi All,
    I have written the following query on COAS view in my code:
          SELECT aufnr bukrs INTO TABLE gt_aufnr
            FROM coas
              WHERE
                    aufnr IN r_aufrm AND
                    auart IN s_auart AND
                    autyp = c_autyp_01 AND
                    kokrs = c_kokrs_mbca.
    When records in range r_aufrm are too many like 6000 or so it gives me a run time error on this query - DBIF_RSQL_INVALID_RSQL. Error description says size of select query is large.
    Question : Is this bug coming because I am using the view. If i select the records on table AUFK (only table on which the view is created), will it rectify the problem?? I am asking this because it's in production and I cant make any change and test then and there.
    Note: the range r_aufrm contains two types of records for AUFNR - 1. with sign GE and others with sign LE. So I cannot use for all entries. If I still can, please tell me how?
    Thanks a looot!
    Waiting for the response,
    Navita

    Thanks All!!
    I think, this range limit has caused the problem. Range limit is 999 records.
    Just one question I have. At runtime when I check the number of entries in r_aufrm in the query, I get 6000 entries. So, does it allow 6000 records to enter the range variable even if it has a limit of 999. Is it the case that, in select query only it will throw a dump if records in range exceed 999??
    SELECT aufnr bukrs INTO TABLE gt_aufnr
    FROM coas
    WHERE
    aufnr IN r_aufrm AND
    auart IN s_auart AND
    autyp = c_autyp_01 AND
    kokrs = c_kokrs_mbca.
    Please clear my doubt.
    Thanks a lot for ur help!!!!
    Navita

  • Secondary Index Picked with one field short in select query

    Hi,
    We have a select query as follows
    select  single lgort       vgbel        vgpos
        into   (lips-lgort,lips-vgbel,lips-vgpos)
        from    lips
       where         vbeln          Eq p_zlcpp-vbeln
         and         matnr          Eq p_zlcpp-matnr
         and         charg          Eq p_zlcpp-charg
    The secondary index ZB has the fields as follows:
    MANDT     Client
    MATNR     Material Number
    CHARG     Batch Number
    BWART     Movement Type (Inventory Management)
    When seen in the trace it seems the select query picks this secondary index. Whether it is correct? since i find no BWART in the select query. Because of this index the query take large time. I used the Hint statement as follows:
    select  single lgort       vgbel        vgpos
        into   (lips-lgort,lips-vgbel,lips-vgpos)
        from    lips
       where         vbeln          Eq p_zlcpp-vbeln
         and         matnr          Eq p_zlcpp-matnr
         and         charg          Eq p_zlcpp-charg   %_HINTS ORACLE 'INDEX("LIPS" "LIPS~0")' .
    and it now works fast. Please advice the best way to make the select query work on itself without using the hint statement to pick the index LIPS~0 instead of the invalid secondary index ZB.
    Thanks & Regards,
    Selvakumar M.
    Edited by: Selva on Jun 17, 2011 7:35 PM

    Hello Selva,
    your problem here is the decision of the optimizer that does not exactly know the selectivity of the fields.
    If your deliveries are normally small (not too many items), then selecting via the document number will be relatively fast.
    And selecting via the material number + batch will be slow in case if many deliveries are having same product from the same batch delivered.
    I assume that the latest is the case in your system. That's why the selection with ZB index is slow.
    If the data distribution is as I described above, then your hint is quite OK and I advise you to stick to the hint.
    From my PoV this is the better solution rather changing the coding and throwing out MATNR field from the WHERE clause to filter later in ABAP.
    Another solution would be trying to play with histograms. But you'll need %SUBSTITUTE VALUES% or %SUBSTITUTE LITERALS% hint anyway, so I find your solution better.
    So, please stay with hint. Even SAP standard development does it for some select statements.
    Regards,
      Yuri

Maybe you are looking for