Select for all entries

Hi,
      I am new in abap reports. Now i want to know why we should use select for all entries in query. We can do retrieve directly by accessing the table in database dictionary.
      Experts please give me the reasons I want to know the concepts behind it.It will be better if you kindly explain this with help of code.
     With regards,
       Abir.

HI
GOOD
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.
Note
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
- 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 ,
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
GO THROUGH THIS LINK
http://www.geocities.com/SiliconValley/Campus/6345/select.htm
THANKS
MRUTYUN

Similar Messages

  • Dynamic select for all entries?

    Hi!
    Is it possible to do a dynamic SELECT FOR ALL ENTRIES IN... command?
    sg. like:
      DATA:
        select_text TYPE string,
        from_text TYPE string,
        where_text TYPE string.
      SELECT FOR ALL ENTRIES IN <gt_table1> (select_text)
      into corresponding fields of table <gt_table2>
      FROM (from_text)
      WHERE (where_text).
    Thanks and Best Regards,
    Tamas

    Hi,
    you can use the Dynamic Selects for FOR ALL ENTRIES, but i think you may need to use the correct Internal table to match the tabel structure
    Regards
    Sudheer

  • Dynamic OpenSQL - SELECT FOR ALL ENTRIES ?

    Hi!
    Is it possible to do a dynamic SELECT FOR ALL ENTRIES IN... command?
    sg. like:
    DATA:
    select_text TYPE string,
    from_text TYPE string,
    where_text TYPE string.
    SELECT FOR ALL ENTRIES IN <gt_table1> (select_text)
    into corresponding fields of table <gt_table2>
    FROM (from_text)
    WHERE (where_text).
    Thanks and Best Regards,
    Tamas

    Hi
    INSERT INTO (SELECT department_id, department_name, location_id
       FROM departments WHERE location_id < 2000)
       VALUES (9999, 'Entertainment', 2500);
    Is this you are looking for ?
    Regards
    Vinod

  • Usage of 'Select for all entries' for dynamic internal tables..

    Hi all,
    I have a situation where I need to use select for all entries for a dynamic internal table.
    select * from /BIC/AZHSD_O1500 into i_table for all entries in <b>Dynamic_table</b> where doc_number = <dynamic_table????????>
    here iam not knowing how to match the <dynamic_table????????> doc_number ?
    the dynamic_table contains the doc_number as one field.
    here dynaimc_table is the internal table which is dynamic.
    I have tried various options but couldnot find the solution.
    Please resolve.
    Sidhartha.

    data : i_dyn_where type char72 occurs 0.
    field-symbols : <fs> type table.
    assign itab[] to <fs>.
    i_dyn_where = 'docno = <fs>-docno'.
    append i_dyn_where.
    select *
    from   vbak
    into   table t_vbak
    for    all entries in <fs>
    where  (I_dyn_where).   "Populate this where condition dynamically too
    Hope this will solve ur prob.

  • Use HR_READ_INFOTYPE or select (for all entries)

    Hi
    As I have understood the difference between FM HR_READ_INFOTYPE and a select directly from PA0001 (as example) is that the FM take the authorization into account. (please correct me if I am wrong).
    My problem is that I need to select from the infotype for a lot of pernr, so I would use this statement:
        SELECT * FROM pa0001 INTO CORRESPONDING FIELDS OF TABLE wt_pa0001
          FOR ALL ENTRIES IN wt_pernr
             WHERE pernr = wt_pernr-pernr
              AND begda LE pn-endda
              AND endda GE pn-begda.
    but then I don't get the authorization check.
    For the FM HR_READ_INFOTYPE I can't use the "FOR ALL ENTRIES".
    Can I do it in an easy way, or do need to do the select, and then use an authority check after the select from each infotype?

    Calling HR_READ_INFOTYPE or selecting directly from the tables may depend on how much data you are processing.  If you only need to retrieve a few records, you could process the PERNR records you need in a loop and call HR_READ_INFOTYPE for each.  If you're processing a larger number of records, check the authorization for the each table first and then do a SELECT for all entries.  Before you read, make sure that your "FOR ALL ENTRIES" table is not empty.  In order to make your code more generic, you may want to use function module HR_CHECK_AUTHORITY_INFTY to check the authorization for each infotype.  This is the FM that the HR_READ_INFOTYPE function module uses.
    .. Craig

  • Select FOR ALL ENTRIES statement cannot get duplicates entries

    Hi all,
    t_yxapy_fields consist of
    inty  field
    0001 kostl
    0002 perid
    0008 ansal
    0008 preas
    0008 trfst
    The following is the code for me to transfer the contents of t_yxapy_fields into t_pa_fields.
    SELECT dbtab
          FROM t777d
          INTO TABLE t_pa_fields
          FOR ALL ENTRIES IN t_yxapy_fields
          WHERE infty = t_yxapy_fields-infty.
    And t_pa_fields just ended up with
    field   infty
    pa0001
    pa0002
    pa0008
    Question:The first table have 3 similar infotype 0008 but the result table only have one pa0008. I need to filled up acordingly as what table 1 have. I need another 2 pa0008 in my 2nd table. What is wrng with my Select for all entries statement here?
    Edited by: Siong Chao on Mar 27, 2010 10:35 AM

    This has nothing to do with duplicates in t777d.
    Correct, I failed to recognize that table t777d has only infty as key as pointed out by Aby. Thus in your particular case my comment was misleading. In general though FOR ALL ENTRIES removes all duplicate rows from your result set.
    If you want the other 2 values just loop t_yxapy_fields this table and read t_pa_fields and if record found add the other values to t_pa_fields table. --> will trigger performance tuning issue
    I'm pretty sure if you'd code this, you won't run into any performance issues, so follow Aby's recipe. To be more concrete, here's what I'd do: Define a mapping table t777d_tab, which holds the translation from infty to dbtab:
    types:
      begin of T_T777D_VIEW,
        INFTY type T777D-INFTY,
        DBTAB type T777D-DBTAB,
      end of T_T777D_VIEW.
    data:
      T777D_TAB type hashed table of T_T777D_VIEW with unique key INFTY.
    Fill table t_pa_fields, typed using t_t777d_tab from above, from table t777d. Then loop over your table t_yxapy_fields (I'd use [LOOP AT ... ASSIGNING|http://help.sap.com/abapdocu_70/en/ABAPLOOP_AT_ITAB_RESULT.htm] instead of LOOP AT ... INTO) and for each entry get the corresponding DBTAB value from t777d_tab (again use the [READ TABLE ... ASSIGNING|http://help.sap.com/abapdocu_70/en/ABAPREAD_TABLE_OUTDESC.htm] variant) and build your result table t_pa_fields.
    Anyhow, I suspect that even with less optimal coding (e.g. using just standard table for lookup of DBTAB values) you'd not see much of an performance impact, because it seems that your internal tables are most likely rather small...
    Cheers, harald

  • Select -- for all entries.. fetching Duplicates

    Hi,
    Im using a Select- for all entries structure. Actually Select will supress the Duplicates .But i have a table which has 20000 entries , but my select --for all entries fetching around 56000 records..!
    Any idea/ anybody have Experience this kind of Problem..?
    If i sort the internal table would it resolve the proble..? Because its not happening in all cases.. but for few cases only its extracting duplicates.. other times..its supressing the duplicates.
    Appreciate any advise.

    Hi,
    Just check the table is not initial and then write select statement.
    if not internaltable1[] is initial.
    select field into table internaltable2 for all entries in internaltable1 where field1 = internaltable1-field1.
    endif.
    *Then sort the internaltable2
    sort internaltable2 by field.
    delete adjacent dulpcates from internaltable2 comparing field.
    Hope this helps.
    Regards,
    J.Jayanthi

  • Inner join and select for all entries with respect to performance

    Hi Friends,
    I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient? and how? can you explain me in detail ?
    Regards,
    Dinesh

    INNER JOIN->
    The data that can be selected with a view depends primarily on whether the view implements an inner join or an outer join. With an inner join, you only get the records of the cross-product for which there is an entry in all tables used in the view. With an outer join, records are also selected for which there is no entry in some of the tables used in the view.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21ec77446011d189700000e8322d00/content.htm
    FOR ALL ENTRIES->
    Outer join can be created using this addition to the where clause in a select statement. It speeds up the performance tremendously, but the cons of using this variation are listed below
    Duplicates are automatically removed from the resulting data set. Hence care should be taken that the unique key of the detail line items should be given in the select statement.
    If the table on which the For All Entries IN clause is based is empty, all rows are selected into the destination table. Hence it is advisable to check before-hand that the first table is not empty.
    If the table on which the For All Entries IN clause is based is very large, the performance will go down instead of improving. Hence attempt should be made to keep the table size to a moderate level.
    Not Recommended
    Loop at int_cntry.
    Select single * from zfligh into int_fligh
    where cntry = int_cntry-cntry.
    Append int_fligh.
    Endloop.
    Recommended
    Select * from zfligh appending table int_fligh
    For all entries in int_cntry
    Where cntry = int_cntry-cntry.

  • Driver table in select for all entries

    anyone please let me what is driver table in select for all entries and when do we go for select for all entries

    Here is something from help
    FOR ALL ENTRIES WHERE
    Syntax
    ... FOR ALL ENTRIES IN itab WHERE ... col operator itab-comp ...
    Effect
    If the addition FOR ALL ENTRIES is specified before the language element WHERE, then the components comp of the internal table itab can be used as operands when comparing with relational operators.
    The internal table itab must have a structured line type and the component comp must be compatible with the column col.
    The logical expression sql_cond of the WHERE condition can comprise various logical expressions by using AND and OR. However, if FOR ALL ENTRIES is specified, there must be at least one Comparison with a column of the internal table itab, which can be specified either statistically or dynamically (Release 6.40 and higher). In a statement with a SELECTstatement with FOR ALL ENTRIES, the addition ORDER BY can only be used with the addition PRIMARY KEY.
    The whole logical expression sql_cond is evaluated for each individual line of the internal table itab. The resulting set of the SELECT statement is the union of the resulting sets from the individual evaluations. Duplicate lines are automatically removed from the resulting set. If the internal table itab is empty, the whole WHERE statement is ignored and all lines in the database are put in the resulting set.
    Notes
    In Release 6.10 and higher, the same internal table can be specified after FOR ALL ENTRIES and after INTO.
    The addition FOR ALL ENTRIES is only possible before WHERE conditions of the SELECT statement.
    Example
    Exporting all flight data for a specified departure city. The relevant airlines and flight numbers are first put in an internal table entry_tab, which is evaluated in the WHERE condition of the subsquent SELECT statement.
    PARAMETERS p_city TYPE spfli-cityfrom.
    TYPES: BEGIN OF entry_tab_type,
             carrid TYPE spfli-carrid,
             connid TYPE spfli-connid,
           END OF entry_tab_type.
    DATA: entry_tab   TYPE TABLE OF entry_tab_type,
          sflight_tab TYPE SORTED TABLE OF sflight
                           WITH UNIQUE KEY carrid connid fldate.
    SELECT carrid connid
           FROM spfli
           INTO CORRESPONDING FIELDS OF TABLE entry_tab
           WHERE cityfrom = p_city.
    SELECT carrid connid fldate
           FROM sflight
           INTO CORRESPONDING FIELDS OF TABLE sflight_tab
           FOR ALL ENTRIES IN entry_tab
           WHERE carrid = entry_tab-carrid AND
                 connid = entry_tab-connid.
    Regards,
    Santosh

  • Regarding SELECT FOR ALL ENTRIES AND DELETE ADJACENT DUPLICATES

    Hi,
    i got few doubts.....
        1) Is it necessary to DELETE ADJACENT DUPLICATES when we perform a SELECT FOR ALL ENTRIES ? because for all entries itself eliminates the duplicate entries?
       2) Wat Sy-subrc returns after a SELECT FOR ALL ENTRIES statement?
       I found some code where these are used
               SORT ITAB[] BY NEWKO[].
              DELETE ADJACENT DUPLICATES FORM ITAB[].
      SELECT buknr
                   kunnr
    FORM KNB1
        into table ITAB_KNB1
      FOR ALL ENTRIES IN ITAB
        where kunnr eq itab-newko.
    Regards.
    Maehsh.

    Hi Mahesh,
    To be more specific, first you should delete "adjacent duplicates" using the sorting key ( here : NEWKO ), if Itab contains other fields.
    SORT ITAB[] BY NEWKO[].
    DELETE ADJACENT DUPLICATES FORM ITAB COMPARING NEWKO.
    You can delete or not the duplicates, but, you must know that if you don't delete them in the Itab, you will retrieve them in the ITAB_KNB1.
    Concerning the return code, it works like for the "SELECT"  ( 0 = entries found / 4 = no entrie found )
    => One more thing, it's better check :
    Check not ITab[] is initial
    because, if the Itab is empty, you'll retrieve all the record of KNB1 !
    Hope this helps,
    Erwan.
    Message was edited by:
            Erwan LE BRUN

  • Regarding select for all entries

    Hi all,
    I want to use select for all entries....
    because i have to club 3 tablese and get the data.
    I can go for inner joins but i cant use because of performmance issues.
    so can anybody help me regarding this.
    thanks and regards,
    giri.

    do this way............
    types: begin of gt_vbrk,
            vbeln type vbrk-vbeln,
            fkart type vbrk-fkart,
            knumv type vbrk-knumv,
            bukrs type vbrk-bukrs,
            waerk type vbrk-waerk,
            netwr type vbrk-netwr,
            end of gt_vbrk,
            begin of gt_vbrp,
            vbeln type vbrp-vbeln,
            posnr type vbrp-posnr,
            fkimg type vbrp-fkimg,
            meins type vbrp-meins,
            gsber type vbrp-gsber,
            netwr type vbrp-netwr,
            aubel type vbrp-aubel,
            aupos type vbrp-aupos,
            end of gt_vbrp,
            begin of gt_vbak,
            vbeln type vbak-vbeln,
            augru type vbak-augru,
            vkgrp type vbak-vkgrp,
            gsber type vbak-gsber,
            end of gt_vbak,
            begin of gt_vbap,
            vbeln type vbap-vbeln,
            posnr type vbap-posnr,
            matnr type vbap-matnr,
            netwr type vbap-netwr,
            end of gt_vbap,
    data : git_vbrk type standard table of gt_vbrk,
          git_vbrp type standard table of gt_vbrp,
          git_vbak type standard table of gt_vbak,
          git_fcode type table of gt_fcode,
          git_vbap type table of gt_vbap.
    data : wa_vbrk type gt_vbrk,
          wa_vbrp type gt_vbrp,
          wa_vbak type gt_vbak,
          wa_fcode type gt_fcode,
          wa_vbap type gt_vbap.
    select  vbeln
              fkart
              knumv
              bukrs
              waerk
              netwr
        from vbrk into table git_vbrk
        where vbeln in s_vbeln.
      if sy-subrc eq 0.
        sort git_vbrk by vbeln.
      endif.
    if not git_vbrk[] is initial.
    clear git_vbrp[].
      select  vbeln
              posnr
              fkimg
              meins
              gsber
              netwr
              aubel
              aupos
         from vbrp into table git_vbrp
         for all entries in git_vbrk
         where vbeln = git_vbrk-vbeln.
      if sy-subrc eq 0.
        sort git_vbrp by vbeln.
      endif.
    select  vbeln
              augru
              vkgrp
              gsber
        from vbak into table git_vbak
        for all entries in git_vbrp
        where vbeln = git_vbrp-aubel.
      if sy-subrc eq 0.
        sort git_vbak by vbeln.
      endif.
    reward points if helpful............

  • Inner join and select for all entries with respect to performance in SAP

    Hi Friends,
    I just want to know which is more efficient with respect to performance the Inner join or select for all entries?which is more efficient?
    Regards,
    Dinesh

    I did some testing a while ago and found that a JOIN is usually a bit more efficient than FOR ALL ENTRIES. This wasn't always the case though, so the best thing to do is to write it both ways and see which is faster.
    Rob

  • Performance on Select Single&Write  AND Select*(For All Entries)&Read&Write

    Hi Experts,
    I got a code review problem & we are in a argument.
    I need the best performance code out of this two codes. I have tested this both on 5 & 1000 & 3000 & 100,000 & 180,000 records.
    But still, I just need a second opinion of experts.
    TYPES : BEGIN OF ty_account,
            saknr   TYPE   skat-saknr,
            END OF ty_account.
    DATA : g_txt50      TYPE skat-txt50.
    DATA : g_it_skat    TYPE TABLE OF skat,       g_wa_skat    LIKE LINE OF g_it_skat.
    DATA : g_it_account TYPE TABLE OF ty_account, g_wa_account LIKE LINE OF g_it_account.
    Code 1.
    SELECT saknr INTO TABLE g_it_account FROM skat.
    LOOP AT g_it_account INTO g_wa_account.
      SELECT SINGLE txt50 INTO g_txt50 FROM skat
        WHERE spras = 'E'
          AND ktopl = 'XXXX'
          AND saknr = g_wa_account-saknr.
      WRITE :/ g_wa_account-saknr, g_txt50.
      CLEAR : g_wa_account, g_txt50.
    ENDLOOP.
    Code 2.
    SELECT saknr INTO TABLE g_it_account FROM skat.
    SELECT * INTO TABLE g_it_skat FROM skat
      FOR ALL ENTRIES IN g_it_account
          WHERE spras = 'E'
            AND ktopl = 'XXXX'
            AND saknr = g_it_account-saknr.
    LOOP AT g_it_account INTO g_wa_account.
      READ TABLE g_it_skat INTO g_wa_skat WITH KEY saknr = g_wa_account-saknr.
      WRITE :/ g_wa_account-saknr, g_wa_skat-txt50.
      CLEAR : g_wa_account, g_wa_skat.
    ENDLOOP.
    Thanks & Regards,
    Dileep .C

    Hi Dilip.
    from you both the code I have found that you are selecting 2 diffrent fields.
    In Code 1.
    you are selecting SAKNR and then for these SAKNR you are selecting TXT50 from the same table.
    and in Code 2 you are selecting all the fields from SAKT table for all the values of SAKNR.
    I don't know whats your requirement.
    Better you declare a select option on screen and then fetch required fields from SAKT table for the values entered on screen for SAKNR.
    you only need TXT50 and SAKNR fields.
    so declare two types one for SAKNR and another for TXT50.
    Points to be remember.
    1. while using for all entries always check the for all entries table should not be blank.
    2. you will have to fetch all the key fields in table while applying for all entries,
        you can compare key fields with a constant which is greater than initial value.
    3. while reading the table sort the table by the field on which you are going to read it.
    try this:
    TYPES : BEGIN OF ty_account,
    saknr TYPE skat-saknr,
    END OF ty_account.
    TYPES : begin of T_txt50,
          saknr type saknr,
          txt50 type txt50,
    end of t_txt50.
    DATA: i_account type table of t_account,
          w_account type t_account,
          i_txt50 type table t_txt50,
          w_txt50 type t_txt50.
    select SAKNR from SKAT into table i_account.
    if sy-subrc = 0.
    sort i_account by saknr.
    select saknr txt50 from SKAT into table i_txt50
    for all entries in i_account
    where SAKNR = i_account-SAKNR
    here mention al the primary keys and compare them with their constants.
    endif.     
    Note; here you need to take care that, you will have to fetch all the key fields in table i_txt50.
    and compare those fields with there constants which should be greater than initial values.
    they should be in proper sequence.
    now for writing.
    loop at i_account into w_account.
    clear w_txt50.
    sort i_txt50 by saknr.
    read table i_txt50 into w_txt50 with key SAKNR = w_account-saknr
    if sy-subrc = 0.
    write: w_txt50-saknr, w-txt50-txt50.
    clear w_txt50, w_account.
    endif.
    endloop.
    Hope it wil clear your doubts.
    Thanks
    Lalit

  • Select For all entries with multiple keys

    Dear Developers,
    im writing a program which reads the last the last mseg entry with bwart 101 and bwart 201 an writes it into different fields of a table. In dependance of the bwart the max-value of mkpf-budat should be moved into field wedat or wadat.
    At the moment i use this coding:
    loop at gt_daten assigning <fs_daten>.
        select distinct max( budat ) from wb2_v_mkpf_mseg2 into <fs_daten>-wedat
          where matnr_i = <fs_daten>-matnr
            and werks_i = <fs_daten>-werks
            and lgort_i = <fs_daten>-lgort
            and bwart_i = '101'.
        select distinct max( budat ) from wb2_v_mkpf_mseg2 into <fs_daten>-wadat
        where matnr_i = <fs_daten>-matnr
          and werks_i = <fs_daten>-werks
          and lgort_i = <fs_daten>-lgort
          and bwart_i = '201'.
      endloop.
    wb2_v_mkpf_mseg2 is a view combining mkpf an mseg by primary keys.
    Searching the internet i read, using FOR ALL ENTRIES should be prefered to selectstatements in loops.
    So i tried:
    *selectstatement
    select budat matnr_i werks_i lgort_i bwart_i from wb2_v_mkpf_mseg2 into table lt_mseg for all entries in gt_daten
        where matnr_i = gt_daten-matnr
          and werks_i = gt_daten-werks
          and lgort_i = gt_daten-lgort
          and ( bwart_i = '101' or bwart_i = '201' )
    *Substitute the MAX( )-Function
      sort lt_mseg descending by matnr werks lgort bwart budat.
      delete adjacent duplicates from lt_mseg comparing matnr werks lgort bwart.
    *Differ between wedat and wadat
      loop at gt_daten assigning <fs_daten>.
        loop at lt_mseg assigning <fs_mseg>
          where matnr = <fs_daten>-matnr
            and werks = <fs_daten>-werks
            and lgort = <fs_daten>-lgort.
          case <fs_mseg>-bwart.
            when '101'.
              <fs_daten>-wedat = <fs_mseg>-budat.
            when '201'.
              <fs_daten>-wadat = <fs_mseg>-budat.
          endcase.
        endloop.
    Even in the dev-system this takes twice the time of the "nested" selects.
    Imho this is because of the internal OR interpretation of the FOR ALL ENTRIES-statement and the size of the result.
    Can somebody give me a hint, how to tune this code?
    Select Inner join should be difficult because the target field differs, dependent of the value in bwart...
    Thanks in advance!

    I understand that you are trying to capture the maximum value of posting date MKPF-BUDAT for movement types 101 and 201 for each combination of material, plant and storage location.
    Few things, that makes the below coding more efficient at both application and database level and I confirmed this on an IDES sandbox
    1. Along with MKPF and MSEG, there is another table WBGT, in the view WB2_V_MKPF_MSEG join and also WBGT has select condition restrictions imposed on its fields. So if this restriction impacts your selection you may want to do a INNER JOIN of MSEG with MKPF only (with MSEG as leading table, as it has an active secondary index with MATNR, WERKS, LGORT and BWART ) and also there won't be overhead from the unnecessary join with WBGT table whose fields you are not using.
    2. The below SORT on lt_mseg will ensure that the record having greatest BUDAT will be at the top of all rows (least index) for each combination of MATNR, WERKS, LGORT and BWART.
    3. DELETE ADJACENT DUPLICATES will ensure that only the top row (having greatest BUDAT) remains in the table lt_mseg for each combination of MATNR, WERKS, LGORT and BWART. This will ensure that subsequent READs with BINARY SEARCH will always and efficiently read the row with maximum value of BUDAT for each unique combination of MATNR, WERKS, LGORT and BWART.
    4. The below logic will require more memory (even though it is more efficient performance wise) compared to direct SELECT with MAX for each MATNR, WERKS, LGORT and BWART in a LOOP the way you were doing before. So if the size of lt_mseg is causing memory issues, your logic with aggregate function MAX at database level will be your only option.
    So, I propose you revise your coding like below for most optimal results
    CHECK NOT gt_daten[] IS INITIAL.
    *selectstatement
    *SELECT budat matnr_i werks_i lgort_i bwart_i
    *  FROM wb2_v_mkpf_mseg2
    *  INTO TABLE lt_mseg
    *    FOR ALL ENTRIES IN gt_daten
    *    WHERE matnr_i = gt_daten-matnr
    *      AND werks_i = gt_daten-werks
    *      AND lgort_i = gt_daten-lgort
    *      AND ( bwart_i = '101' OR bwart_i = '201' ).
    * The below SELECT is more economical than the one commented above
    SELECT mkpf~budat mseg~matnr mseg~werks mseg~lgort mseg~bwart
      FROM mseg INNER JOIN mkpf
        ON mseg~mblnr = mkpf~mblnr AND
           mseg~mjahr = mkpf~mjahr
        INTO TABLE lt_mseg
          FOR ALL ENTRIES IN gt_daten
            WHERE mseg~matnr = gt_daten-matnr
              AND mseg~werks = gt_daten-werks
              AND mseg~lgort = gt_daten-lgort
              AND ( mseg~bwart = '101' OR mseg~bwart = '201' ).
    *Substitute the MAX( )-Function
    SORT lt_mseg BY matnr werks lgort bwart DESCENDING budat.
    DELETE ADJACENT DUPLICATES FROM lt_mseg COMPARING matnr werks lgort bwart.
    *Differ between wedat and wadat
    LOOP AT gt_daten ASSIGNING <fs_daten>.
      READ TABLE lt_mseg ASSIGNING <fs_mseg>
        WITH KEY matnr = <fs_daten>-matnr
                 werks = <fs_daten>-werks
                 lgort = <fs_daten>-lgort
                 bwart = '101' BINARY SEARCH.
      IF sy-subrc = 0.
        <fs_daten>-wedat = <fs_mseg>-budat.
      ENDIF.
      READ TABLE lt_mseg ASSIGNING <fs_mseg>
        WITH KEY matnr = <fs_daten>-matnr
                 werks = <fs_daten>-werks
                 lgort = <fs_daten>-lgort
                 bwart = '201' BINARY SEARCH.
      IF sy-subrc = 0.
        <fs_daten>-wadat = <fs_mseg>-budat.
      ENDIF.
    ENDLOOP.

  • Select for all entries+offset

    Folks,
    please find my code below:
    SELECT partner bpkind FROM but000 INTO TABLE i_but000
        FOR ALL ENTRIES IN lt_cmst_rtcm_bw
        WHERE partner = lt_cmst_rtcm_bw-tk_partner_i+0(10).
        SORT i_but000 BY partner.
    partner is of length 10, tk_partner_i is of length 32.
    when i use this offset value for comparison, its giving me the correct output. no errors.
    but am getting this warning:
    Bei der Verwendung von FOR ALL ENTRIES wird die Längenangabe für "TK_PARTNER_I" in dieser Bedingung ignoriert.          
    Do i have to mind this warning??..
    if this is to be considered, please suggest me an alternate solution to use "For all entries" in this case.
    Thanks in advance..
    Yog

    >
    yogaprakash srirangan wrote:
    > Hi,
    >
    > Actually i am writing this code in CRM system's CMOD-User exit program.
    >
    > when i remove the offset i am getting this error:
    >
    > When using the addition "FOR ALL ENTRIES IN itab", the fields "PARTNER"     and "LT_CMST_RTCM_BW-TK_PARTNER_I" must have the same type and length.and length.     
    >
    > but with offset its generating warning and internal table is getting filled..
    >
    > so can you please explain me on this?..
    >
    > Thanks,
    > Yog
    Wow!  It seems you have indeed found a bug!  With the length specification you get a warning, without you get an error!
    I've also written a little test program
    TYPES: BEGIN OF mandt_ty,
             mandt TYPE char6,
           END OF mandt_ty.
    DATA: t_mandt TYPE STANDARD TABLE OF mandt_ty WITH NON-UNIQUE KEY mandt,
          l_mandt TYPE mandt_ty.
    DATA: lt_t000 TYPE STANDARD TABLE OF t000 WITH NON-UNIQUE KEY mandt,
          ls_t000 TYPE t000.
    l_mandt-mandt = '1201'.
    INSERT l_mandt INTO TABLE t_mandt.
    SELECT * FROM t000 INTO TABLE lt_t000 FOR ALL ENTRIES IN t_mandt WHERE mandt = t_mandt-mandt+1(3).
    *SELECT * FROM t000 INTO TABLE lt_t000 FOR ALL ENTRIES IN t_mandt WHERE mandt = t_mandt-mandt.
    LOOP AT lt_t000 INTO ls_t000.
      WRITE: ls_t000-mandt.
    ENDLOOP.
    And it seems that the offset isn't being ignored.  I've also done and SQL trace, and this confirms that the offset isn't being ignored - the SQL issued actually says SELECT WHERE "MANDT" = '020' even though I've set it in the table to be 1201.
    So it seems that, at the moment, you can safely ignore the message.  But if SAP ever enforce it, or they make it an error instead of a warning, there will be problems.
    matt

Maybe you are looking for

  • Text disappearing in pdf file

    I received a word file that was converted to pdf using "pdf maker". In the word file there is "shading" behind the text. In the pdf file if I select portions of the text and try to "highlight" it to make comments, some of the text disappears. (The te

  • .class error in program

    I keep getting an error on the lines with factorial(term). Not sure if I am writing that part correctly. I am trying to write an expression representing sin and cosine using a while loop for sin and do-while for cos. I have my results set up to print

  • Gradient in file background

    In Photoshop CS6 (64 bit) when I open a new file, the background shows a gradient. No matter what I do or try, there is a gradient from top to bottom in the file. Eventhough I select to change to one even color. No matter what layer I place o top or

  • ERP Update Led to Security Issues

    Has anyone ever seen a situation where a resource pool update (e.g. specifying custom fields or rates) for enterprise resources led to those users losing permissions? We have AD groups setup for permissions too. Thanks, Roland

  • M93P and use of 2 HDD Controller | add additional SATA Controller

    Hello, Has anyone added a second HDD SATA controller to their ThnikCentre M93/p , my is a mini tower, to add SATA HDD ports to their setup. I have try to add a Marvell 88SE9230 based RAID HDD Controller as a second controller, but was not recognized.