Existence of a record

Hi,
I am a starter to Oracle. I wanted to find the existence of a record in a table and then depending on the existence I have to add records to other tables.
I mean depending on the existence I have like 3 cases to handle. Is it possible to store(temp variable) the result of the query to find existence and use the value of the temp variable to run other cases. If so can anyone show a small query.
Thanks in advance.
VR.

Are you working with PL/SQL?
you can check for existence in PL/SQL with something like
select count(*) into local_variable
from table
where ...
if you are in straight SQL you would need to use a not exists clause.
i.e.
insert into table
select a, b, c
from dual
where not exists ( query that would return you row here..)

Similar Messages

  • Checking for existence of a record in csv file

    Hey all, I have two csv files residing on the server that I will be processing using the UTL_FILE package. One of these files (File A) has only one column and the other one (File B) has over ten. The data in file A is the same as the one in column 2 of File B. File A is mainly there for a lookup purpose whereas File B is the one that has all the data that will be processed. The following example should describe better:
    File A[b]
    Number
    "TR_56575"
    "TY_76756"
    etc
    File B
    Column1, Number, Column3, Column4
    "Mine","TR_56575","uhsht","76744"
    "Yours","TY_76756","nghdjd","45645"
    What I have to do is check whether a Number in File B exists anywhere in File A. If it does then I just skip that record and move on to the next. So basically, I wanted to find out if there is any way to compare the two columns on the server side. I know there is a dbms_lob.fileexists function to check the existence of a file on a server, just wanted to see if there is an extension to that or something that checks the existence of a string in file. Any feedback would be appreciated. Thanks.

    Yeah I thought about that. It would be the ideal way to go, however in this case, I already have a Pl/Sql procedure that grabs File B and just processes it from the server. It works fine and everything but now that this extra logic and file is added where I have to check the existence of a corresponding record in File A, I'm just looking for something to add in my code to just make the comparison on the fly and the rest would be the same.

  • Check for existence of a record

    I have a table XX_TEMP. Let us say the columns are inventory_item, organization_id and description
    The values are:
    Inventory_item
    Organization
    Description
    200
    m1
    Sample
    200
    m2
    Not Sample
    400
    m4
    check
    700
    m5
    Test
    I just want to check the existence of an item in the table, I have written two queries and would like to know which one is better in terms of performance:
    Q1:
    select count(1) from xx_temp where inventory_item=200 and rownum=1;
    Q2:
    select count(1) from dual where exists (select 1 from xx_temp where inventory_item=200);
    Both Q1 and Q2 return the same result. In fact, I was surprised with the result from Q1 as I expected that the rownum would be evaluated after the where condition. I expected Q1 to return 2
    I thought that the below query:
    select count(1) from xx_temp where inventory_item=200;
    and Q1 would return the same result as rownum would be evaluated at end. In effect, I've 2 questions:
    1. Isn't rownum calculated at the end?
    2. What is the best way in terms of performance to check for an existence of record?

    Internally this is how it works:
    select count(*) from xx_temp where inventory_item=200 and rownum=1;
      COUNT(*)
             1
    1 row selected.
    Execution Plan
       0       SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=4 Card=1 Bytes=13)
       1    0    SORT AGGREGATE (Card=1 Bytes=13)
       2    1      COUNT STOPKEY
       3    2        TABLE ACCESS FULL XX_TEMP (Cost=4 Card=2 Bytes=26)
    Statistics
              5  user calls
              0  physical read total multi block requests
              0  physical read total bytes
              0  cell physical IO interconnect bytes
              0  commit cleanout failures: block lost
              0  IMU commits
              0  IMU Flushes
              0  IMU contention
              0  IMU bind flushes
              0  IMU mbu flush
              1  rows processed
    Plan
    1 Every row in the table XX_TEMP  is read.
    2 Processing was stopped when the specified number of rows from step 1 were processed.
    3 The rows were sorted to support a group operation (MAX,MIN,AVERAGE, SUM, etc).
    4 Rows were returned by the SELECT statement.
    COUNT STOPKEY knows how many rows you want and will just keep calling its child function under it in the execution plan tree to get more and more rows, until the required amount of rows have been returned. Here it stopped at 1 iteration.
    And to answer your second question : as to which is the fastest way to to check  for an existence of record :
    Answer would be it depends on your requirement.  possible answers are :  Rowid --  fastest way to check for a row.   similar answers can be Index etc.. but all this is relative to what you work with.
    Cheers,
    Manik.

  • Creation of Q-Info record from data in exel sheet published in cfolder

    Hi
    Can any body help to give solution to create Q-Info Record from the data published in exel sheet under collaboration folder.
    This we require for triggering the event for creation of Q-Info from the data available in cfolder in exel sheet which will be furnished by the user who can access organisation's network i.e. R3 network.
    Thanks
    YPB

    Hello Rao,
    My objective is to create/change Q-Info Record through event trigger mechanish from the input data submitted by the vendor in excel sheet input format in cfolder.Details of steps are as follows:-
    1. Input data from the organisation like PO No. Item no, Material Code and all probable vendor code with details of vendor like address, city will be published in the cfolder in excel sheet. This sheet will be availble to vendor as Input data.\
    2. Input data will be updated by the vendor in following manner
        A- Material code of PO, Vendor code(Manufacturer code), Drawing No agreed between Organisation and vendor.
    3. System will pick up the data updated in excel sheet and will trigger the event for creation of Q-Info which will check first existence of the Record, if exists then system will change the record.
    How can I do this? Can any body help me. 
    YPB

  • How to ensure a record is created in a block linked to a detail block?

    Hi All,
    I am stuck. In my form I have a master block (blockA), a detail block (blockB) and a third block (blockC) that is linked to blockB via a standard relation on blockB where blockB.id = blockC.id. In blockB if column adtype = 'P' then the requirement is that a corresponding record is entered into blockC. So If I enter several detail records into blockB and set adtype = 'P' on each then I can double click on each and add the details to blockC. Save. This works fine and when I re-query each of the records can be seen as appropriate. The problem I'm facing is enforcing a record to be entered into blockC based on the adtype equaling 'P' in blockB. I have tried performing checks in lots of different triggers but to no avail the same thing keeps happening which is this. If I create more than one record in blockB with an adtype of 'P' but don't enter any details into blockC my checks will always flag this up when saving. If however I enter some details into blockC for the first of the records from blockB with an adtype of 'P' then all checks are passed and no errors are raised. It is as if that now a record exists in blockC I can no longer check for the existence of a record even though that record is only applicable to the first record in blockB and not any of the others??
    I hope I have explained this clearly enough for someone to come to my aide as I am truly stumped!
    Many Thanks in advance
    Matt

    I think I understand your situation (a bit difficult to follow indeed) but the problem might be here:
    > If I create more than one record in blockB
    With a master-detail, you have to save the master and detail data before continuing to another master record. So, you cannot enter several records in blockB and several records in blockC at the same time.
    I wonder, did you never get a "do you want to save the changes" message when going from one record in blockB to the next?

  • Prepared SQL statement to test existence of a value in a row

    Excuse my ignorance in SQL. I didn't do much in SQL queries or DB design in general, but I'm eager to learn.
    Idea behind: I'm traversing a directory tree (Java, jdbc) (depth first) and want to collect all files
    in that tree and put the as BLOBS into the database.
    To find out whether a file is the same as another file (possibly in a different path) I calculate the md5sum
    (not sure whether it is proof against collisions or if I should use SHA-256 or some combination of md5sum + chksum).
    Anyway, let the md5sum be the unique value that makes the identity of a file for now.
    My problem: Find the jdbc/SQL statements that let me decide whether the file (md5sum) is already stored in a ROW
    upon which I can decide to either do the INSERT or mark the existing file as being present in a different path.
    I stumbled across the problem in the moment when I first time tried to INSERT a row and got told that
    md5sum gotta be unique.
    Any ideas for design and query? The code example below is incomplete. Especially what I'm looking for is
    how to construct a prepared SQL statement into which I can inject the variable later found (md5sum)
    Whether I should do that by COUNT(*) or a different method?
    Christoph
    Here is my sketchy code (Netbeans project) under construction:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package testsqlite;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import java.sql.*;
    import java.util.Iterator;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author chris
    public class Main {
    * @param args the command line arguments
    private static Connection conn;
    private static String sql="INSERT INTO part(name,md5sum) VALUES (?,?)";
    private static PreparedStatement pstmnt,pstmnt_ifexists ;
    private static String sql_ifexists="SELECT COUNT(*) FROM part WHERE md5sum=?"; // ???
    public static void main(String[] args) throws Exception{
    // TODO code application logic here
    System.out.println("Testsuite-Collector\n");
    String path="c:/usr/local/www/data/testsuite/mandanten/chris/probanden";
    File f = new File(path);
    Class.forName ("org.sqlite.JDBC");
    conn =
    DriverManager.getConnection("jdbc:sqlite:c:/users/chris/testsuite/versionen");
    Statement stat = conn.createStatement();
    pstmnt = conn.prepareStatement(sql);
    pstmnt_ifexists = conn.prepareStatement(sql_ifexists);
    // process
    Traverse(f);
    // watch result
    ResultSet rs = stat.executeQuery("select * from part;");
    while (rs.next()) {
    System.out.print("name=" + rs.getString("name") + " ");
    System.out.println("md5sum= " + rs.getString("md5sum"));
    rs.close();
    conn.close();
    private static void Traverse(File f) throws IOException {
    File[] files = f.listFiles();
    for( File file : files) {
    if(file.isDirectory()){
    Traverse(file);
    else {
    try {
    if(file.length() > 0){
    FileInputStream fis = new FileInputStream( file );
    String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex( fis );
    System.out.println(file.length() +" " md5"->"+file.getPath());
    // check whether md5sum is already existing
    pstmnt_ifexists=?????
    pstmnt.setString(1, file.getPath());
    pstmnt.setString(2, md5);
    pstmnt.executeUpdate();
    catch (SQLException e) {
    System.out.println("SQL error:" e.getMessage()"\n");
    }

    And you seriously think that attempting to insert a record and catching the error of it failing is a good design!?!?I certainly do. I agree with Peter here. You can either test for the existence of the record and insert it if absent, or insert the record willy-nilly and catch the exception. The second option is (a) atomic even without transactions and (b) clearly twice as efficient. Same consideration applies to e.g.
    if (!map.containsKey(key))
      map.put(key, value);
    else
      ; // it was already thereas opposed to
    if (!map.put(key, value)
      ; // it was already thereand many other situations of this kind, e.g.
    try
      if (InetAddress.isReachable(ip))
        s = new Socket(ip, port);
      else
        ; // host not up
    catch (ConnectException exc)
      // the host wasn't up during connect
    }as opposed to
    try
      s = new Socket(ip, port);
    catch (ConnectException exc)
      // host not up
    }or
    try
      if (file.exists())
        in = new FileInputStream(file);
      else
        ; // it wasn't there
    catch (IOException exc)
      // it wasn't there, etc ...
    }as opposed to
    try
      in = new FileInputStream(file);
    catch (FileNotFoundException exc)
      // it wasn't there
    }Slight absence of timing window problems in the cases that detect via exceptions, and considerably simpler code. Phobias about how to use exception handling need to be overcome.
    I've also had it seriously argued to me that you shouldn't catch EOFExceptions, merely change the format of your file so you 'know' when one is coming up. Sorry to say that I think this sort of thing is complete rubbish. There is a need for an out of band EOF signal with all the readXXX() methods, and this is it.

  • Valid Records Update, Reporting Possible (Request Green)

    Hi, My company operates change run every night.
    Yesterday, an error occured when loaded data from DSO to cube.
    I guess that there was strange character BW can't recognize.
    Because error had been handled too late, a whole chain was delayed.
    I don't want that this situation happen again.
    I want to skip the error records  so that change run can be operated on schedule.
    As I know, It is possible by using "Valid Records Update, Reporting Possible (Request Green)" option on DTP.
    But, I heard that when I apply this option, there will be no error logs. Is it right?
    I think It can cause the problem of data consistency.
    So, I have question.
    1. Can I get error logs using "Valid Records Update, Reporting Possible (Request Green)" option?
    2. Is there any other way to know existence of invalid records (even if chain skip that record)
    3. If question 1 or 2 are not possible, can an customizing abap program perform this action?
    Thank you.

    Hi,
    can you discribe what's your master data check is like. Propably not your skip record exception is rissen but another exception by sap standard masterdata check. It's behviour may differ from the skip record exception you are expecting.
    Check http://help.sap.com/saphelp_nw70/helpdata/en/42/fbd598481e1a61e10000000a422035/content.htm for other types of exception by SAP errorhandling.
    Regards Michael

  • Hi I'm trying to record audio

    Is there any application in existence that can record audio from a website or audio that is currently playing in a program (ie Itunes). any help is appreciated. Thanks!!

    The best I've found for ease of use is Wiretap Pro by Ambrosia.

  • 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.

  • Performance issue on a select statement

    Hi all @ SAPforums and thanks for your attention,
    the task is quite simple: given a Purchase Requisition number and position (banfn, bnfpo) I have to check if a contract with the same PR as source exists in the EKPO table.
    In order to check for it, I simply typed the following select:
    SELECT SINGLE * FROM EKPO INTO wa_checkekpo
          WHERE bstyp EQ 'K'
            AND banfn EQ l_eban-banfn
            AND bnfpo EQ l_eban-bnfpo.
    This kind of query is quite consuming (more than three seconds in my process) due to the fact that banfn and bnfpo don't belong to a key for the table.
    Any idea/workaround that can lead to better performance? Please note I'm not interested in retrieving the contract number (KONNR), it's sufficient to know it exists.

    Hi,
    > Do not use select * if you just want to check existence of the record.
    so far so good.
    > Use a single variable to store teh count.
    But why should we count the records if we just want to know if a key exists in
    the db or not? change the second half of the recommendation to:
    Use a single field of the used index for the select list to check (sy-subrc or result
    of that field) if the record exists or not.
    Kind regards,
    Hermann

  • Transfer of fields from ECC to APO

    Hi All,
    I have a requirement where in I need to implement logic for Repl. Lead time as follows -
         1. check if the purchase info record exists
              if exists, then check if the current date is between lifba and lifbi of EINA table
                   if exists then pass EINE-APLFZ to AT101 field of cif_matloc
         2. if purchase info record does not exist, then pass the lead time from Material Master data.
    I have done the coding in Exti_SAPLCMAT_001 (ZXCIFU01).
    the issue is, its not checking for the existence of info record, directly the lead time is being taken from material master data.
    Pls help...this is an urgent issue.
    Thanks & Regards,
    SriLalitha. 

    Hi SriLalitha,
    I have loaded a document explaining how you can set defaults values in APO MAT1 when the material is CIFfed. See this document, here you have the ABAP code:
    http://scn.sap.com/docs/DOC-56755
    This need to be done in APO, thru BAdI: BADI SMOD_APOCF005. In the ABAP code in APO you will need to use function: 'RFC_READ_TABLE' in order to get the details from table EINE. In my example, I am doing something similar checking values from tables MARA and MARC.
    Thanks and Regards,
    Mariano

  • Getting DRG-50858: OCI error: OCI_NO_DATA with user_datastore on 9iR2

    Hi there,
    Created a procedure and mapped it to a user_datastore... getting the following error in the ctx error table:
    DRG-12604: execution of user datastore procedure has failed
    DRG-50857: oracle error in drsinopen
    DRG-50858: OCI error: OCI_NO_DATA
    Created the following preferences:
    begin
    -- set the user datastore procedure
    ctx_ddl.create_preference('ccnews_ud', 'user_datastore');
    ctx_ddl.set_attribute('ccnews_ud', 'procedure', 'ctxsys_ccnews_ustore_idx_prc');
    ctx_ddl.set_attribute('ccnews_ud', 'output_type', 'CLOB');
    ctx_ddl.create_preference('english_lexer','basic_lexer');
    ctx_ddl.create_preference('french_lexer','basic_lexer');
    ctx_ddl.create_preference('global_lexer', 'multi_lexer');
    ctx_ddl.add_sub_lexer('global_lexer','default','english_lexer');
    ctx_ddl.add_sub_lexer('global_lexer','ENGLISH','english_lexer','1');
    ctx_ddl.add_sub_lexer('global_lexer','FRENCH','french_lexer','2');
    end;
    Is it possible that the procedure returns an empty clob for a row which causes this problem?
    The index is running on a table with 28,000 rows, I have to admint that the data integrity is not up to par (ie could be existence of orphaned records) Could this cause the problem?

    An empty clob or even an orphaned record should not cause the problem. It is usually due to a bug in the procedure. Data corruption could be a cause. Please post a copy and paste of a run of create or replace for your procedure, followed by show errors and a copy and paste of a run of a query that produces the error stack.

  • SELECT query takes too much time! Y?

    Plz find my SELECT query below:
    select w~mandt
    wvbeln wposnr wmeins wmatnr wwerks wnetwr
    wkwmeng wvrkme wmatwa wcharg w~pstyv
    wposar wprodh wgrkor wantlf wkztlf wlprio
    wvstel wroute wumvkz wumvkn wabgru wuntto
    wawahr werdat werzet wfixmg wprctr wvpmat
    wvpwrk wmvgr1 wmvgr2 wmvgr3 wmvgr4 wmvgr5
    wbedae wcuobj w~mtvfp
    xetenr xwmeng xbmeng xettyp xwepos xabart
    x~edatu
    xtddat xmbdat xlddat xwadat xabruf xetart
    x~ezeit
    into table t_vbap
    from vbap as w
    inner join vbep as x on xvbeln = wvbeln and
    xposnr = wposnr and
    xmandt = wmandt
    where
    ( ( werdat > pre_dat ) and ( werdat <= w_date ) ) and
    ( ( ( erdat > pre_dat and erdat < p_syndt ) or
    ( erdat = p_syndt and erzet <= p_syntm ) ) ) and
    w~matnr in s_matnr and
    w~pstyv in s_itmcat and
    w~lfrel in s_lfrel and
    w~abgru = ' ' and
    w~kwmeng > 0 and
    w~mtvfp in w_mtvfp and
    x~ettyp in w_ettyp and
    x~bdart in s_req_tp and
    x~plart in s_pln_tp and
    x~etart in s_etart and
    x~abart in s_abart and
    ( ( xlifsp in s_lifsp ) or ( xlifsp = ' ' ) ).
    The problem: It takes too much time while executing this statement.
    Could anybody change this statement and help me out to reduce the DB Access time?
    Thx

    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.
    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
    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.
    2.     Select all the records in a single shot using into table clause of select statement rather than to use Append statements.
    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'.
    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.
    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.
    4.     For testing existence, use Select.. Up to 1 rows statement instead of a Select-Endselect-loop with an Exit. 
    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.
    5.     Use Select Single if all primary key fields are supplied in the Where condition .
    If all primary key fields are supplied in the Where conditions you can even use Select Single.
    Select Single requires one communication with the database system, whereas Select-Endselect needs two.
    Select Statements SQL Interface
    1.     Use column updates instead of single-row updates
    to update your database tables.
    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.
    2.     For all frequently used Select statements, try to use an index.
    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.
    3.     Using buffered tables improves the performance considerably.
    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  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  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 Select Over more than one Internal table
    1.     Its better to use a views instead of nested Select statements.
    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
    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.
    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.
    3.     Instead of using nested Select loops it is often better to use subqueries.
    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.
    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 ) ).
    2.     Always try to use binary search instead of linear search. But don’t forget to sort your internal table before that.
    READ TABLE ITAB INTO WA WITH KEY K = 'X'. IS FASTER THAN USING
    READ TABLE ITAB INTO WA WITH KEY (NAME) = 'X'.
    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.
    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.
    6.     Modifying selected components using “ MODIFY itab …TRANSPORTING f1 f2.. “ accelerates the task of updating  a line of an internal table.
    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
    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.
    8.    If collect semantics is required, it is always better to use to COLLECT rather than READ BINARY and then ADD.
    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)) .
    9.    "APPEND LINES OF itab1 TO itab2" accelerates the task of appending a table to another table considerably as compared to “ LOOP-APPEND-ENDLOOP.”
    APPEND LINES OF ITAB1 TO ITAB2.
    This is more optimized as compared to
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    10.   “DELETE ADJACENT DUPLICATES“ accelerates the task of deleting duplicate entries considerably as compared to “ READ-LOOP-DELETE-ENDLOOP”.
    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.
    11.   "DELETE itab FROM ... TO ..." accelerates the task of deleting a sequence of lines considerably as compared to “  DO -DELETE-ENDDO”.
    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”.
    ITAB2[] = ITAB1[].
    This is much more optimized as compared to
    REFRESH ITAB2.
    LOOP AT ITAB1 INTO WA.
      APPEND WA TO ITAB2.
    ENDLOOP.
    13.   Specify the sort key as restrictively as possible to run the program faster.
    “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.

  • FAQ's, intros and memorable discussions in the Performance and Tuning Forum

    Welcome to the SDN ABAP Performance and Tuning Forum!
    In addition to release dependent information avalaible by:
    - pressing the F1 key on an ABAP statement,
    - or searching for them in transaction ABAPDOCU,
    - using the [SDN ABAP Development Forum Search|https://www.sdn.sap.com/irj/sdn/directforumsearch?threadid=&q=&objid=c42&daterange=all&numresults=15&rankby=10001],
    - the information accessible via the [SDN ABAP Main Wiki|https://wiki.sdn.sap.com/wiki/display/ABAP],
    - the [SAP Service Marketplace|http://service.sap.com] and see [SAP Note 192194|https://service.sap.com/sap/support/notes/192194] for search tips,
    - the 3 part [How to write guru ABAP code series|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f2dac69e-0e01-0010-e2b6-81c1e8e5ce50] ... (use the search to easily find the other 2 documents...)
    ... this "sticky post" lists some threads from the ABAP forums as:
    - An introduction for new members / visitors on topics discussed in threads,
    - An introduction to how the forums are used and the quality expected,
    - A collection of some threads which provided usefull answers to questions which are frequently asked, and,
    - A collection of some memorable threads if you feel like reading some ABAP related material.
    The listed threads will be enhanced from time to time. Please feel welcome to post to [this thread|Suggestions thread for ABAP FAQ sticky; to suggest any additional inclusions.
    Note: When asking a question in the forum, please also provide sufficient information such that the question can be answered usefully, do not repeat interview-type questions, and once closed please indicate which solution was usefull - to help others who search for it.

    ABAP Performance and Tuning
    Read Performance   => Gurus take over the discussion from Guests caught cheating the points-system.
    SELECT INTO TABLE => Initial questions often result in interesting follow-up discussions.
    Inner Joins vs For all Entries. => Including infos about system parameters for performance optimization.
    Inner Join Vs Database view Vs for all entries => Usefull literature recommended by performance guru YukonKid.
    Inner Joins vs For All Entries - performance query => Performance legends unplugged... read the blogs as well.
    The ABAP Runtime Trace (SE30) - Quick and Easy => New tricks in old tools. See other blogs by the same author as well.
    Skip scan used instead of (better?) range scan => Insider information on how index access works.
    DELETE WHERE sample case that i would like to share with you => Experts discussing the deletion of data from internal tables.
    Impact of Order of fields in Secondary  index => Also discussing order of fields in WHERE-clause
    "SELECT SINGLE" vs. "SELECT UP TO 1 ROWS" => Better for performance or semantics?
    into corresponding fields of table VERSUS into table => detailed discussion incl. runtime measurements
    Indexes making program run slower... => Everything you ever wanted to know about Oracle indexes.
    New! Mass reading standard texts (STXH, STXL) => avoiding single calls to READ_TEXT for time-critical processes
    New! Next Generation ABAP Runtime Analysis (SAT) => detailed introduction to the successor of SE30
    New! Points to note when using FOR ALL ENTRIES => detailed blog on the pitfall(s) a developer might face when using FAE
    New! Performance: What is the best way to check if a record exist on a table ? => Hermann's tips on checking existence of a record in a table
    Message was edited by: Oxana Noa Zubarev

  • Sql Server bulk update

    Hi
    I have a datatable (in .net Application) which has a huge data.
    I need to update/insert the data in to  the Sql server database table.
     (Upadte if the data exist in the table and insert if the data does not exist in the table).
    just I wanted to know Is there any option for bulk insert or update rather than checking each row in (using cursor - SP) the table and inserting/updating..
    Samproo

    Hi Samproo, You will never use a cursor to check the existence of a record to whether update it or insert it. It will cost a lot to you when huge data stars flowing in.
    Just use the Exists statement as below.
    IF EXISTS(SELECT 1 FROM Table_Name WHERE condition = Value)
    BEGIN
    ......UPDATE DATA Statemet.....
    END
    ELSE
    BEGIN
    .......INSERT DATA Statement.......
    END
    And Yes, you can use this inside any stored procedure the same way it is.
    or if you doing matches between two tables then you can use MERGE as well...
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

Maybe you are looking for

  • Displaying Document Name With The Summary in a Single Column Using Document Library View.

    Hi All, I have a question that relates to SharePoint Document Library Views. I want to view the Documents name with the summary in a single column. Below image shows an example of it. I need this within a SharePoint Document Library. Also I want the

  • Mirroring issue with retina 5k

    i have bought Imac retina 5k and i've got latest apple tv.  The problem is when i connect my mac to apple tv, its just showing black screen  but when i airplay from itunes it plays ok.  I tried disconnecting the bluetooth and i also updated apple tv

  • Problem in launching newly installed SQL Developer in Linux

    In order to install ORacle SQL Developer for linux, I tried to install JDK 5.0 according to the instruction. I downloaded the files and installed it. But when running the sqldeveloper, I got the error message: Error: This product requires a Java(TM)

  • One clik to print graph proxy

    Hi I want to print a chart after click button. After I click this button then is creating a chart in a new box and I see printer parameters to print this but the legend on the chart is on the right not bellow like is definied. In normal view I see a

  • Finder View options, won't stay set after restart or log out

    I like to have my application and utility folders (in the finder side bar) open in icon view and arranged by name and my Home and Movies folder open in list view with files arranged by name. Each time i log out of my computor or restart the view opti