Performance tuning the loop statement

Hi,
I have the following requirement.
I have an internal table IT_TEST1 which has values
Column1
A
B
C
D
consider a second internal table IT_TEST2. It'll have values like as follows:..I need to know which are the entries in column1 that have more than one entry in column 2 without looping through this internal table..Kindly suggest..
Column1 column2
A            VAL1
B            VAL1
B            VAL2
C            VAL1
C            VAL2
D            VAL1
D            VAL2
D            VAL3
This has caused very big performance issue for it is

Hi,
I have faced a similar problem and the following strategy has saved a lot of processing time
the following code may serve your pupose
if you are using IT_TEST2 for further processing please use IT_TEST3
otherwise use IT_TEST2 instead of IT_TEST3 in the code below......'
*************************CODE SAMPLE************************************
data : IT_TEST3 like IT_TEST2.  "declare internal table same as IT_TEST2
  IT_TEST3[] = IT_TEST2[]. 
    "Pass contents if IT_TEST2 is used for further processing
Sort IT_TEST1 by column1 .  "Sort
Sort IT_TEST3 by column1 .  "Sort
   loop at IT_TEST1.
           read table IT_TEST3
                with key column1 = IT_TEST1-column1.
                 if sy-subrc = 0.
                      describle table IT_TEST3 lines n.
                          if lines > 1.
                             "Multiple entries
                           else.
                             "Single entry
                          endif.
                 endif.
  "Perform all operations on IT_TEST3
    DELETE IT_TEST3 WHERE  column1 = IT_TEST1-column1.
"Delete the entry in IT_TEST3 already processed with the key of IT_TEST1
"Next time you do the read entries for the previous and all predecessor loops
will not be there'
"As you go down the loop performance increases
endloop.
Regards
Byju

