Problem in Select stmt in loop

Hi all,
Pls provide your suggestions for the following code.
LOOP at ITAB.
select * from zxyz into corresponding fields of table ITAB_FINAL
where fromdate eq date1
          todate eq date2
          MATNR eq ITAB-matnr.
ENDLOOP.
My question is that for a particular entry in itab , select stmt is executed and some 5 to 6 line item is selected into itab_final. Now in second loop , again select stmt is executed and again some line item will be selected , BUT will this selection will replace the earlier entry in ITAB_FINAL OR the entry in SUCCESSIVE loop will be APPENDED ?
Please suggest your valuable suggestion on this problem
Thanks in advance,
Regards,
Vivek

Hi,
There is no need to loop if you are using FOR ALL ENTRIES
select * from zxyz into corresponding fields of table ITAB_FINAL
for all entries in itab
where matnr eq itab-matnr
and fromdate eq date1
and todate eq date2.

Similar Messages

  • Problem in select  statment & loop of itab.

    Hi all,
          I am having on ITAB1  for, ex which is having five line items or more  .
    iam also using select statment SINGLE statment for 7 times ,to select values for
    different data base  table.
    for ex,
    loop at itab.
       1---> SELECT SINGLE Z_CTRY_ORIG INTO LS_PSHDESN-Z_CTRY_ORIG FROM ZLE_PART_MST
      WHERE                           WERKS        = ITAB1-LGNUM
      AND                                 MATNR        = ITAB1-MATNR .
    2---
    3---
    4---
    endloop
    i want to remove from the loop statment  and i have to select  the datas ..
    can any one sugesset some possible ways....
    regards
    veera

    hi,
    Solution:
    Never use select single in loop at itab!! for that :
    Solution 1:
    say ur main table is ITAB and rferring  this u want to select data from other tables.
    SELECT SINGLE Z_CTRY_ORIG INTO LS_PSHDESN-Z_CTRY_ORIG FROM ZLE_PART_MST
    into table itab2
    FOR ALL ENTRIES IN ITAB
    WHERE WERKS = ITAB-LGNUM
    AND MATNR = ITAB-MATNR.
    With this what will hapeen , u will get all records in itab2 which u can update itab1(master) using loop.
    solution 2:
    Instead of all this use JOINs in select statement properly and u can fetch data in one shot this will reduce database load as well as abap load ( More than 3 joins in SELECT stmt  are not recommeded but can be used)
    I believe this is perfect solution if and only if u are giving joins on KEY fields only.  Same is applied for wherer clause.
    Hope this will help u, if not revert.
    Jogdand M B

  • How to avoid data selection inside the loop?

    Hello Experts,
    I am working on one performance item and I have already applied some changes to the original version.
    Now, If I compare my new program with old program, I have good improvement in performance. I am checking if I can do anything on statements that are top on the below list. I think 40% for Modify statement is acceptable after my research (Below run is updating around 20M records which is real time volume for this application).
    As we can see 34% of run time to going for one SELECT query on custom table. Take a look at below high level flow of my program to understand above select query.
    1. Select data from ZABC
    2. Select data from Variant Table (Var1, Var2, Var3 etc.., 12 in real time)
    3. Loop Variant Table
    4. Select data from X, Y, Z table for Var<n>.
    5. Populate final internal table from ZABC, X, Y and Z table
    6. Modify ZTABLE with Final Internal table data
    7. End Loop on Variant Table
    As described in the flow of the program, ZABC table data is common for all the variants and need not to fetch multiple times. Hence I am doing it only once in my program. Below is that select query:
    select rrcty ryear rbukrs racct rcntr sum( amt1) as amt1  "Like I have 32 amount fields in original query
               from zabc
                into table i_zabc
                where ryear in r_year    " Two records in ranges with I and EQ
                and rvers = '001'
                and rrcty in r_rrcty        "Three records in ranges with I and EQ
                and rldnr = 'DT'
                group by rrcty ryear rbukrs racct rcntr
                order by rrcty ryear rbukrs racct rcntr.
    ZABC table is again having huge volume of data and we are fetching millions of records with above query. That is primary reason to take long time. May be that is okay as I am already using Indexes of this table. But, I am not comfortable with it as it can reach max. memory point and through run time error. Fetch Cursor is one reliable option that I can see here, but with that, I should move ZABC selection inside the variant loop which can cause fetching ZABC data 12 times (Let me know If I am missing anything here).
    Now, third statement in my trace results, with 10% of overall time is this:
    loop at i_abc assigning <fs_abc>. 
    loop at i_table assigning <fs_table> where low <= <fs_abc>-racct and high >= <fs_abc>-racct. 
    endloop. 
    endloop. 
    6 million executions with this complex WHERE condition is causing this statement to get 3rd position in trace results. I tried below two options which are, I think, taking even more time - (I am still monitoring these options)
    1) Removed WHERE condition on LOW, HIGH and applied filter inside the loop.
    2) Removed WHERE condition on HIGH only and applied filter inside the loop.
    Any suggestions on how to proceed with ZABC selection and I_TABLE loop.
    Let me know if you have any questions on above compose.

    Since I looked at this case before, let me try some quick suggestions:
    Is table ZABC related to table X, Y and/or Z and can the selection be limited by applying those 12 selection variants?
    If yes, try a join select involving these tables that could make your step 1 obsolete and replace steps 4 and 5.
    This might also get rid of the "loop inside loop" problem. Generally, make sure that the inner table is declared as a sorted table with a key that consists of the fields as used in the WHERE-condition of the inner loop. Use secondary keys for internal tables if your ABAP release permits and the task at hand warrants it.
    Finally, look at PACKAGE SIZE option for the (join) select to reduce memory consumption.
    Thomas

  • Use of Select stmts with Update stmts

    Hi,
    I want to execute the following update stmt...
    UPDATE Test1_tab a
    SET a.invpln_seq_no = (SELECT b.seq_no
    FROM Test2_tab b
    WHERE b.contract_id = a.contract_id
    AND b.date_from = a.period_from_date)
    WHERE a.invpln_seq_no != (SELECT b.seq_no
    FROM Test2_tab b
    WHERE b.contract_id = a.contract_id
    AND b.date_from = a.period_from_date)
    Here the problem is I have used 'SELECT b.seq_no FROM Test2_tab b WHERE b.contract_id = a.contract_id AND b.date_from = a.period_from_date' twice, one in the SET clause and the other one in WHERE clause...But it is the same SELECT stmt...So this same Select stmt runs twice when I run the whole update stmt I guess. Is there a way to do the above update, where it runs the SELECT stmt only once...
    Any input is highly appreciated...
    Thanks And Best Regards,
    /Dinesh...

    Then you can use Merge statement instead.
    try this
    merge into test1_tab t1
    using
    (SELECT a.rowid,b.seq_no SEQ_DEST
    FROM test1_tab a,test2_tab b
    WHERE b.contract_id = a.contract_id
    AND  b.date_from = a.period_from_date
    AND a.invpln_seq_no != b.seq_no) t2
    ON (t1.rowid=t2.rowid)
    WHEN MATCHED THEN
    UPDATE SET t1.invpln_seq_no=t2.seq_destor if you are sure that sno is a unique key with out any duplicates and if you are going to perform one time manual update then you can use an undocumented hint /*+ bypass_ujvc */ to do this.
    *DO NOT include this code if you are about to add it in a production procedure or a function
    UPDATE /*+ bypass_ujvc */ (SELECT a.invpln_seq_no SEQ_SRC,b.seq_no SEQ_DEST FROM test1_tab a,test2_tab  b
    WHERE b.contract_id = a.contract_id
    AND  b.date_from = a.period_from_date
    AND a.invpln_seq_no != b.seq_no)
    SET SEQ_SRC = SEQ_DESTRegards,
    Prazy

  • New User - Cannot select drum kit loops

    Hi,
    I am a trying out GarageBand for the first time and having a lot of fun.
    However I was following one of the Apple tutorials where I clicked on song writing and had a basic drum track. The tutorial said if you don't like the drum track you can delete it and then use the Loop browser to select different drum kits.
    However when I click on the Loop browser I can't click on the drum kit icons to then select a drum loop - they are all ghosted out - like as if they are not installed on my system.
    Yet the basic drum loop played fine - so it must be there somewhere.
    Do I have to install these loops somehow like I had to install the instruments? (The system told me I needed to install some things online - but I've not seen anything regarding loops)
    Help !!!
    Thanks

    In case anyone had the same problems as me - I had to use the Applications disc that came with my laptop to re-install Garageband from the DVD.
    Just take care using it - make sure you backup your system just in case (always a good idea) - insert the disc and follow the instructions. Make sure you take all the tick boxes out of the other applications so that you only install Garageband.
    Then let it install and when the computer restarts there are all the loops in their glory.
    Its a shame that Garageband lets you download the loops online because that is a complete waste of time as even after downloading 1.2 gigs worth of data Garageband ignores the loops even though they are there on your system. The only way to get the loops to work is by installing off the dvd that came with your computer.
    Hope this helps other users.
    Cheers
    Phil

  • Problem in Selection Screen.

    Dear Experts,
    I am facing a problem in Selection Screen.
    <b>I have 2 radio buttons ,</b>
    <b>Radio Button 1</b> - Choosing the file from desktop and
    <b>Radio Button 2</b> - Executing from Database
    Under Option1 - i have a <b>FILE</b> parameter which is <b><u>Mandatory.</u></b>
    Problem Case -
    <b>when I choose option 2, Option 1 should be disabled. in the sense the file name which is mandatory here should not be mandatory . Currently, when i choose option 2 - i have to provide some dummy characters in the file parameter because the file parameter is mandatory, and <u><b>I want to avoid this.</b></u>
    Please see the entire code .</b>
    REPORT ZTEST.
    DATA: LV_FILE_PATH(20) TYPE  C.
    DATA: LV_MASK(20)      TYPE  C VALUE   ',*.XLS ,*.XLS.     '.
    *-- Macro to put radiobutton on selection screen
    *-- &1 - radiobutton parameter name
    *-- &2 - text element (description)
    *-- &3 - radiobutton group
    DEFINE MAKE_RADIOBUTTON.
      SELECTION-SCREEN BEGIN OF LINE.
      PARAMETERS: &1 RADIOBUTTON GROUP &3.
      SELECTION-SCREEN COMMENT 3(60) &2.
      SELECTION-SCREEN END OF LINE.
    END-OF-DEFINITION.
    SELECTION-SCREEN BEGIN OF BLOCK A0 WITH FRAME TITLE T000.
    * From Config File
    MAKE_RADIOBUTTON RB_1  ALL_DATA SRC.
    SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE T001.
    * Config file from Presentation server
    PARAMETERS: P_FILE1   LIKE T390D-DBNAME  OBLIGATORY. "
    SELECTION-SCREEN END OF BLOCK A1.
    * From database table
    MAKE_RADIOBUTTON RB_2 INC_DOWN SRC.
    SELECTION-SCREEN END OF BLOCK A0.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE1.
      CALL FUNCTION 'WS_QUERY'
           EXPORTING
                QUERY  = 'CD'  "// Current Directory
           IMPORTING
                RETURN = LV_FILE_PATH.
      CALL FUNCTION 'WS_FILENAME_GET'
           EXPORTING
                DEF_FILENAME     = 'TA_DOWNLOAD.MDB'
                DEF_PATH         = LV_FILE_PATH
                MASK             = LV_MASK
                MODE             = 'O'
           IMPORTING
                FILENAME         = P_FILE1
           EXCEPTIONS
                INV_WINSYS       = 1
                NO_BATCH         = 2
                SELECTION_CANCEL = 3
                SELECTION_ERROR  = 4
                OTHERS           = 5.
    INITIALIZATION.
      ALL_DATA = 'From Desktop     : ? '.
      INC_DOWN = 'From Database    : ?'.
      T000     = 'Configuration Upload'.
    Please help
    Thanks

    Hi
    You should do some modifications like these:
    DEFINE MAKE_RADIOBUTTON_1.
      SELECTION-SCREEN BEGIN OF LINE.
      PARAMETERS: &1 RADIOBUTTON GROUP &3 USER-COMMAND &4.
      SELECTION-SCREEN COMMENT 3(60) &2.
      SELECTION-SCREEN END OF LINE.
    END-OF-DEFINITION.
    DEFINE MAKE_RADIOBUTTON_2.
      SELECTION-SCREEN BEGIN OF LINE.
      PARAMETERS: &1 RADIOBUTTON GROUP &3.
      SELECTION-SCREEN COMMENT 3(60) &2.
      SELECTION-SCREEN END OF LINE.
    END-OF-DEFINITION.
    SELECTION-SCREEN BEGIN OF BLOCK A0 WITH FRAME TITLE T000.
    From Config File
    MAKE_RADIOBUTTON_1 RB_1  ALL_DATA SRC AAA.
    SELECTION-SCREEN BEGIN OF BLOCK A1 WITH FRAME TITLE T001.
    Config file from Presentation server
    PARAMETERS: P_FILE1   LIKE T390D-DBNAME MODIF ID FIL. "
    SELECTION-SCREEN END OF BLOCK A1.
    From database table
    MAKE_RADIOBUTTON_2 RB_2 INC_DOWN SRC.
    SELECTION-SCREEN END OF BLOCK A0.
    AT SELECTION-SCREEN OUTPUT.
      IF RB_2 = 'X'.
        LOOP AT SCREEN.
          IF SCREEN-GROUP1 = 'FIL'.
            SCREEN-ACTIVE = 0.
            MODIFY SCREEN.
          ENDIF.
        ENDLOOP.
      ENDIF.
    Max

  • Performance problem with selecting records from BSEG and KONV

    Hi,
    I am having performance problem while  selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
    Regards,
    Prashant

    Hi,
    Some steps to improve performance
    SOME STEPS USED TO IMPROVE UR PERFORMANCE:
    1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
    2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
    3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
    4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
    5. Avoid using nested SELECT statement SELECT within LOOPs.
    6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
    7. Avoid using SELECT * and Select only the required fields from the table.
    8. Avoid nested loops when working with large internal tables.
    9. Use assign instead of into in LOOPs for table types with large work areas
    10. When in doubt call transaction SE30 and use the examples and check your code
    11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
    12. Use "CHECK" instead of IF/ENDIF whenever possible.
    13. Use "CASE" instead of IF/ENDIF whenever possible.
    14. Use "MOVE" with individual variable/field moves instead of "MOVE-
    CORRESPONDING" creates more coding but is more effcient.

  • Reg different kinds of select stmts

    Hi All,
    Hope all are doing gud,
    cud any tell me different kinds of select stmts ????
    regards,
    abc xyz

    hi,
    SELECT
    Basic form
    SELECT result [target] FROM source [where] [GROUP BY fields] [ORDER BY order].
    Effect
    Retrieves an extract and/or a set of data from a database table or view (see Relational database ). SELECT belongs to the OPEN SQL command set.
    Each SELECT command consists of a series of clauses specifying different tasks:
    The SELECT result clause specifies
    whether the result of the selection is a table or a single record,
    which columns the result is meant to have and
    whether the result is allowed to include identical lines.
    The INTO target clause specifies the target area into which the selected data is to be read. If the target area is an internal table, the INTO clause specifies
    whether the selected data is to overwrite the contents of the internal table or
    whether the selected data is to be appended to the contents and
    whether the selected data is to be placed in the internal table all at once or in several packets.
    The INTO clause can also follow the FROM clause.
    You can omit the INTO clause. The system then makes the data available in the table work area (see TABLES ) dbtab . If the SELECT clause includes a "*", the command is processed like the identical SELECT * INTO dbtab FROM dbtab statement. If the SELECT clause contains a list a1 ... an , the command is executed like SELECT a1 ... an INTO CORRESPONDING FIELDS OF dbtab FROM dbtab .
    If the result of the selection is meant to be a table, the data is usually (for further information, see INTO -Klausel ) read line by line within a processing loop introduced by SELECT and concluded by ENDSELECT . For each line read, the processing passes through the loop once. If the result of the selection is meant to be a single record, the closing ENDSELECT is omitted.
    The FROM source clause the source (database table or view ) from which the data is to be selected. It also determines
    the type of client handling,
    the behavior for buffered tables and
    the maximum number of lines to be read.
    The WHERE where clause specifies the conditions which the result of the selection must satisfy. It thus determines the lines of the result table. Normally - i.e. unless a client field is specified in the WHERE clause - only data of the current client is selected. If you want to select across other clients, the FROM clause must include the addition ... CLIENT SPECIFIED .
    The GROUP-BY fields clause combines groups of lines together into single lines. A group is a set of lines which contain the same value for every database field in the GROUP BY clause.
    The ORDER-BY order clause stipulates how the lines of the result table are to be ordered.
    Each time the SELECT statement is executed, the system field SY-DBCNT contains the number of lines read so far. After ENDSELECT , SY-DBCNT contains the total number of lines read.
    The return code value is set as follows:
    SY-SUBRC = 0 At least one line was read.
    SY_SUBRC = 4 No lines were read.
    SY-SUBRC = 8 The search key was not fully qualified.
    (nur bei SELECT SINGLE ). The returned single record is any line of the solution set.
    Example
    Output the passenger list for the Lufthansa flight 0400 on 28.02.1995:
    TABLES SBOOK.
    SELECT * FROM SBOOK
      WHERE
        CARRID   = 'LH '      AND
        CONNID   = '0400'     AND
        FLDATE   = '19950228'
      ORDER BY PRIMARY KEY.
      WRITE: / SBOOK-BOOKID, SBOOK-CUSTOMID,   SBOOK-CUSTTYPE,
               SBOOK-SMOKER, SBOOK-LUGGWEIGHT, SBOOK-WUNIT,
               SBOOK-INVOICE.
    ENDSELECT.
    Performance
    In client/server environments, storing database tables in local buffers (see SAP buffering ) can save considerable amounts of time because the time required to make an access via the network is much more than that needed to access a locally buffered table.
    Notes
    A SELECT command on a table for which SAP buffering is defined in the ABAP/4 Dictionary is normally satisfied from the SAP buffer by bypassing the database. This does not apply with
    - <b>SELECT SINGLE FOR UPDATE
    - SELECT DISTINCT in the SELECT clause ,
    - BYPASSING BUFFER in the FROM clause ,
    - ORDER BY f1 ... fn in the ORDER-BY clause ,
    - aggregate functions in the SELECT clause ,
    - when using IS [NOT] NULL WHERE condition ,</b>
    or if the generic key part is not qualified in the WHERE-Bedingung for a generically buffered table.
    Authorization checks are not supported by the SELECT statement, so you must program these yourself.
    In dialog systems, the database system locking mechanism cannot always guarantee to synchronize the simultaneous access of several users to the same dataset. In many cases, it is therefore advisable to use the SAP locking mechanism .
    Changes to data in a database are only finalized after a database commit (see LUW ). Prior to this, any database update can be reversed by a database rollback (see Programming transactions ). At the lowest isolation level (see the section on the "uncommitted read" under Locking mechanism ), this can result in the dataset selected by the SELECT command not really being written to the database. While a program is selecting data, a second program can add, change or delete lines at the same time. Then, the changes made by the second program are reversed by rolling back the database system. The selection of the first program thus reflects only a very temporary state of the database. If such "phantom data" is not acceptable for a program, you must either use the SAP locking mechanism or at least set the isolation level of the database system to "committed read" (see Locking mechanism ).
    In a SELECT-ENDSELECT loop, the CONTINUE statement terminates the current loop pass prematurely and starts the next.
    If one of the statements in a SELECT ... ENDSELECT loop results in a database commit, the cursor belonging to the SELECT ... ENDSELECT loop is lost and the processing terminates with a runtime error. Since each screen change automatically generates a database commit, statements such as CALL SCREEN , CALL DIALOG , CALL TRANSACTION or MESSAGE are not allowed within a SELECT ... ENDSELECT loop.
    Related OPEN CURSOR , FETCH und CLOSE CURSOR
    SELECT clause
    Variants
    1. <b>SELECT [SINGLE [FOR UPDATE] | DISTINCT] *
    2. SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn
    3. SELECT [SINGLE [FOR UPDATE] | DISTINCT] (itab)</b> Effect
    The result of a SELECT statement is itself a table . The SELECT clause describes which columns this table is supposed to have.
    In addition, you can use the optional addition SINGLE or DISTINCT if you want only certain lines of the solution set to be visible for the calling program:
    SINGLE The result of the selection is a single record . If this record cannot be uniquely identified, the first line of the solution set is selected. The addition FOR UPDATE protects the selected record against parallel changes by other transactions until the next database commit occurs (see LUW and Database locking ). If the database system detects a deadlock, the result is a runtime error.
    DISTINCT Any lines which occur more than once are automatically removed from the selected dataset.
    Note
    To ensure that a record is uniquely determined, you can fully qualify all fields of the primary key by linking them together with AND in the WHERE condition.
    Note
    Performance
    The additions SINGLE FOR UPDATE and DISTINCT exclude the use of SAP buffering .
    The addition DISTINCT requires sorting on the database server and should therefore only be specified if duplicates are likely to occur.
    Variant 1
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] *
    Effect
    In the result set, the columns correspond exactly in terms of order, ABAP/4 Dictionary type and length to the fields of the database table (or view ) specified in the FROM clause .
    Example
    Output all flight connections from Frankfurt to New York:
    TABLES SPFLI.
    SELECT * FROM SPFLI
             WHERE
               CITYFROM = 'FRANKFURT' AND
               CITYTO   = 'NEW YORK'.
      WRITE: / SPFLI-CARRID, SPFLI-CONNID.
    ENDSELECT.
    Example
    Output all free seats on the Lufthansa flight 0400 on 28.02.1995:
    TABLES SFLIGHT.
    DATA   SEATSFREE TYPE I.
    SELECT SINGLE * FROM SFLIGHT
                    WHERE
                      CARRID   = 'LH '      AND
                      CONNID   = '0400'     AND
                      FLDATE   = '19950228'.
    SEATSFREE = SFLIGHT-SEATSMAX - SFLIGHT-SEATSOCC.
    WRITE: / SFLIGHT-CARRID, SFLIGHT-CONNID,
             SFLIGHT-FLDATE, SEATSFREE.
    Variant 2
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn
    Effect
    The order, ABAP/4 Dictionary type and length of the columns of the result set are explicitly defined by the list s1 ... sn . Each si has the form
    ai or ai AS bi .
    Here, ai stands either for
    a field f of the database table or
    a aggregate print.
    bi is an alternative name for the i-th column of the result set.
    When using INTO CORRESPONDING FIELDS OF wa in the INTO clause , you can specify an alternative column name to assign a column of the result set uniquely to a column of the target area.
    An aggregate print uses an aggregate function to group together data from one or all columns of the database table. Aggregate prints consist of three or four components:
    An aggregate function immediately followed by an opening parenthesis DISTINCT (optional) The database field f A closing parenthesis
    All components of a print must be separated by at least one blank.
    The following aggregate functions are available:
    MAX Returns the greatest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    MIN Returns the smallest value in the column determined by the database field f for the selected lines. Specifying DISTINCT does not change the result. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    AVG Returns the average value in the column determined by the database field f for the selected lines. AVG can only apply to a numeric field. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    SUM Returns the sum of all values in the column determined by the database field f for the selected lines. SUM can only apply to a numeric field. NULL values are ignored unless all values in a column are NULL values. In this case, the result is NULL .
    COUNT Returns the number of different values in the column determined by the database field f for the selected lines. Specifying DISTINCT is obligatory here. NULL values are ignored unless all values in a column are NULL values. In this case, the result is 0
    COUNT( * ) Returns the number of selected lines. If the SELECT command contains a GROUP BY clause , it returns the number of lines for each group. The form COUNT(*) is also allowed.
    If ai is a field f , MAX( f ) , MIN( f ) or SUM( f ) , the corresponding column of the result set has the same ABAP/4 Dictionary format as f . With COUNT( f ) or COUNT( * ) , the column has the type INT4 , with AVG( f ) the type FLTP .
    If you specify aggregate functions together with one or more database fields in a SELECT clause, all database fields not used in one of the aggregate functions must be listed in the GROUP-BY clause . Here, the result of the selection is a table.
    If only aggregate functions occur in the SELECT clause, the result of the selection is a single record. Here, the SELECT command is not followed later by an ENDSELECT .
    Notes
    This variant is not available for pooled tables and cluster tables .
    If the SELECT clause contains a database field of type LCHAR or LRAW , you must specify the appropriate length field immediately before.
    Notes
    Performance
    Specifying aggregate functions excludes the use of SAP buffering .
    Since many database systems do not manage the number of table lines and therefore have to retrieve this at some cost, the function COUNT( * ) is not suitable for checking whether a table contains a line or not. To do this, it is best to use SELECT SINGLE f ... for any table field f .
    If you only want to select certain columns of a database table, you are recommended to specify a list of fields in the SELECT clause or to use a View .
    Examples
    Output all flight destinations for Lufthansa flights from Frankfurt:
    TABLES SPFLI.
    DATA   TARGET LIKE SPFLI-CITYTO.
    SELECT DISTINCT CITYTO
           INTO TARGET FROM SPFLI
           WHERE
             CARRID   = 'LH '       AND
             CITYFROM = 'FRANKFURT'.
      WRITE: / TARGET.
    ENDSELECT.
    Output the number of airline carriers which fly to New York:
    TABLES SPFLI.
    DATA   COUNT TYPE I.
    SELECT COUNT( DISTINCT CARRID )
           INTO COUNT FROM SPFLI
           WHERE
             CITYTO = 'NEW YORK'.
    WRITE: / COUNT.
    Output the number of passengers, the total weight and the average weight of luggage for all Lufthansa flights on 28.02.1995:
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH '      AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Variant 3
    SELECT [SINGLE [FOR UPDATE] | DISTINCT] (itab)
    Effect
    Works like SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn if the internal table itab contains the list s1 ... sn as ABAP/4 source code, and like SELECT [SINGLE [FOR UPDATE] | DISTINCT] * , if itab is empty. The internal table itab can only have one field which must be of type C and cannot be more than 72 characters long. itab must appear in parentheses and there should be no blanks between the parentheses and the table name.
    Note
    With this variant, the same restrictions apply as for SELECT [SINGLE [FOR UPDATE] | DISTINCT] s1 ... sn .
    Example
    Output all Lufthansa flight routes:
    TABLES: SPFLI.
    DATA:   FTAB(72) OCCURS 5 WITH HEADER LINE.
    REFRESH FTAB.
    FTAB = 'CITYFROM'. APPEND FTAB.
    FTAB = 'CITYTO'.   APPEND FTAB.
    SELECT DISTINCT (FTAB)
           INTO CORRESPONDING FIELDS OF SPFLI
           FROM SPFLI
           WHERE
             CARRID   = 'LH'.
      WRITE: / SPFLI-CITYFROM, SPFLI-CITYTO.
    ENDSELECT.
    check this one:
    http://www.sts.tu-burg.de/teaching/sap_r3/ABAP4/select.htm

  • Select stmt taking long time.

    Hi,
    This select stmt is taking very long time to execute. Can you please guide me to improve it.
    SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
              FROM LIKP
              INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
              INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
              INTO CORRESPONDING FIELDS OF TABLE IT_OUTPUT
              WHERE LIKP~LFDAT IN S_LFDAT
                    AND LIKP~KUNNR IN S_KUNNR
                    AND LIKP~LIFSK = P_LIFSK.
    Thanks
    Veni.

    >> SELECT LIKPVBELN LIKPLFDAT LIKPKUNNR LIKPKNKLI VBAK~NETWR
    >> FROM LIKP
    >> INNER JOIN LIPS ON LIKPVBELN = LIPSVBELN
    >> INNER JOIN VBAK ON LIPSVGBEL = VBAKVBELN
    >> INTO CORRESPONDING FIELDS OF TABLE IT_OUTPUT
    >> WHERE LIKP~LFDAT IN S_LFDAT
    >> AND LIKP~KUNNR IN S_KUNNR
    >> AND LIKP~LIFSK = P_LIFSK.
    Based on the select that you have in your post, this is what I see.
    As output, you only need fields from LIKP and only one field from VBAK.
    All your fields on the WHERE clause is on LIKP data.
    You only need LIPS for the Sales document number.
    Can you please make a copy of your program and try this below code?
    It would be interesting to see if the extra vgbel sort would help.
    TYPES:
      BEGIN OF TY_LIKP,
        VBELN TYPE LIKP-VBELN,
        LFDAT TYPE LIKP-LFDAT,
        KUNNR TYPE LIKP-KUNNR,
        KNKLI TYPE LIKP-KNKLI,
        NETWR TYPE VBAK-NETWR,
        VGBEL TYPE LIPS-VGBEL,
      END OF TY_LIKP.
    DATA:
      I_LIKP TYPE STANDARD TABLE OF TY_LIKP
        INITIAL SIZE 0
        WITH HEADER LINE,
      BEGIN OF I_VGBEL OCCURS 0,
        VGBEL TYPE LIPS-VGBEL,
      END OF I_VGBEL,
      BEGIN OF I_VBAK OCCURS 0,
        VBELN TYPE VBAK-VBELN,
        NETWR TYPE VBAK-NETWR,
      END OF I_VBAK.
    FIELD-SYMBOLS:
      <FS_LIKP> TYPE TY_LIKP.
    SELECT LIKP~VBELN LIKP~LFDAT LIKP~KUNNR LIKP~KNKLI LIPS~VGBEL
      INTO CORRESPONDING FIELDS OF TABLE I_LIKP
      FROM LIKP
      JOIN LIPS ON LIPS~VBELN EQ LIKP~VBELN
      WHERE LIKP~LFDAT IN S_LFDAT
      AND   LIKP~KUNNR IN S_KUNNR
      AND   LIKP~LIFSK EQ P_LIFSK.
    IF I_LIKP[] IS NOT INITIAL.
      LOOP AT I_LIKP ASSIGNING <FS_LIKP>.
        CLEAR I_VGBEL.
        I_VGBEL-VGBEL = <FS_LIKP>-VGBEL.
        APPEND I_VGBEL.
      ENDLOOP.
      SORT I_VGBEL.
      DELETE ADJACENT DUPLICATES FROM I_VGBEL.
      IF I_VGBEL[] IS NOT INITIAL.
        SELECT VBELN NETWR INTO TABLE I_VBAK
          FROM VBAK
          FOR ALL ENTRIES IN I_VGBEL
          WHERE VBELN EQ I_VGBEL-VGBEL.
        SORT I_VBAK BY VBELN.
        FREE I_VGBEL.
        LOOP AT I_LIKP ASSIGNING <FS_LIKP>.
            CLEAR I_VBAK.
            READ TABLE I_VBAK WITH KEY VBELN = <FS_LIKP>-VGBEL
                                       BINARY SEARCH.
            IF SY-SUBRC EQ 0.
              <FS_LIKP>-NETWR = I_VBAK-NETWR.
    * Note that you don't need to do the Modify statement here
    * because of the field symbol
            ENDIF.
          ENDIF.
        ENDLOOP.
    * Just ignore I_LIKP-VGBEL from all your reporting needs
      ENDIF.
    ENDIF.

  • How to convert update,delete statement into select stmt

    Hi all,
         I have a field called dml_stmt, i am getting the dml statement has input from the user.
         My requirement is, if user is giving "update set col_name = 'xyz' from table_name where codition = 'aa'", before updating the table, i need to get old values from the table and put it in the audit table
         For that,i need to convert those update statement into select stmt and need to execute the query to get the data and then i will put it in the audit table..
         can anyone guide how to convert the update or delete stmt into select(need to write in pl/sql)
    Please do needfull things ......
    Regards,
    Jame

    Maybe I'm missing something, but why would auditing help here? It sounds like the user wants to know the prior values of the data, not the SQL UPDATE statement that was issued. Auditing would tell you that a table was updated, fine-grained auditing would tell you what the UPDATE statement was, but you'd need something else to capture the state of the data prior to the update.
    Depending on why putting triggers on every table was discounted, you may also want to take a look at using Workspace Manager or Total Recall (in 11g) to track a history of data changes. But triggers would be the common solution to this sort of problem.
    Justin

  • I have a problem in select-options

    hi frns,
             i am facing a big problem in select-options
    the requirement is such that
    i have 2 select-options
    one for matnr and the other for maktx
    so wen the clent select matnr with f4
    in the maktx the similar description should come by using f4
    pls help me out

    hi,
    TYPES DECLARATION
    types: begin of tp_marc,
            matnr type marc-matnr,
            werks type marc-werks,
          end of tp_marc.
    INTERNAL TABLE AND WORK AREA DECLARATION
    data: t_marc type standard table of tp_marc,
          wa_marc type tp_marc.
    data : dd like table of dselc with header line. "*--- IMPORTANT
    data : ft like table of dfies with header line.
    data : t_makt like table of makt with header line.
    parameters : matnr like makt-matnr .
    parameters : maktx like makt-maktx.
    at selection-screen output.
      loop at screen.
        if screen-name = 'MAKTX'.
          screen-input = 0.
          modify screen.
        endif.
      endloop.
    at selection-screen on value-request for matnr.
    SELECT matnr maktx  FROM makt INTO TABLE makt up to 500 rows.
      select *
       from makt
        up to 500 rows
      into table t_makt
      where spras = syst-langu.
      if sy-subrc <> 0.
        message 'INVALID MATERIAL NUMBER' type 'E'.
      endif.
    IMPORTANT
      refresh dd.
    dd-fldname = 'MATNR'.
    dd-dyfldname = 'MATNR'.
    append dd.
      dd-fldname = 'MAKTX'.
      dd-dyfldname = 'MAKTX'.
      append dd.
    *------- IMPORTANT
      refresh ft.
      ft-tabname = 'MAKT'.
      ft-fieldname = 'MATNR'.
      append ft.
      ft-tabname = 'MAKT'.
      ft-fieldname = 'MAKTX'.
      append ft.
      call function 'F4IF_INT_TABLE_VALUE_REQUEST'
      exporting
    ddic_structure = 'T001' "*----- IMPORTANT IF STANDARD STRUCT
      retfield = 'MATNR'
      dynpprog = sy-repid
      dynpnr = sy-dynnr
      dynprofield = 'MATNR'
      value_org = 'S'
      tables
      field_tab = ft "*---- IMPORTANT
      value_tab = t_makt
      dynpfld_mapping = dd "* IMPORTANT
      exceptions
      parameter_error = 1
      no_values_found = 2
      others = 3.
      start-of-selection.
      select matnr
             werks
             from marc
             into table t_marc
             where matnr = matnr.
      if sy-subrc <> 0.
        message :'no results IN MARC' type 'E'.
      endif.
      write: at 1(36) sy-uline.
      format intensified on color = 7.
      new-line.
      write :sy-vline,at 10 'MATERIAL NUMBER',at 29 sy-vline, at 30 'PLANT',sy-vline.
      new-line.
      write: at 1(36) sy-uline.
      format intensified off color = 4.
      loop at t_marc into wa_marc.
        new-line.
        write :sy-vline,at 10 wa_marc-matnr ,sy-vline, at 30 wa_marc-werks, at 36 sy-vline.
      endloop.
      new-line.
      write: at 1(36) sy-uline.
    reward points if useful.
    regards,
    Vinod Samuel.

  • Problem in selecting records

    Hi, everyone.
    I have a problem in selecting records.  In this case, I want to select records from database
    LFA1,and the components of this table are LIFNR,ERDAT,LOEVM ,and so on.The type of LIFNR is char(10).There is a internal table:tab_cdhdr , the elements of tab_cdhdr are: objectid,udate and change_ind.The type of objectid is char(50).
    And the select-rule is that: LIFNR = objectid. So I write like this:
    select   lifnr
                 erdat
                 loevm
    form     lfa1
    into       tab_lfa1
    for all entries in tab_cdhdr
    where   lfa1 = tab_cdhdr-objectid+0(10).
    But there is a warning: When using FOR ALL ENTRIES IN the specifyed length for "OBJECTID" is ignored in this condition.
    Can you help me to solve this problem?
    Thanks.

    Hi Feng..
    If you dont want to change the Internal table TAB_CDHDR, Then declare another internal table (TEMPTAB_CDHDR.) with the same structure but Objectid with only 10 chars.
    IF TAB_CDHDR[] IS NOT INITIAL.
    LOOP AT TAB_CDHDR.
    MOVE-CORRESPONDING TAB_CDHDR TO TEMPTAB_CDHDR.
    APPEND TEMPTAB_CDHDR.
    ENDLOOP.
    select lifnr
    erdat
    loevm
    form lfa1
    into tab_lfa1
    for all entries in tab_cdhdr
    where lfa1 = TEMPtab_cdhdr-objectid.
    ENDIF.
    Sure ... this will work for u.....
    REWARD IF HELPFUL.

  • Error  with select stmt.

    Hi All,
    I am getting this error , can you please tell me what I am doing wrong with the select stmt.
    SELECT AFKDAT ANETWR B~KZWI1
                         FROM VBRK AS A INNER JOIN VBRP AS B ON
                              AVBELN = BVBELN
                              INTO (IOUT-FKDAT, IOUT-NETWR, IOUT-KZWI1)
                              WHERE B~VBELN = IOUT-VBELV
                              AND   B~POSNR = ISDOC-POSNR.
    Incorrect nesting: Before the statement "ENDIF", the structure          
    introduced by "SELECT" must be concluded by "ENDSELECT". -
    Thanks
    Veni.

    Hi All,
    I tried INTO CORRESPONDING FIELDS OF IOUT
    but with this also same error is comming. I am sending part of code.
    Please help me.
    Thanks
    Veni.
    TABLES: VBAK, VBAP, KNA1, VBRK, VBRP, VBFA.
    DATA: BEGIN OF ISDOC OCCURS 0,
            VBELN LIKE VBAK-VBELN,
            POSNR LIKE VBAP-POSNR,
            KUNNR LIKE VBAK-KUNNR,
            ERDAT LIKE VBAK-ERDAT,
            BSTNK LIKE VBAK-BSTNK,
            MATNR LIKE VBAP-MATNR,
            ARKTX LIKE VBAP-ARKTX.
    DATA: END OF ISDOC.
    DATA: BEGIN OF IOUT OCCURS 0,
            VBELN LIKE VBAK-VBELN,
            POSNR LIKE VBAP-POSNR,
            KUNNR LIKE VBAK-KUNNR,
            NAME1 LIKE KNA1-NAME1,
            ERDAT LIKE VBAK-ERDAT,
            BSTNK LIKE VBAK-BSTNK,       
            MATNR LIKE VBAP-MATNR,
            ARKTX LIKE VBAP-ARKTX,
            VBELV LIKE VBRP-VBELN,
            FKDAT LIKE VBRK-FKDAT,
            NETWR LIKE VBRK-NETWR,
            KZWI1 LIKE VBRP-KZWI1.
    DATA: END OF IOUT.
    FORM getdata.
      SELECT A~VBELN B~POSNR A~KUNNR A~ERDAT A~BSTNK B~MATNR B~ARKTX
             FROM VBAK AS A INNER JOIN VBAP AS B ON A~VBELN = B~VBELN
             INTO TABLE ISDOC
             WHERE A~AUART IN SAUART
             AND A~ERDAT IN SERDAT
             AND A~KUNNR IN SKUNNR.
               SORT ISDOC BY VBELN POSNR.
      LOOP AT ISDOC.
        MOVE-CORRESPONDING ISDOC TO IOUT.
        CLEAR: KNA1.
        SELECT SINGLE * FROM KNA1 WHERE KUNNR = ISDOC-KUNNR.
        IF SY-SUBRC = 0.
          MOVE KNA1-NAME1 TO IOUT-NAME1.
        ENDIF.
        SELECT VBELN INTO IOUT-VBELV FROM VBFA WHERE VBELV = ISDOC-VBELN
                                               AND   POSNV = ISDOC-POSNR
                                               AND   VBTYP_N = 'O'.
          IF SY-SUBRC = 0.
            SELECT A~FKDAT A~NETWR B~KZWI1
                   FROM VBRK AS A INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
                   INTO CORRESPONDING FIELDS OF IOUT
    *               (IOUT-FKDAT, IOUT-NETWR, IOUT-KZWI1)
                         WHERE B~VBELN = IOUT-VBELV
                         AND   B~POSNR = ISDOC-POSNR.
              APPEND IOUT.
              CLEAR IOUT.
            ENDIF.
          ENDLOOP.
        ENDFORM.                    " getdata

  • Query on select stmt

    hi,
    below is the extraction logic
    1.     Select all invoice documents from Table VBRK where Sales Organization VBRK-VKORG, Distribution Channel VBRK- VTWEG and Division VBRK-SPART matches to Sales Organization, Distribution Channel and Division specified in the selection parameters and SD Document Catergory VBRK- VBTYP <> N u2013 Invoice Cancellation type S1 and S2.
    2.     Select all invoice documents from the above where all Sold-to party/Ship-to party customers VBRK-KUNAG and payer customers VBRK-KUNRG matches to Sold-to party/Ship-to party and payer specified in the selection parameters
    how to write the select stmts for the abluve logic??.
    thank you in advance.

    Hi.
    I will lock this thread. This is not a question that should be discussed in this forum. Your specification is so close to real code that even without any ABAP knowledge a look into some demo programs and the online help for 'SELECT' will solve it.
    As Martin said: If you tried it and have any particular problems then we can discuss them here.
    Best regards,
    Jan Stallkamp

  • Problem about selecting waveform in waveform graph

    Hi all:
    I am developing a project by Labview. Now I meet a problem about selecting the waveform in the waveform graph.
    I am not sure whether it is possible about my idea.
    for example:
    In the waveform graph,  the different waveforms from a couple of channels are displayed. and then I want to select one waveform of them, and corresponding data about this waveform are shown. 
    Thanks so lot
    regards

    hanwei wrote:
    1.  can I zoom in and out in that "waveform graph"??
    You can do this using the graph palette. Just make it visible. The middle control allows you to zoom.
    2.  can I display the plot array or plot index that I select in the waveform graph?
    You can connect the same wire that goes to the ActivePlot property node to an indicator.
    3.  I build a sample codes for my project, in which , I used a random number generater to simulate a DAQmx data collection, and generate a overlapping waveform in the waveform graph.
         but it seems the program is not stable, when i first run the codes, it is ok, and I can select the plot what I want. but after I stop and restart the program, there is error message about "Property Node".
         it seems something wrong about the "waveform graph properties"
    I attached my codes here, anybody know what wrong about it?
    For some strange reason the property node is "messed up". I've seen this happen sometimes with graphs. I don't know what causes it, and the only way I've found to fix the problem is to delete the graph, put a new one on the front panel, and recreate the property nodes. I've typically seen this happen when copying code from another VI that has a graph with property nodes, as I suspect you did. If you delete the graph, put a new one on there, and recreate the property node you should be OK.
    That said, a few comments regarding the code:
    The architecture seems to be a mish-mash of operations, and I'm thinking that you probably want to look at using a producer-consumer architecture. Your producer loop responds to events, and the consumer loop does your DAQ collection.
    You have a race condition with your use of the "size(s) 2" local variable.
    Avoid right-to-left wires.
    The method of creating your arrays seems convoluted. However, since you said you will actually be getting the data from a DAQ system, the actual project code will likely be considerably different.

