How to improve performance of select query when primary key is not referred

Hi,
There is a select query where we are unable to refrence primary key of the tables:
Since, the the below code is refrensing to vgbel and vgpos fields instead of vbeln and posnr..... the performance is very  slow.
select vbeln posnr into (wa-vbeln1, wa-posnr1)             
       from lips                                            
       where ( pstyv ne 'ZBAT'    
           and pstyv ne 'ZNLN' )  
           and vgbel = i_vbap-vbeln                         
           and vgpos = i_vbap-posnr.                        
endselect.                                                 
Please le t me know if you have some tips..

hi,
I hope you are using the select statement inside a loop ...endloop get that outside to improve the performance ..
if not i_vbap[] is initial.
select vbeln posnr into table it_lips
from lips
for all entries in  i_vbap
where ( pstyv ne 'ZBAT'
and pstyv ne 'ZNLN' )
and vgbel = i_vbap-vbeln
and vgpos = i_vbap-posnr.
endif.

Similar Messages

  • How to improve performance of attached query

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description Object_owner Object_name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
    SORT AGGREGATE 1 13
    VIEW GEMINI_REPORTING 14 1 13
    HASH GROUP BY 14 1 103
    NESTED LOOPS 13 1 103
    HASH JOIN 12 1 85
    TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
    NESTED LOOPS 9 5 325
    HASH JOIN 7 1 40
    SORT UNIQUE 2 1 18
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
    INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
    TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
    INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
    TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
    INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1

    duplicate thread..
    How to improve performance of attached query

  • How to improve on insert-select query performance

    Hi,
    Would like to get some opinion on how to improve this query inside my stored proc.
    This insert stmt has run more than 4 hours for inserting around 62k records.
    I have identified the bottleneck is in the function within the select stmt.
    Could anyone help to finetune?
    INSERT INTO STG_PRICE_OUT
    (     ONPN,
         EFFECTIVE_DT,
         PRICE_CATENAME,
         QUEUE_ID
    SELECT P.ONPN, P.EFFECTIVE_DT,
         gps_get_catename(P.PART_STATUS ,P.PROGRAM_CD ,P.MARKET_CD),
         '1'
    FROM      PRICE P,
         GPS_INV_ITEMS GII
    WHERE P.ONPN = GII.ONPN
    FUNCTION Gps_Get_Catename
         p_status      VARCHAR2,
         p_pgm           VARCHAR2,
         p_market      VARCHAR2
    RETURN VARCHAR2
    IS
         catename VARCHAR2(30);
    BEGIN
         SELECT PRICE_CATENAME
         INTO catename
         FROM PRICE_CATEGORY PC
         WHERE NVL(PC.PART_STATUS,' ')= NVL(p_status,' ')
         AND NVL(PC.PROGRAM_CD,' ') = NVL(p_pgm,' ')
         AND NVL(PC.MARKET_CD,' ') = NVL(p_market,' ')
         RETURN catename;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    RETURN NULL;
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.PUT_LINE('gps_get_catename: Exception caught!! (' || SQLCODE || ') : ' || SQLERRM);
         RETURN catename;
    END;
    STG_PRICE_OUT has around 1 mil records
    GPS_INV_ITEMS has around 140K records
    PRICE has around 60k records
    INDEX:
    STG_PRICE_OUT - INDEX 1(ONPN), INDEX2(ONPN,QUEUE_ID)
    GPS_INV_ITEMS - INDEX 3(ONPN)
    PRICE - INDEX 4(ONPN)
    PRICE_CATEGORY - INDEX 5(PART_STATUS ,PROGRAM_CD ,MARKET_CD)
    Thanks and regards,
    WH

    Only use PL/SQL when you can't do it all in SQL...
    INSERT INTO STG_PRICE_OUT
    ( ONPN,
    EFFECTIVE_DT,
    PRICE_CATENAME,
    QUEUE_ID
    SELECT P.ONPN, P.EFFECTIVE_DT,
    PC.PRICE_CATENAME,
    '1'
    FROM PRICE_CATEGORY PC, PRICE P,
    GPS_INV_ITEMS GII
    WHERE P.ONPN = GII.ONPN
    AND PC.PART_STATUS(+) = P.PART_STATUS
    AND PC.PROGRAM_CD(+) = P.PROGRAM_CD
    AND PC.MARKET_CD(+) = P.MARKET_CD
    /Cheers, APC
    P.S. You may need to tweak the outer joins - I'm not quite sure what your business rule is.

  • How to improve Performance of a Query whcih is on a Vritual Cube

    Hi All,
    Please suggest me some tips through which we can improve the performance of a queries that were built on Viirtual Cubes.
    Thanks iin advance.
    Regards,
    Raj

    Hi Raj,
      How is your direct access datasource built ?  Is this a standard datasource or generic datasource on any view/table/function module. This strengthens my second point.
    Suppose you built a virtual cube on direct access datasource built  on AUFK table with Order as primary key (Order master data). when you use Order as selection on query built on this virtual cube then it retrievies the data faster than firing the query on other selections.
    If your selections are different. You can possibly create a secondary index on the table with selections used in query.
    Regards
    vamsi

  • How to improve performance of my query

    Hello Friends,
    Good Morning.
    I am having the following query which is never ending - Can any one throw some light on how to improve the performance of my said said query ..This is the query generated in ODI ( ORACLE DATA INTEGRATOR 11G )
    The only thing I can put in this query is optimizers
    - issue resolved
    Please advice .
    Thanks / Kumar
    Edited by: kumar73 on May 18, 2012 6:38 AM
    Edited by: kumar73 on May 18, 2012 6:39 AM
    Edited by: kumar73 on May 18, 2012 12:04 PM

    The two DISTINCTs are redundant, as UNION results in unique records, as a set can't have duplicates.
    Other than that the query is not formatted and unreadable, and you didn't provide a description of the tables involved.
    Your strategy seems to be maximum help from this forum with minimum effort from yourself, other than hitting copy and paste.
    Sybrand Bakker
    Senior Oracle DBA

  • Select query with primary key on RESB taking too long

    Hello All,
    The below Select query is taking about 1 Hour to run on production. I have done some analysis and the correct index is being selected.
    The query is :
    IF it_aufnr[] IS NOT INITIAL.                             
        SELECT rsnum
               rspos
               matnr
               werks
            lgort
               shkzg
               aufnr
               bdmng
               enmng                      
               FROM  resb INTO  TABLE it_rsnum FOR ALL ENTRIES IN it_aufnr
               WHERE rsnum EQ it_aufnr-rsnum
               AND   xloek NE 'X'
               AND   postp NE 'X'
               AND   resb~bdmng GE resb~enmng.
      ENDIF.
    Database Table RESB: 40,000,000 Records (40 Million)
    Internal Table   it_aufnr:  20,000 Entries
    Entries selected from RESB: 150,000.
    Any ideas on how I could improve the performance ?
    Thanks,
    Shruthi

    >     SELECT rsnum
    >            rspos
    >            matnr
    >            werks
    >         lgort
    >            shkzg
    >            aufnr
    >            bdmng
    >            enmng                      
    >            FROM  resb INTO  TABLE it_rsnum FOR ALL ENTRIES IN it_aufnr
    >            WHERE rsnum EQ it_aufnr-rsnum
    >            AND   xloek NE 'X'
    >            AND   postp NE 'X'
    >            AND   resbbdmng GE resbenmng.
    >   ENDIF.
    >
    > Database Table RESB: 40,000,000 Records (40 Million)
    > Internal Table   it_aufnr:  20,000 Entries
    > Entries selected from RESB: 150,000.
    >
    Hi,
    the problem is the big for all entries table.
    Your 20.000 records FAE will be split into SEVERAL sql statements depending on the size of the table.
    Where do you get the it_auftrn from?
    If it's another transparent table try to JOIN this table to your big table.
    SELECT rsnum
                rspos
                matnr
                werks
            lgort
                shkzg
                aufnr
                bdmng
                enmng                      
                FROM  resb JOIN tab_auftrn  on  resbrsnum = tab_auftrnauftrn
                AND   xloek NE 'X'
                AND   postp NE 'X'
                AND   resbbdmng GE resbenmng.
    Make sure that your WHERE filter and the JOIN keys on both tables are supported by indexes.
    150.000 records about of 40 Mio. can definitly be serviced by an appropriate index:
    i.e. Index fields (check your PK or secondary indexes):
    rsnum
    enmng                      
    aufnr
    bye
    yk

  • How to improve Performance for Select statement

    Hi Friends,
    Can  you please help me in improving the performance of the following query:
    SELECT SINGLE MAX( policyterm ) startterm INTO (lv_term, lv_cal_date) FROM zu1cd_policyterm WHERE gpart = gv_part GROUP BY startterm.
    Thanks and Regards,
    Johny

    long lists can not be produced with  a SELECT SINGLE, there is also nothing to group.
    But I guess the SINGLE is a bug
    SELECT MAX( policyterm ) startterm
                  INTO (lv_term, lv_cal_date)
                  FROM zu1cd_policyterm
                  WHERE gpart = gv_part
                  GROUP BY startterm.
    How many records are in zu1cd_policyterm ?
    Is there an index starting with gpart?
    If first answer is 'large' and second 'no'   =>   slow
    What is the meaning of gpart?  How many different values can it assume?
    If many different values then an index makes sense, if you are allowed to create
    an index.
    Otherwise you must be patient.
    Siegfried

  • How to improve performance of a query that is based on an xmltype table

    Dear Friends,
    I have a query that is pulling records from an xmltype table with 9000 rows and it is running very slow.
    I am using XMLTABLE command to retreive the rows. It is taking upto 30 minutes to finish.
    Would you be able to suggest how I can make it faster. Thanks.
    Below is the query.....
    INSERT INTO temp_sap_po_receipt_history_t
    (po_number, po_line_number, doc_year,
    material_doc, material_doc_item, quantity, sap_ref_doc_no_long,
    reference_doc, movement_type_code,
    sap_ref_doc_no, posting_date, entry_date, entry_time, hist_type)
    SELECT :pin_po_number po_number,
    b.po_line_number, b.doc_year,
    b.material_doc, b.material_doc_item, b.quantity, b.sap_ref_doc_no_long,
    b.reference_doc, b.movement_type_code,
    b.sap_ref_doc_no, to_date(b.posting_date,'rrrr-mm-dd'),
    to_date(b.entry_date,'rrrr-mm-dd'), b.entry_time, b.hist_type
    FROM temp_xml t,
    XMLTABLE(XMLNAMESPACES('urn:sap-com:document:sap:rfc:functions' AS "n0"),
    '/n0:BAPI_PO_GETDETAIL1Response/POHISTORY/item'
    PASSING t.object_value
    COLUMNS PO_LINE_NUMBER VARCHAR2(20) PATH 'PO_ITEM',
    DOC_YEAR varchar2(4) PATH 'DOC_YEAR',
    MATERIAL_DOC varchar2(30) PATH 'MAT_DOC',
    MATERIAL_DOC_ITEM VARCHAR2(10) PATH 'MATDOC_ITEM',
    QUANTITY NUMBER(20,6) PATH 'QUANTITY',
    SAP_REF_DOC_NO_LONG VARCHAR2(20) PATH 'REF_DOC_NO_LONG',
    REFERENCE_DOC VARCHAR2(20) PATH 'REF_DOC',
    MOVEMENT_TYPE_CODE VARCHAR2(4) PATH 'MOVE_TYPE',
    SAP_REF_DOC_NO VARCHAR2(20) PATH 'REF_DOC_NO',
    POSTING_DATE VARCHAR2(10) PATH 'PSTNG_DATE',
    ENTRY_DATE VARCHAR2(10) PATH 'ENTRY_DATE',
    ENTRY_TIME VARCHAR2(8) PATH 'ENTRY_TIME',
    HIST_TYPE VARCHAR2(5) PATH 'HIST_TYPE') b;

    Based on response from mdrake on this thread:
    Re: XML file processing into oracle
    For large XML's, you can speed up the processing of XMLTABLE by using a registered schema...
    declare
      SCHEMAURL VARCHAR2(256) := 'http://xmlns.example.org/xsd/testcase.xsd';
      XMLSCHEMA VARCHAR2(4000) := '<?xml version="1.0" encoding="UTF-8"?>
         <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" xdb:storeVarrayAsTable="true">
            <xs:element name="cust_order" type="cust_orderType" xdb:defaultTable="CUST_ORDER_TBL"/>
            <xs:complexType name="groupType" xdb:maintainDOM="false">
                    <xs:sequence>
                            <xs:element name="item" type="itemType" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="id" type="xs:byte" use="required"/>
            </xs:complexType>
            <xs:complexType name="itemType" xdb:maintainDOM="false">
                    <xs:simpleContent>
                            <xs:extension base="xs:string">
                                    <xs:attribute name="id" type="xs:short" use="required"/>
                                    <xs:attribute name="name" type="xs:string" use="required"/>
                            </xs:extension>
                    </xs:simpleContent>
            </xs:complexType>
            <xs:complexType name="cust_orderType" xdb:maintainDOM="false">
                    <xs:sequence>
                            <xs:element name="group" type="groupType" maxOccurs="unbounded"/>
                    </xs:sequence>
                    <xs:attribute name="cust_id" type="xs:short" use="required"/>
            </xs:complexType>
         </xs:schema>';
      INSTANCE  CLOB :=
    '<cust_order cust_id="12345">
      <group id="1">
        <item id="1" name="Standard Mouse">100</item>
        <item id="2" name="Keyboard">100</item>
        <item id="3" name="Memory Module 2Gb">200</item>
        <item id="4" name="Processor 3Ghz">25</item>
        <item id="5" name="Processor 2.4Ghz">75</item>
      </group>
      <group id="2">
        <item id="1" name="Graphics Tablet">15</item>
        <item id="2" name="Keyboard">15</item>
        <item id="3" name="Memory Module 4Gb">15</item>
        <item id="4" name="Processor Quad Core 2.8Ghz">15</item>
      </group>
      <group id="3">
        <item id="1" name="Optical Mouse">5</item>
        <item id="2" name="Ergo Keyboard">5</item>
        <item id="3" name="Memory Module 2Gb">10</item>
        <item id="4" name="Processor Dual Core 2.4Ghz">5</item>
        <item id="5" name="Dual Output Graphics Card">5</item>
        <item id="6" name="28inch LED Monitor">10</item>
        <item id="7" name="Webcam">5</item>
        <item id="8" name="A3 1200dpi Laser Printer">2</item>
      </group>
    </cust_order>';                
    begin
      dbms_xmlschema.registerSchema
         schemaurl       => SCHEMAURL
        ,schemadoc       => XMLSCHEMA
        ,local           => TRUE
        ,genTypes        => TRUE
        ,genBean         => FALSE
        ,genTables       => TRUE
        ,ENABLEHIERARCHY => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
      execute immediate 'insert into CUST_ORDER_TBL values (XMLTYPE(:INSTANCE))' using INSTANCE;
    end;
    SQL> desc CUST_ORDER_TBL
    Name                                                                                                                                    Null?    Type
    TABLE of SYS.XMLTYPE(XMLSchema "http://xmlns.example.org/xsd/testcase.xsd" Element "cust_order") STORAGE Object-relational TYPE "cust_orderType222_T"
    SQL> set autotrace on explain
    SQL> set pages 60 lines 164 heading on
    SQL> col cust_id format a8
    SQL> select extract(object_value,'/cust_order/@cust_id') as cust_id
      2        ,grp.id as group_id, itm.id as item_id, itm.inm as item_name, itm.qty as item_qty
      3  from   CUST_ORDER_TBL
      4        ,XMLTABLE('/cust_order/group'
      5                  passing object_value
      6                  columns id   number       path '@id'
      7                         ,item xmltype      path 'item'
      8                 ) grp
      9        ,XMLTABLE('/item'
    10                  passing grp.item
    11                  columns id   number       path '@id'
    12                         ,inm  varchar2(30) path '@name'
    13                         ,qty  number       path '.'
    14                 ) itm
    15  /
    CUST_ID    GROUP_ID    ITEM_ID ITEM_NAME                        ITEM_QTY
    12345             1          1 Standard Mouse                        100
    12345             1          2 Keyboard                              100
    12345             1          3 Memory Module 2Gb                     200
    12345             1          4 Processor 3Ghz                         25
    12345             1          5 Processor 2.4Ghz                       75
    12345             2          1 Graphics Tablet                        15
    12345             2          2 Keyboard                               15
    12345             2          3 Memory Module 4Gb                      15
    12345             2          4 Processor Quad Core 2.8Ghz             15
    12345             3          1 Optical Mouse                           5
    12345             3          2 Ergo Keyboard                           5
    12345             3          3 Memory Module 2Gb                      10
    12345             3          4 Processor Dual Core 2.4Ghz              5
    12345             3          5 Dual Output Graphics Card               5
    12345             3          6 28inch LED Monitor                     10
    12345             3          7 Webcam                                  5
    12345             3          8 A3 1200dpi Laser Printer                2
    17 rows selected.Need at least 10.2.0.3 for performance i.e. to avoid COLLECTION ITERATOR PICKLER FETCH in execution plan...
    On 10.2.0.1:
    Execution Plan
    Plan hash value: 3741473841
    | Id  | Operation                          | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                        | 24504 |    89M|   873   (1)| 00:00:11 |
    |   1 |  NESTED LOOPS                      |                        | 24504 |    89M|   873   (1)| 00:00:11 |
    |   2 |   NESTED LOOPS                     |                        |     3 | 11460 |   805   (1)| 00:00:10 |
    |   3 |    TABLE ACCESS FULL               | CUST_ORDER_TBL         |     1 |  3777 |     3   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN                | SYS_IOT_TOP_774117     |     3 |   129 |     1   (0)| 00:00:01 |
    |   5 |   COLLECTION ITERATOR PICKLER FETCH| XMLSEQUENCEFROMXMLTYPE |       |       |            |       |
    Predicate Information (identified by operation id):
       4 - access("NESTED_TABLE_ID"="CUST_ORDER_TBL"."SYS_NC0000900010$")
           filter("SYS_NC_TYPEID$" IS NOT NULL)
    Note
       - dynamic sampling used for this statementOn 10.2.0.3:
    Execution Plan
    Plan hash value: 1048233240
    | Id  | Operation               | Name              | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |                   |    17 |   132K|   839   (0)| 00:00:11 |
    |   1 |  NESTED LOOPS           |                   |    17 |   132K|   839   (0)| 00:00:11 |
    |   2 |   MERGE JOIN CARTESIAN  |                   |    17 |   131K|   805   (0)| 00:00:10 |
    |   3 |    TABLE ACCESS FULL    | CUST_ORDER_TBL    |     1 |  3781 |     3   (0)| 00:00:01 |
    |   4 |    BUFFER SORT          |                   |    17 | 70839 |   802   (0)| 00:00:10 |
    |*  5 |     INDEX FAST FULL SCAN| SYS_IOT_TOP_56154 |    17 | 70839 |   802   (0)| 00:00:10 |
    |*  6 |   INDEX UNIQUE SCAN     | SYS_IOT_TOP_56152 |     1 |    43 |     2   (0)| 00:00:01 |
    |*  7 |    INDEX RANGE SCAN     | SYS_C006701       |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       5 - filter("SYS_NC_TYPEID$" IS NOT NULL)
       6 - access("SYS_NTpzENS1H/RwSSC7TVzvlqmQ=="."NESTED_TABLE_ID"="SYS_NTnN5b8Q+8Txi9V
                  w5Ysl6x9w=="."SYS_NC0000600007$")
           filter("SYS_NC_TYPEID$" IS NOT NULL AND
                  "NESTED_TABLE_ID"="CUST_ORDER_TBL"."SYS_NC0000900010$")
       7 - access("SYS_NTpzENS1H/RwSSC7TVzvlqmQ=="."NESTED_TABLE_ID"="SYS_NTnN5b8Q+8Txi9V
                  w5Ysl6x9w=="."SYS_NC0000600007$")
    Note
       - dynamic sampling used for this statement----------------------------------------------------------------------------------------------------------
    -- CLEAN UP
    DROP TABLE CUST_ORDER_TBL purge;
    exec dbms_xmlschema.deleteschema('http://xmlns.example.org/xsd/testcase.xsd');

  • How to Improve Performance of this query??

    Hi experts,
    Kindly suggest me some perfomance optimization on the below code.
    SELECT * FROM vtrdi AS v
                   INTO TABLE six
                   FOR ALL ENTRIES IN r_vbeln
                   WHERE vbeln EQ  r_vbeln-low
                   AND   trsta IN  s_trsta
                   AND   vstel IN  s_vstel
                   AND   tddat IN  s_tddat
                   AND   vbtyp IN  r_vbtyp
                   AND   lstel IN  s_lstel
                   AND   route IN  s_route
                   AND   tragr IN  s_tragr
                   AND   vsbed IN  s_vsbed
                   AND   land1 IN  s_land1
                   AND   lzone IN  s_lzone
                   AND   wadat IN  s_wadat
                   AND   wbstk IN  s_wbstk
                   AND   lddat IN  s_lddat
                   AND   lfdat IN  s_lfdat
                   AND   kodat IN  s_kodat
                   AND   kunnr IN  s_kunnr
                   AND   spdnr IN  s_spdnr
                   AND   inco1 IN  s_inco1
                   AND   inco2 IN  s_inco2
                   AND   lprio IN  s_lprio
                   AND EXISTS ( SELECT * FROM likp
                                  WHERE vbeln EQ v~vbeln
                                  AND lifnr IN s_lifnr    
                                  AND lgtor IN s_lgtor
                                  AND lgnum IN s_lgnum
                                  AND lfuhr IN s_lfuhr
                                  AND aulwe IN s_aulwe
                                  AND traty IN s_traty
                                  AND traid IN s_traid
                                  AND vsart IN s_vsart
                                  AND trmtyp IN s_trmtyp
                                  AND sdabw IN s_sdabw
                                  AND cont_dg IN r_cont_dg ).
    Thanks in Advance...
    Santosh.

    Try to write 2 select
    SELECT * FROM vtrdi AS v
    INTO TABLE six
    FOR ALL ENTRIES IN r_vbeln
    WHERE vbeln EQ r_vbeln-low
    AND trsta IN s_trsta
    AND vstel IN s_vstel
    AND tddat IN s_tddat
    AND vbtyp IN r_vbtyp
    AND lstel IN s_lstel
    AND route IN s_route
    AND tragr IN s_tragr
    AND vsbed IN s_vsbed
    AND land1 IN s_land1
    AND lzone IN s_lzone
    AND wadat IN s_wadat
    AND wbstk IN s_wbstk
    AND lddat IN s_lddat
    AND lfdat IN s_lfdat
    AND kodat IN s_kodat
    AND kunnr IN s_kunnr
    AND spdnr IN s_spdnr
    AND inco1 IN s_inco1
    AND inco2 IN s_inco2
    AND lprio IN s_lprio.
    SELECT * FROM likp  into table itab
    WHERE vbeln EQ v~vbeln
    AND lifnr IN s_lifnr
    AND lgtor IN s_lgtor
    AND lgnum IN s_lgnum
    AND lfuhr IN s_lfuhr
    AND aulwe IN s_aulwe
    AND traty IN s_traty
    AND traid IN s_traid
    AND vsart IN s_vsart
    AND trmtyp IN s_trmtyp
    AND sdabw IN s_sdabw
    AND cont_dg IN r_cont_dg
    loop at six
      check whether entry is exists or not
    if not remove from six interbal table.
    endloop.
    Thanks
    Venkat

  • How to improve performance of the attached query

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description Object_owner Object_name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
    SORT AGGREGATE 1 13
    VIEW GEMINI_REPORTING 14 1 13
    HASH GROUP BY 14 1 103
    NESTED LOOPS 13 1 103
    HASH JOIN 12 1 85
    TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
    NESTED LOOPS 9 5 325
    HASH JOIN 7 1 40
    SORT UNIQUE 2 1 18
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
    INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
    TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
    INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
    TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
    INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1

    duplicate thread..
    How to improve performance of attached query

  • Need to improve Performance of select...endselect query

    Hi experts,
    I have a query in my program like below with inner join of 3 tables.
    In my program used select....endselect   again inside this select...endselect statements used..
    While executing in production taking lot of time to fetch records. Can anyone suggest to improve performance of below query urgently...
    Greatly appreciated ur help...
    SELECT MVKEDWERK MVKEMATNR MVKEVKORG MVKEVTWEG MARA~MATNR
           MARAMTART ZM012MTART ZM012ZLIND ZM012ZPRICEREF
    INTO (MVKE-DWERK , MVKE-MATNR , MVKE-VKORG , MVKE-VTWEG , MARA-MATNR
         , MARA-MTART , ZM012-MTART , ZM012-ZLIND , ZM012-ZPRICEREF )
    FROM ( MVKE
           INNER JOIN MARA
           ON MARAMATNR = MVKEMATNR
           INNER JOIN ZM012
           ON ZM012MTART = MARAMTART )
           WHERE MVKE~DWERK IN SP$00004
             AND MVKE~MATNR IN SP$00001
             AND MVKE~VKORG IN SP$00002
             AND MVKE~VTWEG IN SP$00003
             AND MARA~MTART IN SP$00005
             AND ZM012~ZLIND IN SP$00006
             AND ZM012~ZPRICEREF IN SP$00007.
      %DBACC = %DBACC - 1.
      IF %DBACC = 0.
        STOP.
      ENDIF.
      CHECK SP$00005.
      CHECK SP$00004.
      CHECK SP$00001.
      CHECK SP$00002.
      CHECK SP$00003.
      CHECK SP$00006.
      CHECK SP$00007.
      clear Check_PR00.
      select * from A004
      where kappl = 'V'
      and kschl = 'PR00'
      and vkorg = mvke-vkorg
      and vtweg = mvke-vtweg
      and matnr = mvke-matnr
      and DATAB le sy-datum
      and DATBI ge sy-datum.
      if sy-subrc = 0.
      select * from konp
      where knumh = a004-knumh.
      if sy-subrc = 0.
      Check_PR00 = konp-kbetr.
      endif.
      endselect.
      endif.
      endselect.
      CHECK SP$00008.
      clear Check_ZPR0.
      select * from A004
      where kappl = 'V'
      and kschl = 'ZPR0'
      and vkorg = mvke-vkorg
      and vtweg = mvke-vtweg
      and matnr = mvke-matnr
      and DATAB le sy-datum
      and DATBI ge sy-datum.
      if sy-subrc = 0.
      select * from konp
      where knumh = a004-knumh.
      if sy-subrc = 0.
      Check_ZPR0 = konp-kbetr.
      endif.
      endselect.
      endif.
      endselect.
      CHECK SP$00009.
      clear ZFMP.
      select * from A004
      where kappl = 'V'
      and kschl = 'ZFMP'
      and vkorg = mvke-vkorg
      and vtweg = mvke-vtweg
      and matnr = mvke-matnr
      and DATAB le sy-datum
      and DATBI ge sy-datum.
      if sy-subrc = 0.
      select * from konp
      where knumh = a004-knumh.
      if sy-subrc = 0.
      ZFMP = konp-kbetr.
      endif.
      endselect.
      endif.
      endselect.
      CHECK SP$00010.
      clear mastercost.
      clear ZDCF.
      select * from A004
      where kappl = 'V'
      and kschl = 'ZDCF'
      and vkorg = mvke-vkorg
      and vtweg = mvke-vtweg
      and matnr = mvke-matnr
      and DATAB le sy-datum
      and DATBI ge sy-datum.
      if sy-subrc = 0.
      select * from konp
      where knumh = a004-knumh.
      if sy-subrc = 0.
      ZDCF = konp-kbetr.
      endif.
      endselect.
      endif.
      endselect.
      CHECK SP$00011.
      clear masterprice.
      clear Standardcost.
      select * from mbew
      where matnr = mvke-matnr
      and bwkey = mvke-dwerk.
      Standardcost = mbew-stprs.
      mastercost = MBEW-BWPRH.
      masterprice = mBEW-BWPH1.
      endselect.
      ADD 1 TO %COUNT-MVKE.
      %LINR-MVKE = '01'.
      EXTRACT %FG01.
      %EXT-MVKE01 = 'X'.
        EXTRACT %FGWRMVKE01.
    ENDSELECT.
    best rgds..
    hari..

    Hi there.
    Some advices:
    - why going to MVKE first and MARA then? You will find n rows in MVKE for 1 matnr, and then go n times to the same record in MARA. Do the oposite, i.e, go first to MARA (1 time per matnr) and then to MVKE.
    - avoid select *, you will save time.
    - use trace or measure performance in tcodes ST05 and SM30.
    -  replace:
    select * from konp
    where knumh = a004-knumh.
    if sy-subrc = 0.
    Check_ZPR0 = konp-kbetr.
    endif.
    endselect.
    by
    select * from konp
    where knumh = a004-knumh.
    Check_ZPR0 = konp-kbetr.
    exit.
    endselect.    
    Here, if I understood, you only need to atribute kbetr value to Check_ZPR0 if selecting anything (don't need the IF because if enters in select, subrc always equal to 0, and also don't need to do it several times from same a004-knumh - reason for the EXIT.
    Hope this helps.
    Regards.
    Valter Oliveira.
    Edited by: Valter Oliveira on Jun 5, 2008 3:16 PM

  • How to improve performance of query

    Hi all,
    How to improve performance of query.
    please send :
    [email protected]
    thanks in advance
    bhaskar

    hi
    go through the following links for performance
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/cccad390-0201-0010-5093-fd9ec8157802
    http://www.asug.com/client_files/Calendar/Upload/ASUG%205-mar-2004%20BW%20Performance%20PDF.pdf
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/1955ba90-0201-0010-d3aa-8b2a4ef6bbb2

  • How to improve performance when there are many TextBlocks in ItemsControl items?

       Hi,
       I'm trying to find a way to improve performance for a situation when there is an ItemsControl using UI and Data virtualization and each item on that control has 36 TextBlocks. Basically the item is a single string. There are so many TextBlocks
    to allow assigning different brushes to different parts of the string. Performance of this construction is terrible. I have 37 items visible on the screen and if I try to scroll up or down it scrolls into the black space and then it takes a second or two to
    show the items.
       I tried different things. For example, the most successful performance-wise was to replace TextBlocks with Borders and then draw bitmaps. In other words, I prepared 127 bitmaps for each character (I need ASCII only) and then I used those bitmaps
    to set Border.Backgrounds. It improved performance about 1.5 - 2 times but it consumed much more memory (which is not surprising, of course). Required amount of memory is so big that it throws OutOfMemoryException on 512MB emulator but works on 1GB. As a result
    I don't thing it is a good solution.
       Another thing that worked perfect is to replace 36 TextBlocks with only 6 TextBlocks. In this case the performance improvement is about 5 - 10 times but I lose the ability to set different colors to different parts of the string. It seems that
    the performance degrades dramatically with the increase of number of TextBlocks. Is there another technique to draw strings where literally each character can be of different color with decent performance?
    Thank you
    Alex

       Using Runs inside TextBlocks gives approximately the same improvement as using bitmaps 1.5 - 2 times faster but it is not even close to the case with just a couple of TextBlocks in the ItemsControl item. Any other ideas?
    Alex

  • HOW TO IMPROVE PERFORMANCE

    HI ALL ,,,
    MY SELECT STATEMENT IS LIKE THIS. IN SM30 ITS SHOWING THAT ITS HAS TAKE THE MAXIMUM TIME. SO HOW CAN I REDUCE THE HITING DB TABLE TIME OR IMPROVE THE PERFORMANCE?
    IF LT_JCDS[] IS NOT INITIAL.
        SELECT  OBJNR
                WKGBTR
                BELNR
                WRTTP
                BEKNZ
                PERIO
                GJAHR
                VERSN
                KOKRS
                VRGNG
                GKOAR
                BUKRS
                REFBZ_FI
                MBGBTR
                FROM COEP
          INTO CORRESPONDING FIELDS OF TABLE LT_COEP
          FOR ALL ENTRIES IN LT_JCDS
          WHERE KOKRS EQ 'DXES'
          AND  OBJNR EQ LT_JCDS-OBJNR
          AND GJAHR <= SO_GJAHR-LOW
          AND  VERSN eq '000'
          AND ( VRGNG EQ 'COIN'  OR VRGNG EQ 'RKU1' OR  VRGNG EQ 'RKL').
          IF SY-SUBRC <> 0.
           MESSAGE  e000(8i) WITH 'DATA NOT FOUND IN "CO Object: Line Items (by Period)"'.
         ENDIF.
      ENDIF.

    Hi
    see these points
    Ways of Performance Tuning
    1.     Selection Criteria
    2.     Select Statements
    •     Select Queries
    •     SQL Interface
    •     Aggregate Functions
    •     For all Entries
    Select Over more than one Internal table
    Selection Criteria
    1.     Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement. 
    2.     Select with selection list.
    Points # 1/2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Select Statements   Select Queries
    1.     Avoid nested selects
    2.     Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
    3.     When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
    4.     For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. 
    5.     Use Select Single if all primary key fields are supplied in the Where condition .
    Point # 1
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops  only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
    Point # 2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Point # 3
    To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
    Point # 4
    SELECT * FROM SBOOK INTO SBOOK_WA
      UP TO 1 ROWS
      WHERE CARRID = 'LH'.
    ENDSELECT.
    The above code is more optimized as compared to the code mentioned below for testing existence of a record.
    SELECT * FROM SBOOK INTO SBOOK_WA
        WHERE CARRID = 'LH'.
      EXIT.
    ENDSELECT.
    Point # 5
    If all primary key fields are supplied in the Where condition you can even use Select Single.
    Select Single requires one communication with the database system, whereas Select-Endselect needs two.
    Select Statements           contd..  SQL Interface
    1.     Use column updates instead of single-row updates
    to update your database tables.
    2.     For all frequently used Select statements, try to use an index.
    3.     Using buffered tables improves the performance considerably.
    Point # 1
    SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
      SFLIGHT_WA-SEATSOCC =
        SFLIGHT_WA-SEATSOCC - 1.
      UPDATE SFLIGHT FROM SFLIGHT_WA.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    UPDATE SFLIGHT
           SET SEATSOCC = SEATSOCC - 1.
    Point # 2
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE MANDT IN ( SELECT MANDT FROM T000 )
        AND CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    Point # 3
    Bypassing the buffer increases the network considerably
    SELECT SINGLE * FROM T100 INTO T100_WA
      BYPASSING BUFFER
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    The above mentioned code can be more optimized by using the following code
    SELECT SINGLE * FROM T100  INTO T100_WA
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    Select Statements       contd…           Aggregate Functions
    •     If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
    Some of the Aggregate functions allowed in SAP are  MAX, MIN, AVG, SUM, COUNT, COUNT( * )
    Consider the following extract.
                Maxno = 0.
                Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
                 Check zflight-fligh > maxno.
                 Maxno = zflight-fligh.
                Endselect.
    The  above mentioned code can be much more optimized by using the following code.
    Select max( fligh ) from zflight into maxno where airln = ‘LF’ and cntry = ‘IN’.
    Select Statements    contd…For All Entries
    •     The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
         The plus
    •     Large amount of data
    •     Mixing processing and reading of data
    •     Fast internal reprocessing of data
    •     Fast
         The Minus
    •     Difficult to program/understand
    •     Memory could be critical (use FREE or PACKAGE size)
    Points to be must considered FOR ALL ENTRIES
    •     Check that data is present in the driver table
    •     Sorting the driver table
    •     Removing duplicates from the driver table
    Consider the following piece of extract
    Loop at int_cntry.
           Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    The above mentioned can be more optimized by using the following code.
    Sort int_cntry by cntry.
    Delete adjacent duplicates from int_cntry.
    If NOT int_cntry[] is INITIAL.
                Select * from zfligh appending table int_fligh
                For all entries in int_cntry
                Where cntry = int_cntry-cntry.
    Endif.
    Select Statements    contd…  Select Over more than one Internal table
    1.     Its better to use a views instead of nested Select statements.
    2.     To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
    3.     Instead of using nested Select loops it is often better to use subqueries.
    Point # 1
    SELECT * FROM DD01L INTO DD01L_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND AS4LOCAL = 'A'.
      SELECT SINGLE * FROM DD01T INTO DD01T_WA
        WHERE   DOMNAME    = DD01L_WA-DOMNAME
            AND AS4LOCAL   = 'A'
            AND AS4VERS    = DD01L_WA-AS4VERS
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.
    The above code can be more optimized by extracting all the data from view DD01V_WA
    SELECT * FROM DD01V INTO  DD01V_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT
    Point # 2
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Point # 3
    SELECT * FROM SPFLI
      INTO TABLE T_SPFLI
      WHERE CITYFROM = 'FRANKFURT'
        AND CITYTO = 'NEW YORK'.
    SELECT * FROM SFLIGHT AS F
        INTO SFLIGHT_WA
        FOR ALL ENTRIES IN T_SPFLI
        WHERE SEATSOCC < F~SEATSMAX
          AND CARRID = T_SPFLI-CARRID
          AND CONNID = T_SPFLI-CONNID
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    The above mentioned code can be even more optimized by using subqueries instead of for all entries.
    SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                         WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    1.     Table operations should be done using explicit work areas rather than via header lines.
    2.     Always try to use binary search instead of linear search. But don’t forget to sort your internal table before that.
    3.     A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
    4.     A binary search using secondary index takes considerably less time.
    5.     LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
    6.     Modifying selected components using “ MODIFY itab …TRANSPORTING f1 f2.. “ accelerates the task of updating  a line of an internal table.
    Point # 2
    READ TABLE ITAB INTO WA WITH KEY K = 'X‘ BINARY SEARCH.
    IS MUCH FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY K = 'X'.
    If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
    Point # 3
    READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
    Point # 5
    LOOP AT ITAB INTO WA WHERE K = 'X'.
    ENDLOOP.
    The above code is much faster than using
    LOOP AT ITAB INTO WA.
      CHECK WA-K = 'X'.
    ENDLOOP.
    Point # 6
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
    The above code is more optimized as compared to
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1.
    7.     Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
    8.    If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
    9.    "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”
    10.   “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.
    11.   "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “  DO -DELETE-ENDDO”.
    Point # 7
    Modifying selected components only makes the program faster as compared to Modifying all lines completely.
    e.g,
    LOOP AT ITAB ASSIGNING <WA>.
      I = SY-TABIX MOD 2.
      IF I = 0.
        <WA>-FLAG = 'X'.
      ENDIF.
    ENDLOOP.
    The above code works faster as compared to
    LOOP AT ITAB INTO WA.
      I = SY-TABIX MOD 2.
      IF I = 0.
        WA-FLAG = 'X'.
        MODIFY ITAB FROM WA.
      ENDIF.
    ENDLOOP.
    Point # 8
    LOOP AT ITAB1 INTO WA1.
      READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
      IF SY-SUBRC = 0.
        ADD: WA1-VAL1 TO WA2-VAL1,
             WA1-VAL2 TO WA2-VAL2.
        MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
      ELSE.
        INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
      ENDIF.
    ENDLOOP.
    The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
    LOOP AT ITAB1 INTO WA.
      COLLECT WA INTO ITAB2.
    ENDLOOP.
    SORT ITAB2 BY K.
    COLLECT, however, uses a hash algorithm and is therefore independent
    of the number of entries (i.e. O(1)) .
    Point # 9
    APPEND LINES OF ITAB1 TO ITAB2.
    This is more optimized as compared to
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 10
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
    This is much more optimized as compared to
    READ TABLE ITAB INDEX 1 INTO PREV_LINE.
    LOOP AT ITAB FROM 2 INTO WA.
      IF WA = PREV_LINE.
        DELETE ITAB.
      ELSE.
        PREV_LINE = WA.
      ENDIF.
    ENDLOOP.
    Point # 11
    DELETE ITAB FROM 450 TO 550.
    This is much more optimized as compared to
    DO 101 TIMES.
      DELETE ITAB INDEX 450.
    ENDDO.
    12.   Copying internal tables by using “ITAB2[ ] = ITAB1[ ]” as compared to “LOOP-APPEND-ENDLOOP”.
    13.   Specify the sort key as restrictively as possible to run the program faster.
    Point # 12
    ITAB2[] = ITAB1[].
    This is much more optimized as compared to
    REFRESH ITAB2.
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 13
    “SORT ITAB BY K.” makes the program runs faster as compared to “SORT ITAB.”
    Internal Tables         contd…
    Hashed and Sorted tables
    1.     For single read access hashed tables are more optimized as compared to sorted tables.
    2.      For partial sequential access sorted tables are more optimized as compared to hashed tables
    Hashed And Sorted Tables
    Point # 1
    Consider the following example where HTAB is a hashed table and STAB is a sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    This runs faster for single read access as compared to the following same code for sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE STAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    Point # 2
    Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
    LOOP AT STAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.
    This runs faster as compared to
    LOOP AT HTAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.

  • Regarding to perform in select query

    could any tell  the select query in this piece of code would affect the performance of the programe
    DATA: BEGIN OF OUTREC,
          BANKS LIKE BNKA-BANKS,
          BANKL LIKE BNKA-BANKL,
          BANKA LIKE BNKA-BANKA,
          PROVZ LIKE BNKA-PROVZ,   "Region (State, Province, County)
          BRNCH LIKE BNKA-BRNCH,
          STRAS LIKE BNKA-STRAS,
          ORT01 LIKE BNKA-ORT01,
          SWIFT LIKE BNKA-SWIFT,
    END OF OUTREC.
    OPEN DATASET P_OUTPUT FOR OUTPUT IN TEXT MODE.
    IF SY-SUBRC NE 0. EXIT. ENDIF.
    SELECT * FROM BNKA
             WHERE BANKS EQ P_BANKS
             AND   LOEVM NE 'X'
             AND   XPGRO NE 'X'
             ORDER BY BANKS BANKL.
      PERFORM TRANSFER_DATA.
    ENDSELECT.
    CLOSE DATASET P_OUTPUT.
    *&      Transfer the data to the output file
    FORM TRANSFER_DATA.
      OUTREC-BANKS = BNKA-BANKS.
      OUTREC-BANKL = BNKA-BANKL.
      OUTREC-BANKA = BNKA-BANKA.
      OUTREC-PROVZ = BNKA-PROVZ.
      OUTREC-BRNCH = BNKA-BRNCH.
      OUTREC-STRAS = BNKA-STRAS.
      OUTREC-ORT01 = BNKA-ORT01.
      OUTREC-SWIFT = BNKA-SWIFT.
      TRANSFER OUTREC TO P_OUTPUT.
    ENDFORM.                               " READ_IN_DATA

    Hi
    Ways of Performance Tuning
    1.     Selection Criteria
    2.     Select Statements
    •     Select Queries
    •     SQL Interface
    •     Aggregate Functions
    •     For all Entries
    Select Over more than one Internal table
    Selection Criteria
    1.     Restrict the data to the selection criteria itself, rather than filtering it out using the ABAP code using CHECK statement. 
    2.     Select with selection list.
    Points # 1/2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Select Statements   Select Queries
    1.     Avoid nested selects
    2.     Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
    3.     When a base table has multiple indices, the where clause should be in the order of the index, either a primary or a secondary index.
    4.     For testing existence , use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. 
    5.     Use Select Single if all primary key fields are supplied in the Where condition .
    Point # 1
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Note: A simple SELECT loop is a single database access whose result is passed to the ABAP program line by line. Nested SELECT loops mean that the number of accesses in the inner loop is multiplied by the number of accesses in the outer loop. One should therefore use nested SELECT loops  only if the selection in the outer loop contains very few lines or the outer loop is a SELECT SINGLE statement.
    Point # 2
    SELECT * FROM SBOOK INTO SBOOK_WA.
      CHECK: SBOOK_WA-CARRID = 'LH' AND
             SBOOK_WA-CONNID = '0400'.
    ENDSELECT.
    The above code can be much more optimized by the code written below which avoids CHECK, selects with selection list and puts the data in one shot using into table
    SELECT  CARRID CONNID FLDATE BOOKID FROM SBOOK INTO TABLE T_SBOOK
      WHERE SBOOK_WA-CARRID = 'LH' AND
                  SBOOK_WA-CONNID = '0400'.
    Point # 3
    To choose an index, the optimizer checks the field names specified in the where clause and then uses an index that has the same order of the fields . In certain scenarios, it is advisable to check whether a new index can speed up the performance of a program. This will come handy in programs that access data from the finance tables.
    Point # 4
    SELECT * FROM SBOOK INTO SBOOK_WA
      UP TO 1 ROWS
      WHERE CARRID = 'LH'.
    ENDSELECT.
    The above code is more optimized as compared to the code mentioned below for testing existence of a record.
    SELECT * FROM SBOOK INTO SBOOK_WA
        WHERE CARRID = 'LH'.
      EXIT.
    ENDSELECT.
    Point # 5
    If all primary key fields are supplied in the Where condition you can even use Select Single.
    Select Single requires one communication with the database system, whereas Select-Endselect needs two.
    Select Statements           contd..  SQL Interface
    1.     Use column updates instead of single-row updates
    to update your database tables.
    2.     For all frequently used Select statements, try to use an index.
    3.     Using buffered tables improves the performance considerably.
    Point # 1
    SELECT * FROM SFLIGHT INTO SFLIGHT_WA.
      SFLIGHT_WA-SEATSOCC =
        SFLIGHT_WA-SEATSOCC - 1.
      UPDATE SFLIGHT FROM SFLIGHT_WA.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    UPDATE SFLIGHT
           SET SEATSOCC = SEATSOCC - 1.
    Point # 2
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    The above mentioned code can be more optimized by using the following code
    SELECT * FROM SBOOK CLIENT SPECIFIED INTO SBOOK_WA
      WHERE MANDT IN ( SELECT MANDT FROM T000 )
        AND CARRID = 'LH'
        AND CONNID = '0400'.
    ENDSELECT.
    Point # 3
    Bypassing the buffer increases the network considerably
    SELECT SINGLE * FROM T100 INTO T100_WA
      BYPASSING BUFFER
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    The above mentioned code can be more optimized by using the following code
    SELECT SINGLE * FROM T100  INTO T100_WA
      WHERE     SPRSL = 'D'
            AND ARBGB = '00'
            AND MSGNR = '999'.
    Select Statements       contd…           Aggregate Functions
    •     If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself.
    Some of the Aggregate functions allowed in SAP are  MAX, MIN, AVG, SUM, COUNT, COUNT( * )
    Consider the following extract.
                Maxno = 0.
                Select * from zflight where airln = ‘LF’ and cntry = ‘IN’.
                 Check zflight-fligh > maxno.
                 Maxno = zflight-fligh.
                Endselect.
    The  above mentioned code can be much more optimized by using the following code.
    Select max( fligh ) from zflight into maxno where airln = ‘LF’ and cntry = ‘IN’.
    Select Statements    contd…For All Entries
    •     The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb/max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause.
         The plus
    •     Large amount of data
    •     Mixing processing and reading of data
    •     Fast internal reprocessing of data
    •     Fast
         The Minus
    •     Difficult to program/understand
    •     Memory could be critical (use FREE or PACKAGE size)
    Points to be must considered FOR ALL ENTRIES
    •     Check that data is present in the driver table
    •     Sorting the driver table
    •     Removing duplicates from the driver table
    Consider the following piece of extract
    Loop at int_cntry.
           Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    The above mentioned can be more optimized by using the following code.
    Sort int_cntry by cntry.
    Delete adjacent duplicates from int_cntry.
    If NOT int_cntry[] is INITIAL.
                Select * from zfligh appending table int_fligh
                For all entries in int_cntry
                Where cntry = int_cntry-cntry.
    Endif.
    Select Statements    contd…  Select Over more than one Internal table
    1.     Its better to use a views instead of nested Select statements.
    2.     To read data from several logically connected tables use a join instead of nested Select statements. Joins are preferred only if all the primary key are available in WHERE clause for the tables that are joined. If the primary keys are not provided in join the Joining of tables itself takes time.
    3.     Instead of using nested Select loops it is often better to use subqueries.
    Point # 1
    SELECT * FROM DD01L INTO DD01L_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND AS4LOCAL = 'A'.
      SELECT SINGLE * FROM DD01T INTO DD01T_WA
        WHERE   DOMNAME    = DD01L_WA-DOMNAME
            AND AS4LOCAL   = 'A'
            AND AS4VERS    = DD01L_WA-AS4VERS
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT.
    The above code can be more optimized by extracting all the data from view DD01V_WA
    SELECT * FROM DD01V INTO  DD01V_WA
      WHERE DOMNAME LIKE 'CHAR%'
            AND DDLANGUAGE = SY-LANGU.
    ENDSELECT
    Point # 2
    SELECT * FROM EKKO INTO EKKO_WA.
      SELECT * FROM EKAN INTO EKAN_WA
          WHERE EBELN = EKKO_WA-EBELN.
      ENDSELECT.
    ENDSELECT.
    The above code can be much more optimized by the code written below.
    SELECT PF1 PF2 FF3 FF4 INTO TABLE ITAB
        FROM EKKO AS P INNER JOIN EKAN AS F
          ON PEBELN = FEBELN.
    Point # 3
    SELECT * FROM SPFLI
      INTO TABLE T_SPFLI
      WHERE CITYFROM = 'FRANKFURT'
        AND CITYTO = 'NEW YORK'.
    SELECT * FROM SFLIGHT AS F
        INTO SFLIGHT_WA
        FOR ALL ENTRIES IN T_SPFLI
        WHERE SEATSOCC < F~SEATSMAX
          AND CARRID = T_SPFLI-CARRID
          AND CONNID = T_SPFLI-CONNID
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    The above mentioned code can be even more optimized by using subqueries instead of for all entries.
    SELECT * FROM SFLIGHT AS F INTO SFLIGHT_WA
        WHERE SEATSOCC < F~SEATSMAX
          AND EXISTS ( SELECT * FROM SPFLI
                         WHERE CARRID = F~CARRID
                           AND CONNID = F~CONNID
                           AND CITYFROM = 'FRANKFURT'
                           AND CITYTO = 'NEW YORK' )
          AND FLDATE BETWEEN '19990101' AND '19990331'.
    ENDSELECT.
    1.     Table operations should be done using explicit work areas rather than via header lines.
    2.     Always try to use binary search instead of linear search. But don’t forget to sort your internal table before that.
    3.     A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime.
    4.     A binary search using secondary index takes considerably less time.
    5.     LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally.
    6.     Modifying selected components using “ MODIFY itab …TRANSPORTING f1 f2.. “ accelerates the task of updating  a line of an internal table.
    Point # 2
    READ TABLE ITAB INTO WA WITH KEY K = 'X‘ BINARY SEARCH.
    IS MUCH FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY K = 'X'.
    If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).
    Point # 3
    READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
    Point # 5
    LOOP AT ITAB INTO WA WHERE K = 'X'.
    ENDLOOP.
    The above code is much faster than using
    LOOP AT ITAB INTO WA.
      CHECK WA-K = 'X'.
    ENDLOOP.
    Point # 6
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1 TRANSPORTING DATE.
    The above code is more optimized as compared to
    WA-DATE = SY-DATUM.
    MODIFY ITAB FROM WA INDEX 1.
    7.     Accessing the table entries directly in a "LOOP ... ASSIGNING ..." accelerates the task of updating a set of lines of an internal table considerably
    8.    If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
    9.    "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”
    10.   “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.
    11.   "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “  DO -DELETE-ENDDO”.
    Point # 7
    Modifying selected components only makes the program faster as compared to Modifying all lines completely.
    e.g,
    LOOP AT ITAB ASSIGNING <WA>.
      I = SY-TABIX MOD 2.
      IF I = 0.
        <WA>-FLAG = 'X'.
      ENDIF.
    ENDLOOP.
    The above code works faster as compared to
    LOOP AT ITAB INTO WA.
      I = SY-TABIX MOD 2.
      IF I = 0.
        WA-FLAG = 'X'.
        MODIFY ITAB FROM WA.
      ENDIF.
    ENDLOOP.
    Point # 8
    LOOP AT ITAB1 INTO WA1.
      READ TABLE ITAB2 INTO WA2 WITH KEY K = WA1-K BINARY SEARCH.
      IF SY-SUBRC = 0.
        ADD: WA1-VAL1 TO WA2-VAL1,
             WA1-VAL2 TO WA2-VAL2.
        MODIFY ITAB2 FROM WA2 INDEX SY-TABIX TRANSPORTING VAL1 VAL2.
      ELSE.
        INSERT WA1 INTO ITAB2 INDEX SY-TABIX.
      ENDIF.
    ENDLOOP.
    The above code uses BINARY SEARCH for collect semantics. READ BINARY runs in O( log2(n) ) time. The above piece of code can be more optimized by
    LOOP AT ITAB1 INTO WA.
      COLLECT WA INTO ITAB2.
    ENDLOOP.
    SORT ITAB2 BY K.
    COLLECT, however, uses a hash algorithm and is therefore independent
    of the number of entries (i.e. O(1)) .
    Point # 9
    APPEND LINES OF ITAB1 TO ITAB2.
    This is more optimized as compared to
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 10
    DELETE ADJACENT DUPLICATES FROM ITAB COMPARING K.
    This is much more optimized as compared to
    READ TABLE ITAB INDEX 1 INTO PREV_LINE.
    LOOP AT ITAB FROM 2 INTO WA.
      IF WA = PREV_LINE.
        DELETE ITAB.
      ELSE.
        PREV_LINE = WA.
      ENDIF.
    ENDLOOP.
    Point # 11
    DELETE ITAB FROM 450 TO 550.
    This is much more optimized as compared to
    DO 101 TIMES.
      DELETE ITAB INDEX 450.
    ENDDO.
    12.   Copying internal tables by using “ITAB2[ ] = ITAB1[ ]” as compared to “LOOP-APPEND-ENDLOOP”.
    13.   Specify the sort key as restrictively as possible to run the program faster.
    Point # 12
    ITAB2[] = ITAB1[].
    This is much more optimized as compared to
    REFRESH ITAB2.
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    Point # 13
    “SORT ITAB BY K.” makes the program runs faster as compared to “SORT ITAB.”
    Internal Tables         contd…
    Hashed and Sorted tables
    1.     For single read access hashed tables are more optimized as compared to sorted tables.
    2.      For partial sequential access sorted tables are more optimized as compared to hashed tables
    Hashed And Sorted Tables
    Point # 1
    Consider the following example where HTAB is a hashed table and STAB is a sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE HTAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    This runs faster for single read access as compared to the following same code for sorted table
    DO 250 TIMES.
      N = 4 * SY-INDEX.
      READ TABLE STAB INTO WA WITH TABLE KEY K = N.
      IF SY-SUBRC = 0.
      ENDIF.
    ENDDO.
    Point # 2
    Similarly for Partial Sequential access the STAB runs faster as compared to HTAB
    LOOP AT STAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.
    This runs faster as compared to
    LOOP AT HTAB INTO WA WHERE K = SUBKEY.
    ENDLOOP.

Maybe you are looking for

  • Viewlink between Custom VO "Cannot set user query to view"

    We have an application where we have extended custom VO and EO's to get data from flat files. It all looks fine till we create a viewlink for a LOV with two related VO's. The viewlink VO fails we get message of the form -Cannot set user query to view

  • [xorg 7] Changing keyboard layout disables deadkeys

    I'm currently using the "us" keyboard, but I'd like to use accents the way I'm used to in Windows with the "US International" layout, i.e. press ' then e which gives me an accented e. I used to use the "us_intl" layout in xorg.conf, but somehow when

  • Lag analytical function and controlling the offset

    Can you help me on that? Small challenge. At least I gave up in half a day. Data ACCOUNT_NUMBER     BATCH_ID     TRANSACTION_DATE     TRANSACTION_TYPE     TRANSACTION_NUMBER     PARENT_TRANSACTION_NUMBER 124680     ZY000489     1/11/2011     62     3

  • Easy Setups and settings not visible

    I've created a few different easy setups and other settings for various situations as I've been working but for some reason none of the settings I've saved are accessible after I close the program. I've tried clicking the "show all" checkbox on the E

  • 2504 WLC future LAG support?

    We just bought a 2504 WLC with 15 AP licenses for our new eight 1141N AP installation.  Some confusion about LAG support for these now confirmed by TAC that LAG NOT supported for the time being.  Has anyone heard about whether this feature will be ad