Similar Messages

  • Performance issue in Loop statement.

    Hi experts,
    I got an issue regarding performance in the loop statement. (IT_OUT_FINAL has huge amount of data.)
    LOOP AT it_out_final INTO wa_out_final.
    READ TABLE it_prdline_txt
    WITH KEY ydprodln = wa_out_final-prdline.
    IF sy-subrc = 0.
    wa_out_final-prdline = it_prdline_txt-ydvtext.
    MODIFY it_out_final FROM wa_out_final TRANSPORTING prdline.
    CLEAR: wa_out_final.
    ENDIF.
    read table i_sokna with key kunnr = wa_out_final-kunnr.
    if sy-subrc eq 0.
    wa_out_final-soreg = i_sokna-regio.
    MODIFY it_out_final FROM wa_out_final TRANSPORTING soreg.
    endif.
    read table i_sokna with key kunnr = wa_out_final-kunwe.
    if sy-subrc eq 0.
    wa_out_final-shreg = i_sokna-regio.
    MODIFY it_out_final FROM wa_out_final TRANSPORTING shreg.
    endif.
    clear : i_sokna,wa_out_final.
    ENDLOOP.
    Can you please help me , how to improve the performance in the above loop statement.
    Thanks,
    Revanth Kumar
    Moderator message: duplicate post locked.
    Edited by: Thomas Zloch on Jun 20, 2011 1:22 PM

    Hi,
    This one helped me in understanding the basics clearly. But I would like to further give you one example by which my question will be more clear to you and hence your further answer to it will help me in getting the idea about WHERE clause clarified.
    I was required to develop a report of all held docs by the SAP USER that were created through transaction FB60, the input obtained from user should be SAP USERNAME(obligatory).
    So the straight approach by me was that writing a SELECT-OPTIONS asking SAP USERNAME, and such username obtained from USER executing a report will be compared with the USERNAME stored in the column of table RFDT which stores all such held docs by a SAP USER that used transaction FB60 to temporarily hold it.
    So the approach used by me was using the select statement fetch all records from the column storing the SAP USERNAMES that have held docs using FB60 transaction and where clause is used to filter out only values matching the values obtained from user i.e. using SELECT-OPTIONS.
    So I was under the impression that WHERE clause can only be used in SELECT STATEMENT and not in LOOP AT...ENDLOOP.
    Now I hope my question is more clear to you. If I am not wrong, there can be two approaches,
    1) Using a SELECT statement containing the WHERE clause, fetch a resultset and then using LOOP...ENDLOOP. statement, display the output of the report using WRITE statement.
    i.e. SELECT...WHERE...ENDSELECT and then LOOP AT...ENDLOOP.
    2) Using SELECT statement, fetch all possible records and using LOOP...ENDLOOP. statement filter out the records using WHERE to match the resultset and display values in that resultset using WRITE statement
    i.e. SELECT...ENDSELECT and then LOOP AT...WHERE...ENDLOOP.
    Hope you will now be able to guide me better.
    Regards
    Ameet

  • ASSIGNING addition  used in the LOOP statement

    Hello Guys ,
    I have a problem about at new  and at end statements, basically I want to use them in a loop with  assigning  like this :
    loop at ti_itab assigning <wa_itab>.
        at new of kunnr.
        endat.
        at end of xref1.
        endat.
    endloop.
    xref1 and kunnr are fields of my table itab , this is the correct form of do this ?  I don´t know why the at  statements are doing  control breaks for every single   register in my table ( even when both have the same value of the previous register ) , could you give me an example please. should i use  at new of <wa_itab>-kunnr it doesnt work either ?
    thank you very much,.

    Hi José,
    Click on below link:
    http://help.sap.com/saphelp_nw04/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/content.htm
    BR
    Dep

  • Error message in the loop statement

    Hi Experts:
                    In my ABAP program,
                    In the loop of internal table,when match some condition,the system give error message, or go on.
                    Now,if the internal table has ten records,  three records match some condition,the others need
                           process going on.
                    But in my program,if finds error record,giving error message,can't process other records.
                    I want it can not only show error message,but also process other records.
                    Pls give me some advice,tks!

    Hi,
    Message type E is error type and it will terminate your program.
    So either we can declare the message type E as information message or status or we can add a varaible flag which can be set on error.
    So that it would not terminate the program.
    Example :
    Loop at inttable1.
    if condition for error
    flag = 'X'.
    continue.
    endif.
    endloop.
    Outside the loop.
    if flag = 'X'.
    message in other internal table with details.
    endif
    Hope this helps.
    Thanks,

  • Performance tuning in loop at itab statements

    Hi ,
    I have one internal table lets ITAB1[] ,
    Its having 15,0000 Records.
    now I want to search only 5 records from ITAB1[] compairing ITAB2[] , ITAB2 having  15,0000 records.
    what is best method to search this records in minimum time.
    loop it ITAB1.
    Read table ITAB2 with = ... binary search.
    Endloop.
    Prblem is that , above statemnt will take 15,0000 intration at each statment while reading.

    Hi,
    loop it ITAB1.
    Read table ITAB2 with = ... binary search.
    Endloop.
    I think whatever code you are using now is appropriate only.
    As you want to read record from ITAB1 based on data in ITAB2, you will have to loop at ITAB2 and then do binary search on ITAB1. Just make sure that your table ITAB1 is sorted correctly as per the binary search criteria.
    Thanks,
    Archana

  • Performance Tuning the AVG function

    Dear All,
    I have a table which is rapidly growing. We have a query which is frequently executed on this table and it utilizes AVG function without a WHERE clause. Is there a way to tune this query?
    I tried to create a Materialized View but Oracle rejects as AVG cannot be used in MV's. Also, it is now really easy at this point in time to rewrite the query.
    Appreciate if anybody can help me out in this situation.
    OS: Windows 2003 EE
    Database: Oracle 10g R2 10.2.0.4
    Sample Table:
    Create table t(id number, name varchar2(30), amt number);
    insert into t select level, 'level - ' || level, level * 100 from dual connect by dual level <= 1000;
    commit;
    Query:
    select avg(amount) from t;
    Thanks for you time.
    - P

    >
    ... and it utilizes AVG function without a WHERE clause
    >
    As Aman stated, a full table scan will be needed for a statement without a WHERE clause.
    See these threads on how to post a tuning request
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HTH
    Srini

  • Performance in the select statement

    Hi All,
    (select a.siteid siteid,a.bpaadd_0 bpaadd_0,a.bpanum_0 bpanum_0,
    case when a.bpaaddlig_0 = '' then '-' else a.bpaaddlig_0 end
    address1,
    case when a.bpaaddlig_1 = '' then '-' else a.bpaaddlig_1 end
    address2,
    case when a.bpaaddlig_2 = '' then '-' else a.bpaaddlig_2 end
    address3,
    case when a.bpades_0 = '' then '-' else a.bpades_0 end place,
    case when a.cty_0 = '' then '-' else a.cty_0 end city,
    case when a.poscod_0 = '' then '-' else a.poscod_0 end
    pincode,
    case when b.cntnam_0 = '' then '-' else b.cntnam_0 end
    contactname,
    case when b.fax_0 = '' then '-' else b.fax_0 end fax,
    case when b.MOBTEL_0 = '' then '-' else b.MOBTEL_0 end mobile,
    case when b.TEL_0 = '' then '-' else b.TEL_0 end phone,
    case when b.web_0 = '' then '-' else b.web_0 end website,
    c.zinvcty_0 zcity,c.bpainv_0 bpainv_0,c.bpcnum_0 bpcnum_0
    from lbcreport.bpaddress@info a,lbcreport.contact@info b
    ,lbcreport.bpcustomer@info c
    where (a.bpanum_0=b.bpanum_0) and (a.cty_0 = c.zinvcty_0) and
    (a.siteid = c.siteid))
    In the above query Is there any performance degradation could i proceed with same query
    or any other solution is there to increase the speed of the query.
    in one select statement these many cases are allowed ah?
    Please could anybody help me in this?
    Thanks in advance
    bye
    Srikavi

    Change you query as follows...
    (select
         a.siteid siteid,
         a.bpaadd_0 bpaadd_0,
         a.bpanum_0 bpanum_0,
         nvl(a.bpaaddlig_0, '-') address1,
         nvl(a.bpaaddlig_1,'-' ) address2,
         nvl(a.bpaaddlig_2,'-' )  address3,
         nvl(a.bpades_0,'-' ) place,
         nvl(a.cty_0,'-' ) city,
         nvl(a.poscod_0,'-' ) pincode,
         nvl(b.cntnam_0,'-' ) end
         contactname,
         nvl(b.fax_0,'-' )  fax,
         nvl(b.MOBTEL_0,'-' )  mobile,
         nvl(b.TEL_0,'-' )  phone,
         nvl(b.web_0,'-' )  website,
         c.zinvcty_0 zcity,c.bpainv_0 bpainv_0,c.bpcnum_0 bpcnum_0
    from
         lbcreport.bpaddress@info a,
         lbcreport.contact@info b,
         lbcreport.bpcustomer@info c
    where
         (a.bpanum_0=b.bpanum_0) and
         (a.cty_0 = c.zinvcty_0) and
         (a.siteid = c.siteid))
    / For performace check the execution plan of the query.. also BluShadow's post
    Regards
    Singh

  • Slow performance of the SQL statement

    Hi All,
    the verison of the db is 10.2.0.5 & the windows 2008 server OS version. Currenty we are facing the issue with a particular query which is taking a long to complete. The query is within a procedure and its consuming resources highly like RAM,CPU,etc. the present size of SGA is 8GB .
    Please let me know how to troubleshoot it. I just need to resolve it and its taking lot of time to resolve it. Please help me out.
    Regards,
    imran khan

    DB verion is 10.2.0.4.0
    OPtimizer related parameters :
    SQL> show parameter optimizer
    NAME TYPE VALUE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 100
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    The job runs daily and not sure how to generate the trace file.
    Regards,
    imran khan

  • How to compare two fields from the same table in the select statement

    Hi, friends
    I try to compare tow fields from the same table, but no result,
    For example, this
    data: cptotchek tyep i.
    select count(*) into cptotchek
    from aufk where erdat = aufk-idat2 .
    The result is  cptotchek = 0, but there are the records in aufk , where,  aufk-erdat = aufk-idat2.
    Please, help me, i don't use the loop statement for optimize my program.
    Regards

    Hi  ,
           it will not return  any value   when you are using   column of same table 
           such as Date Field   , Because  while Using Aggregate Function  it will not check with self column
    .      For that you have to take data in one internal table and then you can work on it  .
         And if you are worried about Performance  it will not affect  , untill you are selecting only required data  .
    you can try this way  .
    data: cptotchek type i.
    types : begin of  w_aufk.
            include structure aufk  .
          types : end of  w_aufk .
    data : it_aufk type standard table of w_aufk with header line  .
    select * into corresponding fields of table it_aufk
    from aufk  .
    loop at it_aufk .
    if it_aufk-erdat  = it_aufk-idat2 .
    write : / it_aufk-erdat , it_aufk-idat2 .
    else .
    delete it_aufk .
    endif  .
    endloop.
    Regards
    Deepak.

  • BDB Performance Tuning.

    Hello All,
    In efforts to tune BDB JE's performance, I'd like to ask everyone what sort of things you have looked at and tried. The application looks like this: it has multi-threaded reads/writes with large number of small entries. One thread for writing and another for reading. Most the performance tuning is needed on writing to the database, preferably to support stable insertion/modification times. Each entry is no more than 4KB (keys and entries are constant size)
    Some research indicates that changing page size to be equal to the size of the entry is helpful. I've looked at this: http://www.oracle.com/technology/documentation/berkeley-db/db/gsg/JAVA/dbconfig.html#pagesize
    However, DatabaseConfig.setPageSize() is nowhere to be found. Am I missing something? Where can I access this setting?
    I've also been having problems with database grinding to a near halt with large amounts of entries (under 1 mil) and total database file size of about 800MB. What are the general suggestions/practices for speeding things up? In this case performance is preferred over memory use.
    Thank you,
    Mike.

    Hi Mike,
    Some research indicates that changing page size to be
    equal to the size of the entry is helpful. I've
    looked at this:
    http://www.oracle.com/technology/documentation/berkele
    y-db/db/gsg/JAVA/dbconfig.html#pagesize
    However, DatabaseConfig.setPageSize() is nowhere to
    be found. Am I missing something? Where can I access
    this setting?You're looking at the docs for the wrong product -- that's the C product. The JE docs are here:
    http://www.oracle.com/technology/documentation/berkeley-db/je
    (Note the je suffix as opposed to the db suffix, which is the C product.)
    I've also been having problems with database grinding
    to a near halt with large amounts of entries (under 1
    mil) and total database file size of about 800MB.
    What are the general suggestions/practices for
    speeding things up? In this case performance is
    preferred over memory use.Have you tried increasing the JE cache size (EnvironmentConfig.setCacheSize)? In general, databases perform better with more memory. But to do performance tuning the first step is to normally print out the EnvironmentStats periodically and correlate changes in the stats with the performance you're seeing. Please see the performance section of the JE FAQ:
    http://www.oracle.com/technology/products/berkeley-db/faq/je_faq.html
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • R12 Performance Tuning...

    Are there any docs or notes that one can to follow for EBS R12 performance tuning ?
    Regards,
    Rupdipt

    Hi,
    Please refer to the following links:
    Performance Tuning the Apps Database Layer
    http://blogs.oracle.com/schan/newsItems/departments/release12/2007/05/17#a1562
    Understanding JDBC Connections From the eBusiness Middle Tier
    http://blogs.oracle.com/schan/newsItems/departments/release12/2007/09/20#a2051
    Performance Tuning for the E-Business Suite
    http://blogs.oracle.com/schan/newsItems/departments/release12/2007/12/11#a2297
    The following notes/links provide guidelines for setting up JVMs (Jserv groups/OC4J instances) for online applications in Apps 11i and R12:
    Note: 362851.1 - Guidelines to setup the JVM in Apps Ebusiness Suite 11i and R12
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=362851.1
    Note: :462550.1 - Generate JVM heap dump in E-Business suite 11i and R12
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=462550.1
    Latest JVM Tuning Recommendations for Apps 11i
    http://blogs.oracle.com/schan/2007/03/01
    Tuning JVMs with Apps 11i
    http://blogs.oracle.com/schan/2007/02/16#a1230
    Configuring Middle-Tier JVMs for Applications 11i
    http://blogs.oracle.com/schan/2006/08/01#a494
    For tuning other application components (i.e. CM, initialization parameters, top SQL statements, application tier, ..etc), the following note should be helpful:
    Note: 169935.1 - Troubleshooting Oracle Applications Performance Issues
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=169935.1
    Note: 244040.1 - Oracle E-Business Suite Recommended Performance Patches
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=244040.1
    Note: 744143.1 - Tuning performance on eBusiness suite
    https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=744143.1
    Regards,
    Hussein

  • Performance tuning for String operation in Field routine

    Dear Experts,
    I am writing a ABAP routine in field level  for capturing an occurence of a string.
    The string may occur in anny of the values  in itab. The ITAB has around 100 thousand records and the source package 400 thousand records.
    My coding goes as
    LOOP AT INV_ITAB INTO INV_WA.
      IF SOURCE_FIELDS-/BIC/X_ASSIGNM  CS INV_WA-XFIELD3(7).+
         RESULT = INV_WA-PO_NO.
         EXIT.
      ELSE.
         RESULT = 'NA'.
      ENDIF.
    ENDIF.
    Now the coding takes more than 15 hours and still running. (It is working fine for small number of records) .
    I beleive the problem is in the LOOP statement (goes around 400000*100000 times). Is it possible for me to somehow improve this code so as to decrease the load time.
    Kindly help on this.
    Thanks,
    Rajarathnam.S

    Hi,
    I think you can use this code in your start routine instead of field level it will speed up your process.As it checks on datapacket level instead of checking records one by one.
    I am just putting some logic
    LOOP AT INV_ITAB INTO INV_WA.
    IF  Datapackage-/BIC/X_ASSIGNM   CS INV_WA-XFIELD+3(7).
    Datapackage-targetfield = INV_WA-PO_NO.
    EXIT.
    ELSE.
    Datapackage-targetfield = 'NA'.
    ENDIF.
    ENDIF.
    Regards,
    Ravi

  • Regarding LOOP Statement in ABAP

    Hi,
    I have small question regarding <b>LOOP ..... ENDLOOP</b> statement against <b>SY-SUBRC</b> Check.
    I have a loop as below:
    <b> LOOP AT i_vbap WHERE vbeln = i_vbak-vbeln.
        Some Code
        ENDLOOP.
        IF sy-subrc <> 0.
          APPEND i_sdata.
          CLEAR i_sdata.
        ENDIF.</b>
    Is the above <b>Code/Syntax</b> is correct one.
    Can we use <b>SY-SUBRC</b> Check against <b>LOOP ...  ENDLOOP</b> statement.
    Is this the right way of writing the code as per standards.
    Can anybody give sujjestions regarding the same.
    Thanks in advance.
    Thanks & Regards,
    Prasad.

    Hi Prasad,
    Yes, you could use sy-subrc after the endloop. For example:
    loop at itab1 where kunnr = itab2-kunnr.
    some conditions...
    endloop.
    if sy-subrc = 0.
    write: 'Success!'.
    else.
    leave program.
    endif.
    if you press F1 while highlighting the LOOP statement here are the meaning of sy-subrc in loop...endloop.
    SY-SUBRC = 0:
    At least one loop pass was processed.
    SY-SUBRC = 4:
    The loop was not processed because the table contains no entries or no entries satisfied the conditions.
    Regards!

  • Delete internal table rows without using loop statement

    i have an internal table which consists of 100 records.
    i need to keep only first 5 records.
    without using the loop statement i need to delete the rest of the records. how can we achieve this result.
    i.e.  delete itab1 where  "recordno"  > 5.
    regards.
    ZG

    Hi,
    Delete itab [FROM idx1] [TO idx2] {Where (log_exp)]
    To delete several lines at once, you have to specify at least one of the additions FROM, TO, or WHERE. You can only use the additions FROM and TO with standard tables and sorted tables.
    Delete itab [FROM idx1]
    If you specify FROM, all the table rows from the table index idx1 onwards are included.
    Delete itab [TO idx2]
    If you specify TO, all the table rows from the table index idx2 onwards are included.
    PARAMETERS: p_carrid TYPE sflight-carrid,
                p_connid TYPE sflight-connid.
    DATA: BEGIN OF seats,
            fldate    TYPE sflight-fldate,
            seatsocc  TYPE sflight-seatsocc,
            seatsmax  TYPE sflight-seatsmax,
            seatsfree TYPE sflight-seatsocc,
          END OF seats.
    DATA seats_tab LIKE STANDARD TABLE OF seats.
    SELECT fldate seatsocc seatsmax
           FROM sflight
           INTO TABLE seats_tab
           WHERE carrid = p_carrid AND
                 connid = p_connid.
    LOOP AT seats_tab INTO seats.
      seats-seatsfree = seats-seatsmax - seats-seatsocc.
      MODIFY seats_tab INDEX sy-tabix FROM seats.
    ENDLOOP.
    ENDLOOP.
    SORT seats_tab BY seatsfree DESCENDING.
    DELETE seats_tab FROM 5.
    Thanks & Regards,
    ShreeMohan
    Edited by: ShreeMohan Pugalia on Jul 21, 2009 4:28 PM

  • Performance Issie in SQL Statement Using Hints

    Hi,
    I am using Oracle version 10G.
    I am using a INSERT statement as:
    INSERT /*+ PARALLEL (TEST,4) */ INTO TEST(COL1,COL2,COL3) SELECT COL1,COL2,COL3 FROM DUMMY;
    For increasing the Performance I am using the above statement.
    Will the usage of Hints increase the Performance?
    Any help will be highly needful.
    Thanks and Regards

    user598986 wrote:
    I am using Oracle version 10G.
    I am using a INSERT statement as:
    INSERT /*+ PARALLEL (TEST,4) */ INTO TEST(COL1,COL2,COL3) SELECT COL1,COL2,COL3 FROM DUMMY;
    For increasing the Performance I am using the above statement.
    Will the usage of Hints increase the Performance?The way you're asking the question suggests that you're not sure what this particular hint is supposed to imply.
    Using this hint suggests that you want to take advantage of direct-path parallel DML operations. Note that you explicitly need to enable parallel DML in your session, it is disabled by default, because it has some significant implications and restrictions. You should think about parallelizing the query on DUMMY, too, if it is not marked as PARALLEL in the dictionary, because otherwise you're combining a parallel DML operation with a serial query which might not be that efficient.
    Note that there is no general answer to the question if this particular hint will actually increase the performance of the DML statement. There are many things to consider, among them are if your system scales reasonably with parallel operations and if the underlying object structure actually allows to benefit from the parallel operation. There are cases where a serial operation might be faster than a parallel operation.
    For more information about direct-path and parallel execution, its implications and restrictions, see the documentation:
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_9014.htm#i2163698
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28313/usingpe.htm#CACEJACE
    You can use the EXPLAIN PLAN and the DBMS_XPLAN.DISPLAY function to get the execution plan of your statement that shows you what kind of parallel operations the optimizer estimates to perform.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

Maybe you are looking for