Maybe you are looking for

  • Internal table with Import and Export

    Hi All, Hi all Please let me know the use of <b>Internal table with Import and Export parameters and SET/GET parameters</b>, on what type of cases we can use these? Plese give me the syntax with some examples. Please give me detailed analysis on the

  • Server Admin | Server Updates | updated to 10.5.5 WITHOUT restart?

    A curious thing. I wonder whether anyone else experienced the same, or similar- When the update to Mac OS X Server 10.5.5 was released, very soon after its announcement, I used Server Admin | Server Updates to apply the update to my Mac OS X Server 1

  • Need Acrobat 9 Pro back

    Hi, everybody! Moved to CS6 (Design & Web Premium, Win7 64-bit) but I'm not happy with Acrobat X Pro--I need my comments on the bottom of Acrobat window and not on the right side. Can I uninstall only Acrobat X Pro from CS6 Design & Web Premium colle

  • Curve 8520 keeps freezing and going to white screen

    I recently had my curve replaced after the trackpad stopped working. Now my new curve keeps freezing when I'm on the internet, the screen will get white lines across it which gradually get bigger until the whole screen is white. A reboot doesn't work

  • Audio in/out port MacbookPro 13inch

    Hi! I bought before 3 ago a MBP 13inch (Mid 2012) and i want to ask if the headphones port can change to a audio in/out port through a IOS update in the near future.You see i´m a musician and this is really annoying the absence of a line in audio por