Performance issue with select query and for all entries.

hi,
i have a report to be performance tuned.
the database table has around 20 million entries and 25 fields.
so, the report fetches the distinct values of two fields using one select query.
so, the first select query fetches around 150 entries from the table for 2 fields.
then it applies some logic and eliminates some entries and makes entries around 80-90...
and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
in short,
it accesses the same database table twice.
so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
is around 80-90 entries too much for using "for all entries"?
the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
i really cant find the way out...
please help.

chinmay kulkarni wrote:Chinmay,
Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
>
> so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
>
It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
> the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
>
That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database.

Similar Messages

  • Select query like For all Entries

    Hi,
    I have a requirement like:
    I need to extract data (BKTXT) from table BKPF based on some criteria, into one internal table and I need to query on REGUP table for the above data, the selection criteria on REGUP as follows:
    BKTXT(Document Header Text with 25 Char) is a combination of DATE and character string.
    Ex: bkpf-bktxt = 20060710-PL02 (YYYYMMDD)
    it is like LAUFD + LAUFI (of table REGUP)
    i.e: LAUFD (REGUP) = 07/10/2006 (MM/DD/YYYY) and LAUFI(REGUP) = PL02
    here I am thinking to use a select query on REGUP using FOR ALL ENTRIES of table i_bkpf..
    How can I change the date format YYYYMMDD to MM/DD/YYYY for my requirement?
    ((    Run-on Date (REGUP-LAUFD) = the first 8 characters in the Document Header Text (BKPF- BKTXT) in MM/DD/YYYY date format (e.g. 07/10/2006)
       Run ID (REGUP-LAUFI) = the 10th character through the 15th character in the Document Header Text (BKPF- BKTXT)

    It is not possible to do in the way you are thinking of doing. "For all entries" requires you to have the itab table field and the database table field to have the same type and length. So something like below <u>will not work</u>.
    TABLES: regup.
    DATA: BEGIN OF itab OCCURS 0,
            text LIKE bkpf-bktxt.
    DATA: END OF itab.
    DATA: BEGIN OF itab_regup OCCURS 0.
            INCLUDE STRUCTURE regup.
    DATA: END OF itab_regup.
    SELECT * INTO TABLE itab_regup
             FROM regup FOR ALL ENTRIES IN itab
            WHERE laufd = itab-text+0(8).
    If you run this code, you will get an error as follows:
    <i>"When using the addition "FOR ALL ENTRIES IN itab", the fields "LAUFD" and "ITAB-TEXT+0(8)" must have the same type and length."</i>

  • Performance issue with select query

    Hi friends ,
    This is my select query which is taking so much time to retrive the records.CAn Any one help me in solving this performance issue.
    *- Get the Goods receipts  mainly selected per period (=> MKPF secondary
      SELECT msegebeln msegebelp mseg~werks
             ekkobukrs ekkolifnr ekkozterm ekkoekorg ekko~ekgrp
             ekkoinco1 ekkoexnum
             lfa1name1 lfa1land1 lfa1ktokk lfa1stceg
             mkpfmblnr mkpfmjahr msegzeile mkpfbldat mkpf~budat
             mseg~bwart
    *Start of changes for CIP 6203752 by PGOX02
             mseg~smbln
    *End of changes for CIP 6203752 by PGOX02
             ekpomatnr ekpotxz01 ekpomenge ekpomeins
             ekbemenge ekbedmbtr ekbewrbtr ekbewaers
             ekpolgort ekpomatkl ekpowebaz ekpokonnr ekpo~ktpnr
             ekpoplifz ekpobstae
             INTO TABLE it_temp
        FROM mkpf JOIN mseg ON msegmblnr EQ mkpfmblnr
                           AND msegmjahr EQ mkpfmjahr
                  JOIN ekbe ON ekbeebeln EQ msegebeln
                           AND ekbeebelp EQ msegebelp
                           AND ekbe~zekkn EQ '00'
                           AND ekbe~vgabe EQ '1'
                           AND ekbegjahr EQ msegmjahr
                           AND ekbebelnr EQ msegmblnr
                           AND ekbebuzei EQ msegzeile
                  JOIN ekpo ON ekpoebeln EQ ekbeebeln
                           AND ekpoebelp EQ ekbeebelp
                  JOIN ekko ON ekkoebeln EQ ekpoebeln
                  JOIN lfa1 ON lfa1lifnr EQ ekkolifnr
        WHERE mkpf~budat IN so_budat
          AND mkpf~bldat IN so_bldat
          AND mkpf~vgart EQ 'WE'
          AND mseg~bwart IN so_bwart
          AND mseg~matnr IN so_matnr
          AND mseg~werks IN so_werks
          AND mseg~lifnr IN so_lifnr
          AND mseg~ebeln IN so_ebeln
          AND ekko~ekgrp IN so_ekgrp
          AND ekko~bukrs IN so_bukrs
          AND ekpo~matkl IN so_matkl
          AND ekko~bstyp IN so_bstyp
          AND ekpo~loekz EQ space
          AND ekpo~plifz IN so_plifz.
    Thanks & Regards,
    Manoj Kumar .Thatha
    Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting and please use code tags when posting code - post locked
    Edited by: Rob Burbank on Feb 4, 2010 9:03 AM

    Hi friends ,
    This is my select query which is taking so much time to retrive the records.CAn Any one help me in solving this performance issue.
    *- Get the Goods receipts  mainly selected per period (=> MKPF secondary
      SELECT msegebeln msegebelp mseg~werks
             ekkobukrs ekkolifnr ekkozterm ekkoekorg ekko~ekgrp
             ekkoinco1 ekkoexnum
             lfa1name1 lfa1land1 lfa1ktokk lfa1stceg
             mkpfmblnr mkpfmjahr msegzeile mkpfbldat mkpf~budat
             mseg~bwart
    *Start of changes for CIP 6203752 by PGOX02
             mseg~smbln
    *End of changes for CIP 6203752 by PGOX02
             ekpomatnr ekpotxz01 ekpomenge ekpomeins
             ekbemenge ekbedmbtr ekbewrbtr ekbewaers
             ekpolgort ekpomatkl ekpowebaz ekpokonnr ekpo~ktpnr
             ekpoplifz ekpobstae
             INTO TABLE it_temp
        FROM mkpf JOIN mseg ON msegmblnr EQ mkpfmblnr
                           AND msegmjahr EQ mkpfmjahr
                  JOIN ekbe ON ekbeebeln EQ msegebeln
                           AND ekbeebelp EQ msegebelp
                           AND ekbe~zekkn EQ '00'
                           AND ekbe~vgabe EQ '1'
                           AND ekbegjahr EQ msegmjahr
                           AND ekbebelnr EQ msegmblnr
                           AND ekbebuzei EQ msegzeile
                  JOIN ekpo ON ekpoebeln EQ ekbeebeln
                           AND ekpoebelp EQ ekbeebelp
                  JOIN ekko ON ekkoebeln EQ ekpoebeln
                  JOIN lfa1 ON lfa1lifnr EQ ekkolifnr
        WHERE mkpf~budat IN so_budat
          AND mkpf~bldat IN so_bldat
          AND mkpf~vgart EQ 'WE'
          AND mseg~bwart IN so_bwart
          AND mseg~matnr IN so_matnr
          AND mseg~werks IN so_werks
          AND mseg~lifnr IN so_lifnr
          AND mseg~ebeln IN so_ebeln
          AND ekko~ekgrp IN so_ekgrp
          AND ekko~bukrs IN so_bukrs
          AND ekpo~matkl IN so_matkl
          AND ekko~bstyp IN so_bstyp
          AND ekpo~loekz EQ space
          AND ekpo~plifz IN so_plifz.
    Thanks & Regards,
    Manoj Kumar .Thatha
    Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting and please use code tags when posting code - post locked
    Edited by: Rob Burbank on Feb 4, 2010 9:03 AM

  • Make this query into for all entries

    Hello Experts,
    please change this query into for all entries to increase performance
    loop at itab1.
        SELECT  single b~vtext INTO itab2
         FROM vbkd AS a
            INNER JOIN tvkggt AS b
            ON akdkg1 = bkdkgr
         WHERE a~vbeln EQ itab1-vbeln_vauf
         AND a~posnr EQ itab1-posnr_vauf.
    endloop.
    Thank you so much for all the replies.

    as I write again and again, then performance is mainly increased but correct index usage
    SELECT single b~vtext
    INTO itab2
    FROM vbkd AS a
    INNER JOIN tvkggt AS b
    ON   ..... spras ???
           bkdkgr  = akdkg1 
    WHERE a~vbeln EQ itab1-vbeln_vauf
    AND      a~posnr EQ itab1-posnr_vauf.
    You access vbkd with the primary key vbeln and posnr
    and then you switch to tvkggt where you need spras and kdgr for the primary key
    With spras you statement is incorrect you get one text it is unclear in which language,
    it might be that there is onyl one, but still you *** it to the statement to use the index.
    spras = sy-langu might be o.k.
    I.e.
    IF NOT ( itab1 is initial ).
       SELECT single b~vtext
           INTO itab2 
           FROM vbkd AS a
           INNER JOIN tvkggt AS b
           ON   b~spras = sy_langu
                  b~kdkgr  = a~kdkg1
           FOR ALL ENTRIES in itab1  
           WHERE a~vbeln EQ itab1-vbeln_vauf
           AND      a~posnr EQ itab1-posnr_vauf.
    ENDIF.
    Siegfried

  • Select ... for all entries problem

    Hi,
    I'm making select statements to BKPF and BSEG, but I can't do an inner join between this two table because BSEG it's a cluster table so I have to do a SELECT... FOR ALL ENTRIES, but in SE16 I make the same query that I have writen in my program as shown below,
    SELECT BUKRS BELNR GJAHR BUDAT MONAT
    FROM BKPF INTO CORRESPONDING FIELDS OF TABLE it_bkpf
    WHERE  BUKRS  = 'XXX'
    AND        GJAHR  = '2005'
    AND        BELNR  = '0000000250'. "just for proof
    AND        MONAT = '10'
    The above query returns me 1 row in program and in SE16 and then I make the next query for BSEG to do the join
    SELECT BUKRS BELNR GJAHR BSCHL SHKZG WRBTR HKONT
    FROM BSEG INTO CORRESPONDING FIELDS OF TABLE IT_BSEG
    FOR ALL ENTRIES IN it_bkpf
    WHERE bukrs = it_bkpf-bukrs
    and gjahr = it_bkpf-gjahr
    and belnr = it_bkpf-belnr.
    this query returns 897 rows and in SE16 this same query returns 901 rows
    Why SELECT...FOR ALL ENTRIES brings me less rows affected by the query in SE16
    Thanks for your help!!

    Hi,
      Please use the following code for selcting the exact number of rows.
    IF it_bkpf[] IS NOT INITIAL.
      SELECT *
      FROM BSEG INTO CORRESPONDING FIELDS OF   TABLE    IT_BSEG
    FOR ALL ENTRIES IN it_bkpf
    WHERE bukrs = it_bkpf-bukrs
    and gjahr = it_bkpf-gjahr
    and belnr = it_bkpf-belnr.
    ENDIF.
    Instead of * ,you can specify the exact fields required along with all the key fields as selection fields.Also it is must to check the condition it_bkpf[] IS NOT INITIAL before using the statement FOR ALL ENTRIES IN it_bkpf.Suppose if this condition is not used and if it_bkpf is initial,it will fetch all entries from the table.
    Reward if helpful.
    Regards,
    Aravind

  • Issue with Select Query in the Delivery userexit USEREXIT_SAVE_DOCUMENT

    Hi All,
    I am facing a strang issue with delivery userexit
    1) I have a delivery user exit MV50AFZ1 - USEREXIT_SAVE_DOCUMENT.
    2) In this user exit. I have written a select query as shown below
    *Get the already delivered data
        SELECT vbeln
               vgbel
               vgpos
               erdat
               erzet
               lfimg
          FROM lips
          INTO TABLE t_lips
           FOR ALL ENTRIES IN t_xlips_reference
         WHERE vgbel EQ t_xlips_reference-vgbel
           AND vgpos EQ t_xlips_reference-vgpos.
        IF sy-subrc EQ 0.
        ENDIF.
    3) The use of the above select query is to find out if there is any delivery that has already been created for the reference slaes order for which the current delivery is being created.
    4) The issue here is that for the FIRST DELIVERY, this select query should fail becuase there is no delivery created earlier and LIPS table would not have data. But, I am seeing some data getting populated in the internal table. The data that I am seeing in the internal table is the data of XLIPS which is nothing but the one that is about to get saved in the database after finishing this userexit.
    5) STRANGE Point is that this is working fine in case if I create delivery using the transaction VL01N. But, if I create delivery using VL10A program I am facing this issue.
    << Removed >>
    Thanks,
    Babu Kilari
    Edited by: Rob Burbank on Jun 16, 2010 4:22 PM

    Then why don't you add
    AND vbeln NE likp-vbeln

  • Performance issue in select query

    Moderator message: do not post the same question in two forums.  Duplicate (together with answers) deleted.
    SELECT a~grant_nbr
            a~zzdonorfy
            a~company_code
            b~language
          b~short_desc
    INTO TABLE i_gmgr_text
    FROM gmgr AS a
    INNER JOIN gmgrtexts AS b ON a~grant_nbr = b~grant_nbr
    WHERE a~grant_nbr  IN s_grant
    AND   a~zzdonorfy  IN s_dono
    AND   b~language   EQ sy-langu
    AND   b~short_desc IN s_cont.
    How to use for all all entries in the above inner join for better performance?
    then....
      IF sy-subrc EQ 0.
        SORT i_gmgr_text BY grant_nbr.
      ENDIF.
      IF i_gmgr_text[] IS NOT INITIAL.
    * Actual Line Item Table
        SELECT rgrant_nbr
               gl_sirid
               rbukrs
               rsponsored_class
               refdocnr
               refdocln
        FROM gmia
        INTO TABLE i_gmia
        FOR ALL ENTRIES IN i_gmgr_text
        WHERE rgrant_nbr        = i_gmgr_text-grant_nbr
        AND   rbukrs            = i_gmgr_text-company_code
        AND   rsponsored_class IN s_spon.
        IF sy-subrc EQ 0.
          SORT i_gmia BY refdocnr refdocln.
        ENDIF.
    Edited by: Matt on Dec 17, 2008 1:40 PM

    > How to use for all all entries in the above inner join for better performance?
    my best christmas recommendation for performance, simply ignore such recommendations.
    And check the performance of your join!
    Is the performance really low, if it is then there is probably no index support. Without indexes FOR ALL ENTRIES will be much slower.
    Siegfried

  • Select fom table for all entries where field starts with value

    Hello
    I want to write a select like this
    select * from bsis
    into lt_bsis
    for all entries in lt_itab
    where xblnr like lt_itab-belnr%
    I want to select all the entries from bsis where the field xblnr starts with the values found in lt_itab-belnr.
    for example
    ls_itab-belnr = 5100000028
    bsis-xblnr = 510000002810001
                        510000002810002
                        510000002810003
                        520000002810001
    and i want to select only the entries that start with 5100000028 in this case
    Can anybody help?
    Thanks

    Hi,
    I hope below example code will help you to fix your issue,
    REPORT  ytest.
    TYPES : BEGIN OF ty_typ1,
              val TYPE i,
            END OF ty_typ1.
    TYPES : BEGIN OF ty_typ2,
              val1 TYPE hrobjid,
              val2 TYPE hrobjid,
            END OF ty_typ2.
    DATA : int_typ1 TYPE TABLE OF ty_typ1,
           int_typ2 TYPE TABLE OF ty_typ2,
           wa_typ1  TYPE ty_typ1,
           wa_typ2  TYPE ty_typ2,
           int_1001 TYPE TABLE OF hrp1001,
           wa_1001  TYPE hrp1001.
    REFRESH : int_typ1, int_typ2, int_1001.
    CLEAR : wa_typ1, wa_typ2, wa_1001.
    wa_typ1-val = 500001.
    APPEND wa_typ1 TO int_typ1.
    wa_typ1-val = 500002.
    APPEND wa_typ1 TO int_typ1.
    wa_typ1-val = 500003.
    APPEND wa_typ1 TO int_typ1.
    wa_typ1-val = 500001.
    APPEND wa_typ1 TO int_typ1.
    SORT int_typ1 ASCENDING BY val.
    DELETE ADJACENT DUPLICATES FROM int_typ1 COMPARING val.
    LOOP AT int_typ1 INTO wa_typ1.
      wa_typ2-val1 = ( wa_typ1-val * 100 ) + 1.
      wa_typ2-val2 = wa_typ2-val1 + 98.
      APPEND wa_typ2 TO int_typ2.
      CLEAR : wa_typ1, wa_typ2.
    ENDLOOP.
    SELECT * FROM hrp1001 INTO TABLE int_1001
             FOR ALL ENTRIES IN int_typ2 WHERE
                 plvar EQ '01'          AND
                 otype EQ 'S'           AND
                 sclas EQ 'O'           AND
                 begda LE sy-datum      AND
                 endda GE sy-datum      AND
                 objid GE int_typ2-val1 AND
                 objid LE int_typ2-val2.
    LOOP AT int_1001 INTO wa_1001.
      WRITE : / wa_1001-objid.
    ENDLOOP.
    Thanks & Regards,
    Harish Kumar N

  • Performance issue on select query

    hi,
    Can any explain how the system behaves for the below 2 scenarios and which is much better?
    In table EABLG i have around 1 billion records (FYI)
    1)
        SELECT
              ablbelnr
              anlage
              ablesgr  
          FROM eablg
          INTO TABLE it_eablg
          FOR ALL ENTRIES IN it_eanl
          WHERE ( anlage = it_eanl-anlage
            AND  ablesgr = '01'           
            AND adatsoll GT  '20080706' )        " last 3 months
          OR    ( anlage = it_eanl-anlage
            AND  ablesgr = '06'
            AND adatsoll GT  '20080706' )       " last 3 months
    2)
    SELECT
              ablbelnr
              anlage
              ablesgr  
        FROM eablg
        INTO TABLE it_eablg
        FOR ALL ENTRIES IN it_eanl
        WHERE  anlage = it_eanl-anlage
        AND  (  ablesgr = '01'           
           OR     ablesgr = '06')         
       AND adatsoll GT '20080706'    .  " last 3 months
    thanks in advance.
    with regards
    sumanth

    The statement has to be in a special format, so it might make sense run a trace in DEV, check the "Explain" there and download/upload the statement to QA (also via ST05). I have not tried this myself yet, so I would be interested if it works
    Here is two resources for you, SAP online help and a good blog by Siegfried Boes:
    http://help.sap.com/saphelp_erp60_sp/helpdata/EN/d1/801f7c454211d189710000e8322d00/frameset.htm
    The SQL Trace (ST05) – Quick and Easy
    It's a very powerful analysis tool, so it's worth the time to work yourself into it.
    But again, you actually want good test data in DEV for this matter.
    Thomas

  • Performance Issue With Displaying Candidate Details for iRecruitment

    We are in EBS R12.1.3 when we trying to display the Candidate Details page in iRecruitment iRecruitment >vacancies>applicants> click on applicant>   the page spins for  a quite whille to show the results and some times we see the 500 errors..
    We are in R12.1.3 and also applied the  Patch.10427777:R12.IRC.B patch.. is there any  tunnign steps for the iRecruitment  page=/oracle/apps/irc/candidateSearch/webui/CmAplSrchPG

    You have already applied the patch mention in note: Performance Issue With Displaying Candidate Details Page in 12.1.3 (Doc ID 1293164.1)
    check this note also Performance Issue when Clicking on Candidate Name (Doc ID 1575164.1)
    thanks

  • Select SUM in FOR ALL ENTRIES Select Query

    Hi ,
            I am using for all entries select statment ,can any one guide me how can i use SUM in the select statment with for all entries .
    Regards,
    Veera

    Hi,
    THis is  not possible using for all entries.
    Thanks,
    Sriram Ponna.

  • Performance issue with selection of line items.

    Hi All.
    I am facing seriour Time_Out error problem for my program. Actually i am developing RFC and i have to send data to non sap system as it is in sap tables. Now i have to send data for BSIS for new entries for a day. SO first i search BELNR for CPUDT in BKPF and then use for all entries on BSIS. But now my problem is for a single day i am getting 1679 documents from BKPF and when i use for all entries in BSIS, it will give time out error.
    my code is like
    SELECT BUKRS BELNR GJAHR
       FROM BKPF INTO CORRESPONDING FIELDS OF TABLE I_BKPF
          WHERE CPUDT IN S_CPUDT.
    if i_bkpf[] is not initial.
    SELECT * FROM BSIS INTO TABLE I_BSIS
       FOR ALL ENTRIES IN I_BKPF
          WHERE BUKRS = I_BKPF-BUKRS
                       BELNR = I_BKPF-BELNR
                       GJAHR = I_BKPF-GJAHR.
    endif.
    So please gurus help me ..its urgent..

    Instead of writing Select * write Select "Fields names" then try might be it will solve ur problem.
    Reward points is helpfull

  • Facin problems in the 'Select... for all entries'

    I am facing problem with this piece of code, please share ur thoughts on it. I have specified the inputs.
    I am extracting the open items from the BSIS table for specified 3 account number.
    Inputs to the prg:
    field     No. of values
    r_bukrs       1
    r_hkont      2
    r_blart     6
    r_budat  date range of 1 yr
    r_bldat  nil
    v_tosdef contain 1 account number
    " In each FI document posted, one line will have the 'v_tosdef' account number and one account from the 'r_hkont' values."
    So will this query efficient.
      SELECT bukrs
             hkont
             gjahr
             belnr
             budat
             bldat
             xblnr
             blart
             shkzg
             dmbtr
        FROM bsis
        INTO TABLE i_bsis
       WHERE bukrs IN r_bukrs                    " Company code
         AND hkont =  v_tosdef                  " Account number
         AND budat IN r_budat                    " Posting date
         AND bldat IN r_bldat                    " Document date
         AND blart IN r_blart.                   " Document type
      IF sy-subrc <> 0.
        MESSAGE i003.
        STOP.
      ENDIF.
    *@ Collecting the BELNR & GJAHR From the extracted records
      li_bsis[] = i_bsis[].
      SORT li_bsis BY bukrs gjahr belnr.
      DELETE ADJACENT
      DUPLICATES FROM li_bsis
            COMPARING bukrs gjahr belnr.
      IF NOT li_bsis[] IS INITIAL.
        SELECT bukrs
               hkont
               gjahr
               belnr
               budat
               bldat
               xblnr
               blart
               shkzg
               dmbtr
          FROM bsis
    APPENDING TABLE i_bsis
           FOR ALL ENTRIES IN li_bsis
         WHERE bukrs = li_bsis-bukrs               " Company code
           AND hkont IN r_hkont                    " Account number
           AND gjahr =  li_bsis-gjahr              " Fiscal year
           AND belnr =  li_bsis-belnr.             " Document num
    BSIS table size around 86GB
    primary index size aroung 33GB
    and the index quality is 54%
    the CBO shows less cost, but the actual runs takes too much disk read's / bgets..
    Message was edited by:
            Sandy

    Hi Sandy,
    You indicated the size of the tables and index, what is the total number of records in your BSIS?
    In your range tables, make sure they are postive formed.
    Ex. r_bukrs :  I EQ '1001', and not I NE '1000'.
    You should consider coding your statements to check for input for bldat, code it with r_bldat and then another set without. It should be better performance to not have empty where conditions. So two routines, Selects with bldat and without.
    Don't know if you have a Basis person to help analyze the performance, but you should look at the indexes in BSIS. You may have several indexes that contain some of your input fields but they may be spread across several indexes or there may be none. But say you have 5 indexes and it happens that just one of your parameters are in each of those indexes. Well, it can only use one index so while you think you are providing alot of parameters to help performance only one field is being used to access the index. What you need to do then is to find an index that has the most fields in your where clause and see if you can add to that, so long it's not an SAP index. If it's a z index consider adding additional fields to it, or consider creating a new index.
    You can at least analyze the first Select in your DEV client. Run a trace, ST05 and then execute your code. It will show you which index it has used if any.
    Also, look at the query values it is passing to the database. You said you get 6 M records on the first Select. This just seem like a lot of records, which is for just one account number (v_tosdef) along with the other parameters. I'm wondering if there's a problem with your input data. With 6M in your first table, your FOR ALL ENTRIES statement will be executed 1.2 million times. Tyically the database interface breaks down your Select-For All entries statement into 5 records per query. Again, run ST05 and you will see this.
    In SE16, on your BSIS table, what is your count of records if you enter only the account number?
    As a test, you might want to try entering all your parameters in SE16, run ST05 to trace the SQL to see what it is doing. You may have to kill your SE16 session or it may time out on you. You can stop your ST05 trace before your SE16 finishes and it will still show how SAP is going after the data and what index it used.
    Let me know if this helped any.
    Regards,
    Filler

  • Advice required on a select statement using "FOR ALL ENTRIES"

    Hi,
    this is really intresting ...
    I have a small requirement where in i have to find out
    the valid entries in my internal table (T_MATNR) by using a select statement to a check table (MARA) which has all the fields present in the internal table T_MATNR.
    Select statement is
    SELECT MATNR
           MTART
           from MARA
           for all entries in T_MATNR
           into table T_MATNR
           where matnr eq T_MATNR-MATNR.
    If you observe the itab in the option 'FOR ALL ENTRIES' and the destination table is the same. I want to know whether this is correct? will it cause any performance issue? right now this statement is working fine for me.

    Hi,
    U have to use
    SELECT MATNR
    MTART
    from MARA
    <b>into table I_MATNR(different table)</b>
    for all entries in T_MATNR
    where matnr eq T_MATNR-MATNR.
    If u r specifying both same table name then for what entries it will retrieve, if u have alreay selected some entries and appending u can use
    SELECT MATNR
    MTART
    from MARA
    <b>into table T_MATNR</b>where matnr eq T_MATNR-MATNR.
    then
    SELECT MATNR
    MTART
    from MARA
    <b>appending table T_MATNR</b>
    for all entries in T_MATNR
    where matnr eq T_MATNR-MATNR.
    In this way u can do.
    Hope u got it.

  • Using delete and FOR ALL ENTRIES

    Hi,
    We have a error message regarding the following code :
    Delete FROM TABLE FOR ALL ENTRIES IN lt_TABLE WHERE
    TABLE_KEY1  = LT_TABLE_KEY1
    Could we use the For All entries with "Select" ?
    For information, the error message is "Unable to interpret "FOR". Possible causes: Incorrect spelling or comma error.
    Thank you.

    Hi,
    Check the below syntax, if you want to delete from database
    DELETE FROM sflight
    WHERE  carrid = p_carrid AND
           fldate = sy-datum AND
           seatsocc = 0.
    Just a suggestion. May be from next time you can use F1 help for syntax:
    1. Place the cursor on the delete keword in your program and press F1 - You willl get all the possible syntax for delete statement
    2. Else open the transaction ABAPDOCU, Click Keyword Help, Enter the required keyword(delete in this case) and press cont.. You will get the syntax.
    Hope thsi will help you.
    Regards,
    Swarna Munukoti.

Maybe you are looking for