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.

Similar Messages

  • Regarding performance in select query

    hi to all,
    i wrote select query for fetching duplicate records,like select distinct *.
    so at runtime it fetches all fields in table (FI dbtable).
    but i want to fetch only 8 records,for this i am using
    select distinct
              field1
               field2
    ..... like this ,it wasnt excuted.
    how can i avoid this issue.
    in program not much logic is there,only fetching the data and summation,n display.....
    plz giv me reply asap.
    regards
    satya

    satya wrote:>
    > hi to all,

    >  i wrote select query for fetching duplicate records,like select distinct *.
    > so at runtime it fetches all fields in table (FI dbtable).
    >
    > but i want to fetch only 8 records,for this i am using
    > select distinct
    >           field1
    >            field2
    > ..... like this ,it wasnt excuted.
    >
    > how can i avoid this issue.
    > in program not much logic is there,only fetching the data and summation,n display.....
    >
    > plz giv me reply asap.
    >
    > regards
    > satya
    Hi,
    write like this
    > select field1
    >           field2
    >          .......
    >   from  table
    >   into ( itab-f1,
    >            itab-f2,
    >            ........ )
    <REMOVED BY MODERATOR>
    Edited by: Alvaro Tejada Galindo on Feb 19, 2008 5:14 PM

  • Basic query regarding work-area and select query

    hi
    dear sdn members,
    thanks too all for solving all my query's up till now
    i am stuck in a problem need help
    1)  why basically work-area has been used ? the sole purpose
    2)  different types of select query ? only coding examples
    note: no links pls
    regards,
    virus

    hi,
    Work Area
    Description for a data object that is particularly useful when working with internal tables or database tables as a source for changing operations or a target for reading operations.
    WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.
    Each row in a table is a record and each column is a field.
    While adding or retrieving records to / from internal table we have to keep the record temporarily.
    The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
    Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
    .g.
    data: begin of itab occurs 10,
    ab type c,
    cd type i,
    end of itab. " this table will have the header line.
    data: wa_itab like itab. " explicit work area for itab
    data: itab1 like itab occurs 10. " table is without header line.
    The header line is a field string with the same structure as a row of the body, but it can only hold a single row.
    It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table.
    With header line
    SELECT.
    Put the curson on that word and press F1 . You can see the whole documentation for select statements.
    select statements :
    SELECT result
    FROM source
    INTO|APPENDING target
    [[FOR ALL ENTRIES IN itab] WHERE sql_cond]
    Effect
    SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
    The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
    The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
    Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
    System Fields
    The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.
    sy-subrc Relevance
    0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.
    4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.
    8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.
    After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.
    Notes
    Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab.
    Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server.
    SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective.
    Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close.
    SELECT - result
    Syntax
    ... lines columns ... .
    Effect
    The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program.
    The data in result consists of data for the rows lines and for the columns columns.
    SELECT - lines
    Syntax
    ... { SINGLE }
    | { { } } ... .
    Alternatives:
    1. ... SINGLE
    2. ... { }
    Effect
    The data in lines specifies that the resulting set has either multiple lines or a single line.
    Alternative 1
    ... SINGLE
    Effect
    If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.
    An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
    Note
    When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
    Alternative 2
    Effect
    If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
    If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
    If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW
    If the system tries to access pool or cluster tables and single columns are specified in columns.
    Note
    When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.
    SELECT - columns
    Syntax
    | { {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ... }
    | (column_syntax) ... .
    Alternatives:
    1. ... *
    2. ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    3. ... (column_syntax)
    Effect
    The input in columns determines which columns are used to build the resulting set.
    Alternative 1
    Effect
    If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO.
    Note
    If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *.
    Alternative 2
    ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    Effect
    A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times.
    The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. .
    Column labels
    The following column labels are possible:
    If only a single database table or a single view is specified after FROM, the column labels in the database table - that is, the names of the components comp1 comp2... - can be specified directly for col1 col2 ... in the structure of the ABAP Dictionary.
    If the name of the component occurs in multiple database tables of the FROM addition, but the desired database table or the view dbtab is only specified once after FROM, the names dbtab~comp1 dbtab~comp2 ... have to be specified for col1 col2 .... comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary.
    If the desired database table or view occurs multiple times after FROM, the names tabalias~comp1 tabalias~comp2 ... have to be specified for col1 col2 .... tabalias is the alternative table name of the database table or view defined after FROM, and comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary.
    The data type of a single column in the resulting list is the datatype of the corresponding component in the ABAP Dictionary. The corresponding data object after INTO or APPENDING has to be selected accordingly.
    Note
    If multiple database tables are specified after FROM, you can use alternative names when specifying single columns to avoid having multiple columns with the same name.
    Example
    Read specific columns of a single row.
    DATA wa TYPE spfli.
    SELECT SINGLE carrid connid cityfrom cityto
    INTO CORRESPONDING FIELDS OF wa
    FROM spfli
    WHERE carrid EQ 'LH' AND connid EQ '0400'.
    IF sy-subrc EQ 0.
    WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
    ENDIF.
    Alternative 3
    ... (column_syntax)
    Effect
    Instead of static data, a data object column_syntax in brackets can be specified, which, when the command is executed, either contains the syntax shown with the static data, or is initial. The data object column_syntax can be a character-type data object or an internal table with a character-type data type. The syntax in column_syntax, like in the ABAP editor, is not case-sensitive. When specifying an internal table, you can distribute the syntax over multiple rows.
    If column_syntax is initial when the command is executed, columns is implicitly set to * and all columns are read.
    If columns are specificied dynamically without the SINGLE addition, the resulting set is always regarded as having multiple rows.
    Notes
    Before Release 6.10, you could only specify an internal table with a flat character-type row type for column_syntax with a maximum of 72 characters. Also, before Release 6.10, if you used the DISTINCT addition for dynamic access to pool tables or cluster tables, this was ignored, but since release 6.10, this causes a known exception.
    If column_syntax is an internal table with header line, the table body and not the header line is evaluated.
    Example
    Read out how many flights go to and from a city. The SELECT command is implemented only once in a sub-program. The column data, including aggregate function and the data after GROUP BY, is dynamic. Instead of adding the column data to an internal l_columns table, you could just as easily concatenate it in a character-type l_columns field.
    PERFORM my_select USING `CITYFROM`.
    ULINE.
    PERFORM my_select USING `CITYTO`.
    FORM my_select USING l_group TYPE string.
    DATA: l_columns TYPE TABLE OF string,
    l_container TYPE string,
    l_count TYPE i.
    APPEND l_group TO l_columns.
    APPEND `count( * )` TO l_columns.
    SELECT (l_columns)
    FROM spfli
    INTO (l_container, l_count)
    GROUP BY (l_group).
    WRITE: / l_count, l_container.
    ENDSELECT.
    ENDFORM.
    SELECT - aggregate
    Syntax
    ... { MAX( col )
    | MIN( col )
    | AVG( col )
    | SUM( col )
    | COUNT( DISTINCT col )
    | COUNT( * )
    | count(*) } ... .
    Effect
    As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):
    MAX( col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.
    MIN( col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.
    AVG( col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    SUM( col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.
    COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.
    If you are using aggregate expressions, all column labels that are not listed as an argument of an aggregate function are listed after the addition GROUP BY. The aggregate functions evaluate the content of the groups defined by GROUP BY in the database system and transfer the result to the combined rows of the resulting set.
    The data type of aggregate expressions with the function MAX, MIN or SUM is the data type of the corresponding column in the ABAP Dictionary. Aggregate expressions with the function AVG have the data type FLTP, and those with COUNT have the data type INT4. The corresponding data object after INTO or APPENDING has to be selected accordingly.
    Note the following points when using aggregate expressions:
    If the addition FOR ALL ENTRIES is used in front of WHERE, or if cluster or pool tables are listed after FROM, no other aggregate expressions apart from COUNT( * ) can be used.
    Columns of the type STRING or RAWSTRING cannot be used with aggregate functions.
    When aggregate expressions are used, the SELECT command makes it unnecessary to use SAP buffering.
    Null values are not included in the calculation for the aggregate functions. The result is a null value only if all the rows in the column in question contain the null value.
    If only aggregate expressions are used after SELECT, the results set has one row and the addition GROUP BY is not necessary. If a non-table type target area is specified after INTO, the command ENDSELECT cannot be used together with the addition SINGLE. If the aggregate expression count( * ) is not being used, an internal table can be specified after INTO, and the first row of this table is filled.
    If aggregate functions are used without GROUP BY being specified at the same time, the resulting set also contains a row if no data is found in the database. If count( * ) is used, the column in question contains the value 0. The columns in the other aggregate functions contain initial values. This row is assigned to the data object specified after INTO, and unless count( * ) is being used exclusively, sy-subrc is set to 0 and sy-dbcnt is set to 1. If count( *) is used exclusively, the addition INTO can be omitted and if no data can be found in the database, sy-subrc is set to 4 and sy-dbcnt is set to 0.
    if helpful reward points

  • Performance of  Select query

    Hi All,
    I am using select stmt on MARA and ZTSDNETPR.
    In ZTSDNETPR table,  pltyp,konda,MATNR,DATAB,DATBI are indexes in same order as i am using in my select stmt.
    But it is taking 1 hrs 45 min to take execute. Please give me any suggestion.
    SELECT  MATNR MTART MATKL ZPLINE ZREL ZLANG ZUSG_TYPE
      ZDEPLOY ZLIC_TYPE ZSER_TYPE ZSVC_SALE_TYPE
      ZSUB_LEVEL ZSUB_REL ZASM ZREF_TYPE ZUPD_FRM
      FROM MARA
      INTO CORRESPONDING FIELDS OF  TABLE IT_MATERIAL_INFO
      WHERE MATNR IN S_MATNR
      AND   MATKL IN S_MATKL
      AND   ERSDA IN S_ERSDA.
      IF SY-SUBRC = 0.
        sort it_material_info by matnr.
    ***Fetching the price details from ZTSDNETPR table
       select pltyp konda MATNR datab datbi
       from ZTSDNETPR
       into TABLE IT_ZTSDNETPR
       for all entries in it_material_info
       where
         pltyp <> space  
         and konda <> space
         AND MATNR = it_material_info-matnr
         AND  DATAB <= sy-datum
         AND  DATBI >= sy-datum.
    Regards,
    Shiv.

    shiv,
    SELECT MATNR MTART MATKL ZPLINE ZREL ZLANG ZUSG_TYPE
    ZDEPLOY ZLIC_TYPE ZSER_TYPE ZSVC_SALE_TYPE
    ZSUB_LEVEL ZSUB_REL ZASM ZREF_TYPE ZUPD_FRM
    FROM MARA
    INTO CORRESPONDING FIELDS OF TABLE IT_MATERIAL_INFO
    <b>WHERE MATNR IN S_MATNR
    AND MATKL IN S_MATKL
    AND ERSDA IN S_ERSDA.</b>
    changed to
    SELECT MATNR MTART MATKL ZPLINE ZREL ZLANG ZUSG_TYPE
    ZDEPLOY ZLIC_TYPE ZSER_TYPE ZSVC_SALE_TYPE
    ZSUB_LEVEL ZSUB_REL ZASM ZREF_TYPE ZUPD_FRM
    FROM MARA
    INTO CORRESPONDING FIELDS OF TABLE IT_MATERIAL_INFO
    WHERE MATNR IN S_MATNR.
    loop at it_material_info.
    if ( it_material_info-matkl  not in s_matkl ) or ( it_material_info-ersda not in s_ersda )
    delete it_material_info.
    endif.
    endloop.
    In your previous query the fields given in the where clause are not primary keys.Always make it a point to use only primary keys or index in the where clause.This will enhance the performance.
    So,I had changed the select query accordingly and then filtered it w.r.t the selection-screen matkl and ersda.
    The same you apply for the ztable also.This will surely enhance the performance.
    K.Kiran.
    Message was edited by:
            Kiran K

  • OPtimizing Performance for Select query on NAST table

    Hi All,
       We are fetching a single record from NAST table. The table has around 10 Million Entries.
       The Select Query takes around 5-6 minutes to return.
       We are not using the Primary key completely. We are using only one field of the primary key.
        The field is also a part of the Index but we are not using all the fields in the index as well.
        We need to bring down the time. What can be the solution? I cant see any changes to the code, since its a single query and we cant use the Entire Primary key.
       Would creating an Index on the fields that we are concerned with help in this regard.
       Open to all solutions.
    Thanks in Advance,
    Imran

    Hi,
    Please check this thread
    http://sap.ittoolbox.com/documents/popular-q-and-a/specifying-the-index-to-be-used-2462
    For creating another secondary index in NAST whether basis will approve for this?
    aRs

  • OPtimizing Performance for Select query on huge table

    Hi All,
       We are fetching a single record from NAST table. The table has around 10 Million Entries.
       The Select Query takes around 5-6 minutes to return.
       We are not using the Primary key completely. We are using only one field of the primary key.
        The field is also a part of the Index but we are not using all the fields in the index as well.
        We need to bring down the time. What can be the solution? I cant see any changes to the code, since its a single query and we cant use the Entire Primary key.
       Would creating an Index on the fields that we are concerned with help in this regard.
       Open to all solutions.
    Thanks in Advance,
    Imran

    There are sometimes tricks you can use to get it to use the index more efficiently. If you let us know which fields you are using in the SELECT (all of them actually), we might be able to help.
    Or are you saying you can't change the code at all?
    Please don't create duplicate posts though.
    Rob
    Message was edited by:
            Rob Burbank

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

  • Performance on select query

    Hello,
    I have a generic question on the select query. I have a big table with more than 500,000 rows of data and I use JDBC to query data. If I run select * and select <selected columns>, which one runs faster? I would like to know the difference in excuting time, not the time to fetch data from the result set.
    Since my DB is from different machine, I can't get the true test case since there is some delay over the network. Any help is appreciated.
    Thanks,
    Truong

    > Are the selected columns all of the columns or just some of them. If you are
    only selecting some of the columns the fetch will be faster.
    To expand a bit on what 3360 said.
    The IP4 max packet size is around 1.4KB I think. So you want ideally to fit in as many rows into a packet as possible and reduce the number of packets transmitted from the server to your client. The less columns selected, the smaller the size of the row to return.
    Another reason is index vs table. The CBO can select to scan an index instead of a table to return rows - depending on factors such as that the index containing all the columns you want. The reason for this is that the index is a smaller volume of data to read than the table. And if the data in the index alone can satisfy your query, why then hit the larger table?

  • Regarding - Tilde symbol in 'SELECT' Query

    Hi all,
           Kindly tell me whether this type of Select query statement with where conition is correct, can we use it. Also tell me whether it will fetch correct data at any point of time.
    Types : BEGIN OF ty_sector ,         
               sector     TYPE zpat003_sector-sector,
               END OF ty_sector.
    data : it_sector       TYPE TABLE OF ty_sector.
    SELECT sector
      FROM zpat003_sector
      INTO TABLE it_sector
      WHERE sectgrp = zpat003_sector~sectgrp
        AND subsect = zpat003_sector~subsect
        AND sector  = zpat003_sector~sector.
      IF sy-subrc IS INITIAL.
        SORT it_sector BY sector.
        DELETE ADJACENT DUPLICATES FROM it_sector.
    Note :
    1. I am filling this it_sector to use it for F4 purposes.
    2. This table 'zpat003_sector' contains all the sector details, sub-sector and    sector group details.
    3. I have used this where condition, to avoid the EPC warnings.
    Kindly guide me on this, how for this statement is right.

    Hi all,
            Thanks all for your responses.
    My aim is to fetch all the sector values from the table ZPAT003_SECTOR.
    This i can achieve by just giving
    SELECT sector
      FROM zpat003_sector
      INTO TABLE it_sector.
    If i give like this, i am getting getting warning message in code inspector, saying
    Table ZPAT003_SECTOR : No where condition.
    So, to avoid this warning message, i have given the where condition as
    WHERE sectgrp = zpat003_sector~sectgrp
        AND subsect = zpat003_sector~subsect
        AND sector  = zpat003_sector~sector.
    or else we can use #EC to truncate warning message.
    By using this 'where' condition i am able to truncate the warning message and able to get all the data in developement server, but i want to know, using the condition like this is acceptable and whether will it work all time.
    So kindly guide me on this

  • SELECT query performance : One big table Vs many small tables

    Hello,
    We are using BDB 11g with SQLITE support. I have a query about 'select' query performance when we have one huge table vs. multiple small tables.
    Basically in our application, we need to run select query multiple times and today we have one huge table. Do you guys think breaking them into
    multiple small tables will help ?
    For test purposes we tried creating multiple tables but performance of 'select' query was more or less same. Would that be because all tables will map to only one database in backed with key/value pair and when we run lookup (select query) on small table or big table it wont make difference ?
    Thanks.

    Hello,
    There is some information on this topic in the FAQ at:
    http://www.oracle.com/technology/products/berkeley-db/faq/db_faq.html#9-63
    If this does not address your question, please just let me know.
    Thanks,
    Sandra

  • JDBC Receiver : Handling NULL return from SELECT query

    Hi All,
    I have a Proxy <-> XI <-> JDBC synchronous scenario. I have designed my message mapping to perform a select query using JDBC receiver adapter. The request message mapping structure at the JDBC end is as follows.
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Matmvmt_Jdbc_Request xmlns:ns0="http://esag.com/xi/bat/MatMovementRead">
       <StatementSelect>
          <Tablename action="SELECT">
             <Table>MM_DATA</Table>
             <access>
                <SEQNO/>
                <MATERIAL/>
                <UOM/>
                <SOLDQTY/>
                <SAPUPD/>
             </access>
             <key compareOperation="EQ">
                <SAPUPD>N</SAPUPD>
             </key>
          </Tablename>
       </StatementSelect>
    </ns0:MT_Matmvmt_Jdbc_Request>
    The scenario works fine when there are records matching the select condition, but when there are no records matching the select condition (i.e. if there are no record with value SAPUPD = 'N' ) then my response message is returning the empty message strucuture as given below.
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Matmvmt_Jdbc_Request_response xmlns:ns0="http://esag.com/xi/bat/MatMovementRead">
       <StatementSelect_response/>
    </ns0:MT_Matmvmt_Jdbc_Request_response>
    My requirement is that if there are no records matching the select condition then my response message should look like below.
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Matmvmt_Jdbc_Request_response xmlns:ns0="http://esag.com/xi/bat/MatMovementRead">
       <StatementSelect_response>
          <row>
             <SEQNO/>
             <MATERIAL/>
             <UOM/>
             <SOLDQTY/>
             <SAPUPD/>
          </row>
       </StatementSelect_response>
    </ns0:MT_Matmvmt_Jdbc_Request_response>
    Note : I have made the occurence of the request and response message elements as miniccurs = 0 and maxoccurs = 1.
    Any inputs in this regard will be highly appreciated.
    Regards,
    Sandeep

    Hi Sandeep,
    you can not expect structure like <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Matmvmt_Jdbc_Request_response xmlns:ns0="http://esag.com/xi/bat/MatMovementRead">
       <StatementSelect_response>
          <row>
             <SEQNO/>
             <MATERIAL/>
             <UOM/>
             <SOLDQTY/>
             <SAPUPD/>
          </row>
       </StatementSelect_response>
    </ns0:MT_Matmvmt_Jdbc_Request_response>
       if there is no data in table. The response which you are geting is standard format which you can not change. Instead you map this response with mapwithdefault node function while mapping to target to make the response mapping success, even though there is no data in response message.
    thanks,
    madhu

  • How to : SELECT MAX(EmpID) / count(*) in SELECT Query

    Hi,
    I like to find out the Maximum of the EmpID that is in the DB table.
    So I need to perform a select Query:
    Select MAX(EmpID) from EmpTable
    or Select Count(*) from EmpTable
    <StatementName>
    <dbTableName action=”SELECT”>
       <table>realDbTableName</table>
         <access>
             <??? />
          </access>
    </dbTableName> 
    </StatementName>
    I cannot type MAX(EmpID) or count(*) as access element
    So what should I mention in the Access?
    Thanks & regards,
    Siva Maranani.

    if 0CALDAY is used as a characteristic then you have to convert that as a key figure using a replacement path variable.
    Please see the below link for changing 0CALDAY as a key figure using Replacement path
    http://www.sd-solutions.com/documents/SDS_BW_Replacement%20Path%20Variables.html
    https://websmp106.sap-ag.de/~sapdownload/011000358700001963972003E/HowToCalcWithAttr.pdf
    Now you have to create an exception "Top N Rows" based on the replacement path variable created above.
    This will solve your problem.
    Regs
    Gopi.
    Award points if it helps ...

  • Issue in select query

    HI All experts,<br><br>
    i have  a program in which i have a select query <pre>
    SELECT  b~vertrag
              a~anlage
              a~operand
              a~saison
              a~ab
              a~ablfdnr
              a~bis
              a~wert1
      FROM ettifn AS a INNER JOIN ever AS b
      ON aanlage = banlage
      INTO TABLE li_captran PACKAGE SIZE p_pack
      WHERE a~anlage IN s_anlage
        AND a~ab <= l_date
        AND a~bis >= l_date
        AND a~operand IN ('ID-CAPLOAD','ID-OBLT')
        AND b~einzdat <= l_date
        AND b~auszdat >= l_date.</pre><br><br>
    this query is taking a lot of time in running and we are facing lot of performance related issues
    <br><br>
    kindly guide me how i can break this into som simpler query
    <br><br>
    ettifn has 10 million records
    ever has around 5 million records .
    <br><br>
    also please tell me how much data i can store into an internal table
    can i store 5 million records in an internal table ??????
    is it good in terms of performance of a program if not please tell me what is the better way of doing dat .
    <br><br>
    also tell me how secondry indexes help in improving performance of select query
    is it good to maintain number of secondry indexes in a standard table or it decreases performance of a standard table .
    <br><br>
    <pre>
      TYPES: BEGIN OF ty_eanlh,
              anlage LIKE eanlh-anlage,
              bis LIKE eanlh-bis,
              tariftyp LIKE eanlh-tariftyp,
             END OF ty_eanlh.
      DATA: l_date TYPE datum.
      DATA: li_eanlh TYPE HASHED TABLE OF ty_eanlh WITH UNIQUE KEY anlage
                                                                   bis
                                                   WITH HEADER LINE.
      DATA: li_captran TYPE HASHED TABLE OF ty_captran WITH UNIQUE KEY vertrag
                                                                       anlage
                                                                       operand
                                                                       saison
                                                                       ab
                                                                       ablfdnr
                                                        WITH HEADER LINE.
      DATA: l_tariftyp LIKE eanlh-tariftyp.
    l_date = p_date + 6.
      l_date = p_date + 5.          "As per Terry's Request 1/23/2009
      CHECK NOT p_cap IS INITIAL.
    Get Operand Values
      SELECT  b~vertrag
              a~anlage
              a~operand
              a~saison
              a~ab
              a~ablfdnr
              a~bis
              a~wert1
      FROM ettifn AS a INNER JOIN ever AS b
      ON aanlage = banlage
      INTO TABLE li_captran PACKAGE SIZE p_pack
      WHERE a~anlage IN s_anlage
        AND a~ab <= l_date
        AND a~bis >= l_date
        AND a~operand IN ('ID-CAPLOAD','ID-OBLT')
        AND b~einzdat <= l_date
        AND b~auszdat >= l_date.
        IF sy-subrc EQ 0 AND NOT li_captran[] IS INITIAL.
       Get Rate Category
          SELECT anlage
                 bis
                 tariftyp
          FROM eanlh INTO CORRESPONDING FIELDS OF TABLE li_eanlh
          FOR ALL ENTRIES IN li_captran
          WHERE anlage = li_captran-anlage
            AND ab <= l_date
            AND bis >= l_date.
       Get POD ID
          SELECT a~anlage
                 a~int_ui
                 a~dateto
                 a~timeto
                 b~ext_ui
          INTO TABLE i_pod
          FROM euiinstln AS a INNER JOIN euitrans AS b
          ON aint_ui = bint_ui
          FOR ALL ENTRIES IN li_captran
          WHERE a~anlage = li_captran-anlage.
          IF sy-subrc EQ 0 AND NOT i_pod[] IS INITIAL.
            SORT i_pod BY anlage.
            SELECT vertrag
                   int_ui
                   serviceid
            FROM eservice
            INTO TABLE i_servicect
            FOR ALL ENTRIES IN i_pod
            WHERE int_ui = i_pod-int_ui
              AND service_start <= l_date
              AND service_end >= l_date
              AND service = 'ESUP'.
          ENDIF.
          LOOP AT li_captran.
            i_ct-anlage = li_captran-anlage.
            READ TABLE li_eanlh WITH KEY anlage = li_captran-anlage.
            IF sy-subrc EQ 0.
              i_ct-tariftyp = li_eanlh-tariftyp.
              READ TABLE i_rate WITH KEY tariftyp = i_ct-tariftyp.
              IF sy-subrc NE 0.
                CONTINUE.
              ENDIF.
            ELSE.
              i_ct-tariftyp = '0000'.
            ENDIF.
            READ TABLE i_pod WITH KEY anlage = li_captran-anlage.
            IF sy-subrc EQ 0.
              READ TABLE i_servicect WITH KEY int_ui = i_pod-int_ui.
              IF sy-subrc EQ 0.
                i_ct-serviceid = i_servicect-serviceid.
              ENDIF.
            ENDIF.
            IF li_captran-operand = 'ID-CAPLOAD'.
              i_ct-cap = li_captran-wert1.
            ELSEIF li_captran-operand = 'ID-OBLT'.
              i_ct-tran = li_captran-wert1.
            ENDIF.
            COLLECT i_ct.
            CLEAR: li_captran, i_ct.
          ENDLOOP.
        ENDIF.
      ENDSELECT.</pre><br><br>
      this code is taking a lot of time to execute and decreasing the system performance .<br><br>
    please guide me how can i increase the performance of this code .<br><br>
    Thanks in advance<br><br><br><br>
    Edited by: Matt on Oct 11, 2009 9:45 PM

    Hi matt ,
    no i am not thru bcoz of formatting i just trying to remove it and i just marked it answered so that it will not come in my unanswered because unanswered questions are limited.
    also could you please help me in this question .
    now how can i change this question to unanswerd .
    plz guide me
    Thanks in advance

  • Select query on a table with 13 million of rows

    Hi guys,
    I have been trying to perform a select query on a table which has 13 millions of entries however it took around 58 min to complete.
    The table has 8 columns with 4 Primary keys looks like below:
    (PK) SegmentID > INT
    (PK) IPAddress > VARCHAR (45)
    MAC Address > VARCHAR (45)
    (PK) Application Name > VARCHAR (45)
    Total Bytes > INT
    Dates > VARCHAR (45)
    Times > VARCHAR (45)
    (PK) DateTime > DATETIME
    The sql query format is :
    select ipaddress, macaddress, sum(totalbytes), applicationname , dates,
    times from appstat where segmentid = 1 and datetime between '2011-01-03
    15:00:00.0' and '2011-01-04 15:00:00.0' group by ipaddress,
    applicationname order by applicationname, sum(totalbytes) desc
    Is there a way I can improve this query to be faster (through my.conf or any other method)?
    Any feedback is welcomed.
    Thank you.
    Mus

    Tolls wrote:
    What db is this?
    You never said.
    Anyway, it looks like it's using the Primary Key to find the correct rows.
    Is that the correct number of rows returned?
    5 million?
    Sorted?I am using MySQL. By the way, the query time has been much more faster (22 sec) after I changed the configuration file (based on my-huge.cnf).
    The number of rows returned is 7999 Rows
    This is some portion of the my.cnf
    # The MySQL server
    [mysqld]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    skip-locking
    key_buffer = 800M
    max_allowed_packet = 1M
    table_cache = 256
    sort_buffer_size = 1M
    read_buffer_size = 1M
    read_rnd_buffer_size = 4M
    myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    query_cache_size= 16M
    log = /var/log/mysql.log
    log-slow-queries = /var/log/mysqld.slow.log
    long_query_time=10
    # Try number of CPU's*2 for thread_concurrency
    thread_concurrency = 6
    Is there anything else I need to tune so it can be faster ?
    Thanks a bunch.
    Edited by: user578505 on Jan 17, 2011 6:47 PM

  • Select query not working with like & and operator

    Hi,
    The below is the select query which is used to select only the failed rollup jobs from DB table ( background jobs ) the status 'A' which means only the failed roll up jobs.
    select jobname status from v_op into table zjob_rollup where jobname like '%ROLLUP%'
                                                             or jobname like  'BI_AGGR%'
                                                             and status like 'A'.
    Right now my internal tables is picking the job name other than status A also.
    Can you please help.
    Note: Ps consider the performance of select query also.
    Thanks,
    Siva

    Hi,
    select jobname status
         from v_op
         into table zjob_rollup
         where ( jobname like '%ROLLUP%'  or jobname like  'BI_AGGR%' )
                      and status = 'A'.

Maybe you are looking for

  • Using Airport Express to Extend a Time Capsule Network: Results (*Long*)

    Thought I would share my recent (2 hours ago) experience with setting up an Airport Express to Extend a Time Capsule 802.11N 5Ghz Network. Basically I just followed the directions in the Apple Airport Utility, using the "Extend a Wireless Network" se

  • Acrobat 9.0 allows only 2 installations

    Hello.  I recently purchased Acrobat 9.0 Standard and it only allows for 2 installations (I think that's a rip off).  Nonetheless, how do I find a version that allows for multiple installations or how do I purchase additional product keys for the cur

  • Converting Binary Data to Decimals

    Hello, my task is to use the VI I created which reads magnetic card strips and displays the 32 bit X 8 binary code. I need to display the binary code as decimals. Here is my VI, where do I go from here? Fernando Attachments: 1MCardReader_finalCopy.vi

  • Sending email Notifications from BPM 11.1.1.5+FP

    Hi all, We're trying to send an email notifications from our process but we need to send HTML mails, not just plain text... Any help would be appreciated. Thanks in advance

  • Navigate in XML tree

    Hi I use oracle 10g. what is the best tool to navigate in XML tree and to analize it.when I dont no the exact structure of the xml. for example I need to do some action like DFS search and to set whiget to each tag is dbms_xmldom is the only option o