Poor performance due to select query

Hey ppl,
I am facing a problem in one of the select query on BSEG.
The query is as given
TYPES :BEGIN OF wa1_bseg,
        bukrs    TYPE bseg-bukrs,
        belnr     TYPE bseg-belnr,     
        gjahr         TYPE bseg-gjahr,
        buzei    TYPE bseg-buzei,
        fwbas    TYPE bseg-fwbas ,     
        pswbt    TYPE bseg-pswbt,
        hkont    TYPE bseg-hkont,
        wrbtr     TYPE bseg-wrbtr,
        ktosl     TYPE bseg-ktosl,
        koart     TYPE bseg-koart,
        shkzg    TYPE bseg-shkzg,
        mwskz   TYPE bseg-mwskz,
        qsskz    TYPE bsis-qsskz,
        dmbtr     TYPE bseg-dmbtr,
        flag        TYPE C,
        END OF wa1_bseg.
DATA: it_bsegv TYPE TABLE OF wa1_bseg WITH HEADER LINE.
SELECT bukrs belnr gjahr buzei fwbas pswbt hkont wrbtr  ktosl shkzg koart mwskz
FROM bseg INTO TABLE it_bsegv
FOR ALL ENTRIES IN it_ekko
   WHERE bukrs = 'MU51'     AND
                gjahr IN s_fiscal    AND
                valut IN s_budat1  AND
                ebeln = it_ekko-ebeln.
Even if there are only around 5 records in it_ekko it takes very long time in executing. Sumtimes it even shows 'time out' in
foreground.   Kindly help me out with it

Hi,
Go through this link it will helpful,
Re: Performance Issue with BKPF, BSEG, BSET
Re: Reading BSEG: performance problems
/people/rob.burbank/blog/2007/11/12/quickly-retrieving-fi-document-data-from-bseg
Regards
Adil
Edited by: Syed  Abdul Adil on Jun 17, 2008 12:33 PM

Similar Messages

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

  • Performance Problem in Select query

    Hi,
    I have performance Problem in following Select Query :
    SELECT VBELN POSNR LFIMG VRKME VGBEL VGPOS
      FROM LIPS INTO CORRESPONDING FIELDS OF TABLE GT_LIPS
       FOR ALL ENTRIES IN GT_EKPO1
       WHERE VGBEL = GT_EKPO1-EBELN
         AND VGPOS = GT_EKPO1-EBELP.
    as per trace i have analysed that it is fetch the complete table scan from the LIPS table and table contants almost 3 lakh records.
    Kindly Suggest what we can do to optimize this query.
    Regards,
    Harsh

    types: begin of line,
              vbeln type lips-vbeln
              posnr type lips-posnr
              lfimg type lips-lfimg
             vrkme type lips-vrkme
             vgbel type lips- vgbel
             vgpos type lips-vgpos
             end of line.
    data: itab type standard table of line,
             wa type line.
    IF GT_EKPO1[] IS NOT INITIAL.
    SELECT VBELN POSNR LFIMG VRKME VGBEL VGPOS
    FROM LIPS INTO  TABLE ITAB
    FOR ALL ENTRIES IN GT_EKPO1
    WHERE VGBEL = GT_EKPO1-EBELN
    AND VGPOS = GT_EKPO1-EBELP.
    ENDIF.

  • Needed help to improve the performance of a select query?

    Hi,
    I have been preparing a report which involves data to be fetched from 4 to 5 different tables and calculation has to performed on some columns also,
    i planned to write a single cursor to populate 1 temp table.i have used INLINE VIEW,EXISTS more frequently in the select query..please go through the query and suggest me a better way to restructure the query.
    cursor c_acc_pickup_incr(p_branch_code varchar2, p_applDate date, p_st_dt date, p_ed_dt date) is
    select sca.branch_code "BRANCH",
    sca.cust_ac_no "ACCOUNT",
    to_char(p_applDate, 'YYYYMM') "YEARMONTH",
    sca.ccy "CURRENCY",
    sca.account_class "PRODUCT",
    sca.cust_no "CUSTOMER",
    sca.ac_desc "DESCRIPTION",
    null "LOW_BAL",
    null "HIGH_BAL",
    null "AVG_CR_BAL",
    null "AVG_DR_BAL",
    null "CR_DAYS",
    null "DR_DAYS",
    --null                                 "CR_TURNOVER",       
    --null                                 "DR_TURNOVER",       
    null "DR_OD_DAYS",
    (select sum(gf.limit_amount * (scal.linkage_percentage / 100)) +
    (case when (p_applDate >= sca.tod_limit_start_date and
    p_applDate <= nvl(sca.tod_limit_end_date, p_applDate)) then
    sca.tod_limit else 0 end) dd
    from getm_facility gf, sttm_cust_account_linkages scal
    where gf.line_code || gf.line_serial = scal.linked_ref_no
    and cust_ac_no = sca.cust_ac_no) "OD_LIMIT",
    --sc.credit_rating                      "CR_GRADE",        
    null "AVG_NET_BAL",
    null "UNAUTH_OD_AMT",
    sca.acy_blocked_amount "AMT_BLOCKED",
    (select sum(amt)
    from ictb_entries_history ieh
    where ieh.acc = sca.cust_ac_no
    and ieh.brn = sca.branch_code
    and ieh.drcr = 'D'
    and ieh.liqn = 'Y'
    and ieh.entry_passed = 'Y'
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select * from ictm_pr_int ipi, ictm_rule_frm irf
    where ipi.product_code = ieh.prod
    and ipi.rule = irf.rule_id
    and irf.book_flag = 'B')) "DR_INTEREST",
    (select sum(amt)
    from ictb_entries_history ieh
    where ieh.acc = sca.cust_ac_no
    and ieh.brn = sca.branch_code
    and ieh.drcr = 'C'
    and ieh.liqn = 'Y'
    and ieh.entry_passed = 'Y'
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select * from ictm_pr_int ipi, ictm_rule_frm irf
    where ipi.product_code = ieh.prod
    and ipi.rule = irf.rule_id
    and irf.book_flag = 'B')) "CR_INTEREST",
    (select sum(amt) from ictb_entries_history ieh
    where ieh.brn = sca.branch_code
    and ieh.acc = sca.cust_ac_no
    and ieh.ent_dt between p_st_dt and p_ed_dt
    and exists (
    select product_code
    from ictm_product_definition ipd
    where ipd.product_code = ieh.prod
    and ipd.product_type = 'C')) "FEE_INCOME",
    sca.record_stat "ACC_STATUS",
    case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
    and not exists (select 1
    from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null))
    then 1 else 0 end "NEW_ACC_FOR_THE_MONTH",
    case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
    and trunc(sc.cif_creation_date,'MM') = trunc(p_applDate,'MM')
    and not exists (select 1
    from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null))
    then 1 else 0 end "NEW_ACC_FOR_NEW_CUST",
    (select 1 from dual
    where exists (select 1 from ictm_td_closure_renew itcr
    where itcr.brn = sca.branch_code
    and itcr.acc = sca.cust_ac_no
    and itcr.renewal_date = sysdate)
    or exists (select 1 from ictm_tdpayin_details itd
    where itd.multimode_payopt = 'Y'
    and itd.brn = sca.branch_code
    and itd.acc = sca.cust_ac_no
    and itd.multimode_offset_brn is not null
    and itd.multimode_tdoffset_acc is not null)) "RENEWED_OR_ROLLOVER",
    (select maturity_date from ictm_acc ia
    where ia.brn = sca.branch_code
    and ia.acc = sca.cust_ac_no) "MATURITY_DATE",
    sca.ac_stat_no_dr "DR_DISALLOWED",
    sca.ac_stat_no_cr "CR_DISALLOWED",
    sca.ac_stat_block                     "BLOCKED_ACC",       Not Reqd
    sca.ac_stat_dormant "DORMANT_ACC",
    sca.ac_stat_stop_pay "STOP_PAY_ACC", --New
    sca.ac_stat_frozen "FROZEN_ACC",
    sca.ac_open_date "ACC_OPENING_DT",
    sca.address1 "ADD_LINE_1",
    sca.address2 "ADD_LINE_2",
    sca.address3 "ADD_LINE_3",
    sca.address4 "ADD_LINE_4",
    sca.joint_ac_indicator "JOINT_ACC",
    sca.acy_avl_bal "CR_BAL",
    0 "DR_BAL",
    0 "CR_BAL_LCY", t
    0 "DR_BAL_LCY",
    null "YTD_CR_MOVEMENT",
    null "YTD_DR_MOVEMENT",
    null "YTD_CR_MOVEMENT_LCY",
    null "YTD_DR_MOVEMENT_LCY",
    null "MTD_CR_MOVEMENT",
    null "MTD_DR_MOVEMENT",
    null "MTD_CR_MOVEMENT_LCY",
    null "MTD_DR_MOVEMENT_LCY",
    'N' "BRANCH_TRFR", --New
    sca.provision_amount "PROVISION_AMT",
    sca.account_type "ACCOUNT_TYPE",
    nvl(sca.tod_limit, 0) "TOD_LIMIT",
    nvl(sca.sublimit, 0) "SUB_LIMIT",
    nvl(sca.tod_limit_start_date, global.min_date) "TOD_START_DATE",
    nvl(sca.tod_limit_end_date, global.max_date) "TOD_END_DATE"
    from sttm_cust_account sca, sttm_customer sc
    where sca.branch_code = p_branch_code
    and sca.cust_no = sc.customer_no
    and ( exists (select 1 from actb_daily_log adl
    where adl.ac_no = sca.cust_ac_no
    and adl.ac_branch = sca.branch_code
    and adl.trn_dt = p_applDate
    and adl.auth_stat = 'A')
    or exists (select 1 from catm_amount_blocks cab
    where cab.account = sca.cust_ac_no
    and cab.branch = sca.branch_code
    and cab.effective_date = p_applDate
    and cab.auth_stat = 'A')
    or exists (select 1 from ictm_td_closure_renew itcr
    where itcr.acc = sca.cust_ac_no
    and itcr.brn = sca.branch_code
    and itcr.renewal_date = p_applDate)
    or exists (select 1 from sttm_ac_stat_change sasc
    where sasc.cust_ac_no = sca.cust_ac_no
    and sasc.branch_code = sca.branch_code
    and sasc.status_change_date = p_applDate
    and sasc.auth_stat = 'A')
    or exists (select 1 from cstb_acc_brn_trfr_log cabtl
    where cabtl.branch_code = sca.branch_code
    and cabtl.cust_ac_no = sca.cust_ac_no
    and cabtl.process_status = 'S'
    and cabtl.process_date = p_applDate)
    or exists (select 1 from sttbs_provision_history sph
    where sph.branch_code = sca.branch_code
    and sph.cust_ac_no = sca.cust_ac_no
    and sph.esn_date = p_applDate)
    or exists (select 1 from sttms_cust_account_dormancy scad
    where scad.branch_code = sca.branch_code
    and scad.cust_ac_no = sca.cust_ac_no
    and scad.dormancy_start_dt = p_applDate)
    or sca.maker_dt_stamp = p_applDate
    or sca.status_since = p_applDate
    l_tb_acc_det ty_tb_acc_det_int;
    l_brnrec cvpks_utils.rec_brnlcy;
    l_acbr_lcy sttms_branch.branch_lcy%type;
    l_lcy_amount actbs_daily_log.lcy_amount%type;
    l_xrate number;
    l_dt_rec sttm_dates%rowtype;
    l_acc_rec sttm_cust_account%rowtype;
    l_acc_stat_row ty_r_acc_stat;
    Edited by: user13710379 on Jan 7, 2012 12:18 AM

    I see it more like shown below (possibly with no inline selects
    Try to get rid of the remaining inline selects ( left as an exercise ;) )
    and rewrite traditional joins as ansi joins as problems might arise using mixed syntax as I have to leave so I don't have time to complete the query
    select sca.branch_code "BRANCH",
           sca.cust_ac_no "ACCOUNT",
           to_char(p_applDate, 'YYYYMM') "YEARMONTH",
           sca.ccy "CURRENCY",
           sca.account_class "PRODUCT",
           sca.cust_no "CUSTOMER",
           sca.ac_desc "DESCRIPTION",
           null "LOW_BAL",
           null "HIGH_BAL",
           null "AVG_CR_BAL",
           null "AVG_DR_BAL",
           null "CR_DAYS",
           null "DR_DAYS",
    --     null "CR_TURNOVER",
    --     null "DR_TURNOVER",
           null "DR_OD_DAYS",
           w.dd "OD_LIMIT",
    --     sc.credit_rating "CR_GRADE",
           null "AVG_NET_BAL",
           null "UNAUTH_OD_AMT",
           sca.acy_blocked_amount "AMT_BLOCKED",
           x.dr_int "DR_INTEREST",
           x.cr_int "CR_INTEREST",
           y.fee_amt "FEE_INCOME",
           sca.record_stat "ACC_STATUS",
           case when trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
                 and not exists(select 1
                                  from ictm_tdpayin_details itd
                                 where itd.multimode_payopt = 'Y'
                                   and itd.brn = sca.branch_code
                                   and itd.acc = sca.cust_ac_no
                                   and itd.multimode_offset_brn is not null
                                   and itd.multimode_tdoffset_acc is not null
                then 1
                else 0
           end "NEW_ACC_FOR_THE_MONTH",
           case when (trunc(sca.ac_open_date,'MM') = trunc(p_applDate,'MM')
                 and trunc(sc.cif_creation_date,'MM') = trunc(p_applDate,'MM')
                 and not exists(select 1
                                  from ictm_tdpayin_details itd
                                 where itd.multimode_payopt = 'Y'
                                   and itd.brn = sca.branch_code
                                   and itd.acc = sca.cust_ac_no
                                   and itd.multimode_offset_brn is not null
                                   and itd.multimode_tdoffset_acc is not null
                then 1
                else 0
           end "NEW_ACC_FOR_NEW_CUST",
           (select 1 from dual
             where exists(select 1
                            from ictm_td_closure_renew itcr
                           where itcr.brn = sca.branch_code
                             and itcr.acc = sca.cust_ac_no
                             and itcr.renewal_date = sysdate
                or exists(select 1
                            from ictm_tdpayin_details itd
                           where itd.multimode_payopt = 'Y'
                             and itd.brn = sca.branch_code
                             and itd.acc = sca.cust_ac_no
                             and itd.multimode_offset_brn is not null
                             and itd.multimode_tdoffset_acc is not null
           ) "RENEWED_OR_ROLLOVER",
           m.maturity_date "MATURITY_DATE",
           sca.ac_stat_no_dr "DR_DISALLOWED",
           sca.ac_stat_no_cr "CR_DISALLOWED",
    --     sca.ac_stat_block "BLOCKED_ACC", --Not Reqd
           sca.ac_stat_dormant "DORMANT_ACC",
           sca.ac_stat_stop_pay "STOP_PAY_ACC", --New
           sca.ac_stat_frozen "FROZEN_ACC",
           sca.ac_open_date "ACC_OPENING_DT",
           sca.address1 "ADD_LINE_1",
           sca.address2 "ADD_LINE_2",
           sca.address3 "ADD_LINE_3",
           sca.address4 "ADD_LINE_4",
           sca.joint_ac_indicator "JOINT_ACC",
           sca.acy_avl_bal "CR_BAL",
           0 "DR_BAL",
           0 "CR_BAL_LCY", t
           0 "DR_BAL_LCY",
           null "YTD_CR_MOVEMENT",
           null "YTD_DR_MOVEMENT",
           null "YTD_CR_MOVEMENT_LCY",
           null "YTD_DR_MOVEMENT_LCY",
           null "MTD_CR_MOVEMENT",
           null "MTD_DR_MOVEMENT",
           null "MTD_CR_MOVEMENT_LCY",
           null "MTD_DR_MOVEMENT_LCY",
           'N' "BRANCH_TRFR", --New
           sca.provision_amount "PROVISION_AMT",
           sca.account_type "ACCOUNT_TYPE",
           nvl(sca.tod_limit, 0) "TOD_LIMIT",
           nvl(sca.sublimit, 0) "SUB_LIMIT",
           nvl(sca.tod_limit_start_date, global.min_date) "TOD_START_DATE",
           nvl(sca.tod_limit_end_date, global.max_date) "TOD_END_DATE"
      from sttm_cust_account sca,
           sttm_customer sc,
           (select sca.cust_ac_no
                   sum(gf.limit_amount * (scal.linkage_percentage / 100)) +
                       case when p_applDate >= sca.tod_limit_start_date
                             and p_applDate <= nvl(sca.tod_limit_end_date, p_applDate)
                            then sca.tod_limit else 0
                       end
                      ) dd
              from sttm_cust_account sca
                   getm_facility gf,
                   sttm_cust_account_linkages scal
             where gf.line_code || gf.line_serial = scal.linked_ref_no
               and cust_ac_no = sca.cust_ac_no
             group by sca.cust_ac_no
           ) w,
           (select acc,
                   brn,
                   sum(decode(drcr,'D',amt)) dr_int,
                   sum(decode(drcr,'C',amt)) cr_int
              from ictb_entries_history ieh
             where ent_dt between p_st_dt and p_ed_dt
               and drcr in ('C','D')
               and liqn = 'Y'
               and entry_passed = 'Y'
               and exists(select null
                            from ictm_pr_int ipi,
                                 ictm_rule_frm irf
                           where ipi.rule = irf.rule_id
                             and ipi.product_code = ieh.prod 
                             and irf.book_flag = 'B'
             group by acc,brn
           ) x,
           (select acc,
                   brn,
                   sum(amt) fee_amt
              from ictb_entries_history ieh
             where ieh.ent_dt between p_st_dt and p_ed_dt
               and exists(select product_code
                            from ictm_product_definition ipd
                           where ipd.product_code = ieh.prod
                             and ipd.product_type = 'C'
             group by acc,brn
           ) y,
           ictm_acc m,
           (select sca.cust_ac_no,
                   sca.branch_code
                   coalesce(nvl2(coalesce(t1.ac_no,t1.ac_branch),'exists',null),
                            nvl2(coalesce(t2.account,t2.account),'exists',null),
                            nvl2(coalesce(t3.acc,t3.brn),'exists',null),
                            nvl2(coalesce(t4.cust_ac_no,t4.branch_code),'exists',null),
                            nvl2(coalesce(t5.cust_ac_no,t5.branch_code),'exists',null),
                            nvl2(coalesce(t6.cust_ac_no,t6.branch_code),'exists',null),
                            nvl2(coalesce(t7.cust_ac_no,t7.branch_code),'exists',null),
                            decode(sca.maker_dt_stamp,p_applDate,'exists'),
                            decode(sca.status_since,p_applDate,'exists')
                           ) existence
              from sttm_cust_account sca
                   left outer join
                   (select ac_no,ac_branch
                      from actb_daily_log
                     where trn_dt = p_applDate
                       and auth_stat = 'A'
                   ) t1
                on (sca.cust_ac_no = t1.ac_no
               and  sca.branch_code = t1.ac_branch
                   left outer join
                   (select account,account
                      from catm_amount_blocks
                     where effective_date = p_applDate
                       and auth_stat = 'A'
                   ) t2
                on (sca.cust_ac_no = t2.account
               and  sca.branch_code = t2.branch
                   left outer join
                   (select acc,brn
                      from ictm_td_closure_renew itcr
                     where renewal_date = p_applDate
                   ) t3
                on (sca.cust_ac_no = t3.acc
               and  sca.branch_code = t3.brn
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttm_ac_stat_change
                     where status_change_date = p_applDate
                       and auth_stat = 'A'
                   ) t4
                on (sca.cust_ac_no = t4.cust_ac_no
               and  sca.branch_code = t4.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from cstb_acc_brn_trfr_log
                     where process_date = p_applDate
                       and process_status = 'S'
                   ) t5
                on (sca.cust_ac_no = t5.cust_ac_no
               and  sca.branch_code = t5.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttbs_provision_history
                     where esn_date = p_applDate
                   ) t6
                on (sca.cust_ac_no = t6.cust_ac_no
               and  sca.branch_code = t6.branch_code
                   left outer join
                   (select cust_ac_no,branch_code
                      from sttms_cust_account_dormancy
                     where dormancy_start_dt = p_applDate
                   ) t7
                on (sca.cust_ac_no = t7.cust_ac_no
               and  sca.branch_code = t7.branch_code
           ) z
    where sca.branch_code = p_branch_code
       and sca.cust_no = sc.customer_no
       and sca.cust_ac_no = w.cust_ac_no
       and sca.cust_ac_no = x.acc
       and sca.branch_code = x.brn
       and sca.cust_ac_no = y.acc
       and sca.branch_code = y.brn
       and sca.cust_ac_no = m.acc
       and sca.branch_code = m.brn
       and sca.cust_ac_no = z.sca.cust_ac_no
       and sca.branch_code = z.branch_code
       and z.existence is not nullRegards
    Etbin

  • Need pointers to improve performance of a select query to table vbrk

    Hey Folks,
    I have a query , whose performance needs to be tuned , as such:
        SELECT a~vbeln
               a~fkart                    
               a~waerk
               a~fkdat                   
               b~posnr
               b~vgbel
               b~vgpos
               b~matnr
               b~arktx
               b~prctr
               b~txjcd
          INTO TABLE gi_billing_items
          FROM vbrk AS a
          INNER JOIN vbrp AS b
          ON a~vbeln = b~vbeln
          FOR ALL ENTRIES IN gi_sales_items
         WHERE b~vgbel = gi_sales_items-vbeln
           AND b~vgpos  = gi_sales_items-posnr
           AND b~matnr  = gi_sales_items-matnr
           AND b~werks  = gi_sales_items-werks.
    where
    gi_sales_items is an internal table consisting of 278 entries,.
    The result set collected in table gi_billing_items is 200 records
    The total execution time for this query for the afore given data is 72,983 ms with the average time/record being ~ 9,471 ms which is too high.
    When I try to verify the Explain Plan of the query in ST05, in the Access path I see that the performance of Query Block 1 is bad. Query Block 1 is of the QBLOCK_TYPE UNIONA. Its the very first step in the Query execution internally.
    The indexes are defined on participating tables VBRK and VBRP as:
    VBRK~0      MANDT,VBELN
    VBRK~LOC MANDT,LCNUM
    VBRP~0      MANDT,VBELN,POSNR
    VBRP~Z01   FPLNR,MANDT
    VBRP~Z02   MANDT,MATNR,WERKS
    Its clear from the ST05, STAD and SE30 traces that there is a performance issue in this query. Does anyone have any pointers as to how to resolve this issue? Is there a protocol one needs to follow when using the "FOR ALL ENTRIES IN" clause? Or is there a need for any secondary indexes to be created?
    Please let me know
    Thanks and Best Regards,
    Rashmi.

    Hi,
    Try using the VBFA...to get the Invoice number and line item..and then use that value in VBRK...
    * Declare the internal table for T_VBFA.
    IF NOT gi_sales_items[] IS INITIAL.
    SELECT VBELV
                  POSNV
                  VBELN
                  POSNN
                  VBTYP_N
                  INTO TABLE T_VBFA
                  FOR ALL ENTRIES IN gi_sales_items
                  WHERE VBELV = gi_sales_items-VBELN
                  AND       POSNV = gi_sales_items-POSNR
                  AND       VBTYP_N = 'M'.             "Invoice                       ""Added this..
    ENDIF.
    **Add two columns to GI_SALES_ITEMS..to store the VBELN POSNN the data from t_vbfa..let's assume it is VBELN_VF and POSNR_VF
    * Basically merge gi_sales_items AND t_vbfa
    ** Then use that field in
    IF NOT GI_SALES_ITEMS[] IS INITIAL.
          SELECT a~vbeln
               a~fkart                    
               a~waerk
               a~fkdat                   
               b~posnr
               b~vgbel
               b~vgpos
               b~matnr
               b~arktx
               b~prctr
               b~txjcd
          INTO TABLE gi_billing_items
          FROM vbrk AS a
          INNER JOIN vbrp AS b
          ON a~vbeln = b~vbeln
          FOR ALL ENTRIES IN gi_sales_items
          WHERE b~vbeln = gi_sales_items-vbeln_vf   " Change here
           AND b~posnr  = gi_sales_items-posnr_vf     " Change here
           AND b~matnr  = gi_sales_items-matnr
           AND b~werks  = gi_sales_items-werks.
    ENDIF.
    Thanks
    Naren
    Edited by: Narendran Muthukumaran on Oct 15, 2008 11:35 PM

  • Performance of the select query

    i want to know wheter the conversion of  the select query
    SELECT  * FROM mchb                        
            WHERE matnr EQ mch1-matnr
            AND   charg EQ mch1-charg
            AND   werks EQ plant-werks.
            itab-lgort = mchb-lgort.
            itab-clabs = mchb-clabs.
            APPEND itab.
          ENDSELECT.
    into following pattern
    select lgort clabs
           from mchb
           into corresponding fields of itab
           WHERE matnr EQ mch1-matnr
           AND   charg EQ mch1-charg
           AND   werks EQ plant-werks.
           ENDSELECT.
    will give  the same results ?

    Hi,
    It will results in performance issue because of end select statement.
    select lgort clabs
         from mchb
            into table itab
            WHERE matnr EQ mch1-matnr
                  AND charg EQ mch1-charg
                  AND werks EQ plant-werks.
    Use like this you will get the values of lgort and clabs in the internal table itab.
    Then use loop statement to use that values further.
    Dont use end select it will be a performance issue.
    In this code there is no need to use of ENDSELECT and use corresponding fields of table itab.
    select lgort clabs
    from mchb
    into corresponding fields of itab
    WHERE matnr EQ mch1-matnr
    AND charg EQ mch1-charg
    AND werks EQ plant-werks.
    ENDSELECT.
    Thanks,
    Sakthi

  • 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

  • Performance optimization on select query for all entries

    Hi All,
          I want to optimize the select query in my Program.
         The select query is taking lot of time to search the records for the given condition in the where clause
         and more interestingly there are no records fetched from the database as the where condition does not matches. 
         It is taking more than 30 min to search the record and the result is no record found.
         Below is my select query. I have also created the secondary Index for the same.
         In My opinion FOR ALL ENTRIES is taking lot of time. Because there are more than 1200 records in internal table t_ajot     
          select banfn  bnfpo     bsart      txz01   matnr   Werks   lgort     matkl    reswk   menge     meins   flief      ekorg  
              INTO CORRESPONDING FIELDS OF TABLE t_req
              FROM eban
                FOR ALL ENTRIES IN t_ajot
              WHERE matkl >= t_ajot-matkl_low
                AND matkl <= t_ajot-matkl_high
                AND werks = t_ajot-werks
                AND loekz = ' '
                AND badat IN s_badat
                AND bsart = 'NB'.  
        Please suggest.

    Hi,
    that,
    FOR ALL ENTRIES IN t_ajot
    WHERE matkl >= t_ajot-matkl_low
    AND matkl <= t_ajot-matkl_high
    AND werks = t_ajot-werks
    AND loekz = ' '
    AND badat IN s_badat
    AND bsart = 'NB'.
    looks strange.
    However:
    How does your index look like?
    What executoin plan do you get?
    How do the statistics look like?
    Whats the content of the variables t_ajot-... and s_badata?
    Kind regards,
    Hermann

  • Performance improvement for select query

    Hi all,
    need to improve performace for the below select query as it is taking long time
    SELECT vbeln pdstk
             FROM vbuk INTO TABLE it_vbuk1 FOR ALL ENTRIES IN it_likp
          WHERE vbeln = it_likp-vbeln       AND
                wbstk = 'C'  AND "pdstk = ' ' AND
                vbtyp IN gr_delivery AND
                ( fkstk = 'A' OR fkstk = 'B' ) OR
                ( fkivk = 'A' OR fkivk = 'B' ).
    Regards,
    Kumar

    Hi,
        Check if it_likp is sorted on vbeln.
    SELECT vbeln pdstk
    FROM vbuk INTO TABLE it_vbuk1 FOR ALL ENTRIES IN it_likp
    WHERE vbeln = it_likp-vbeln AND
    wbstk = 'C' AND
    vbtyp IN gr_delivery AND
    ( ( fkstk = 'A' OR fkstk = 'B' ) OR      <-- check this condition , if ( ) is needed ...
      ( fkivk = 'A' OR fkivk = 'B' ) ) .
    Regards,
    Srini.

  • Performance issue in Select Query on ERCH

    Dear Friends,
    I have to execute a query on ERCH in production system having around 20 lakh data which keeps on increasing. "Select BELNR VERTRAG ADATSOLL from ERCH where BCREASON = u201803u2019 " . The expected volume of data that the query will return is approx 1400 records.
    Since the where clause includes a field which is not a key field please suggest the performance of the query so that it doesn't time-out.
    Regards,
    Amit Srivastava

    Hello Amit Srivastava ,
                                        You can add the Contract account number(VKONT)  and Business Partner number(GPARTNER) in your query and can create a custom Index for the contract account number  (We have this index created in our system).
    This will improve the performance effectively.
    Hope this answers your question.
    Thanks,
    Greetson

  • 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

  • Performance improvement of Select Query

    Hi All,
    Please suggest me to fine tune below query with example. It is causing DUMP when I am executing it because of low memory..
    select * from vbap into table it_vbap where vbeln = p_vbeln
    or vgbel = p_vbeln
    or vbeln = j_3avbfae-vbelv
    or vgbel = j_3avbfae-vbelv
    or vbeln = p_vgbel
    or vgbel = p_vgbel.
    Thanks in advance.
    Regards,
    Chandravadan

    Check out this way...
    declare 2 ranges it_vbeln and it_vgbel.
    move values of p_vbeln, j_3avbfae-vbelv, p_vgbel to it_vbeln.
    move values of p_vbeln, j_3avbfae-vbelv, p_vgbel to it_vgbel.
    select * from vbap into table it_vbap
    where vbeln in it_vbeln.
    select * from vbap appending table it_vbap
    where vbeln in it_vgbel.

  • Performance improvement in select query

    Hi,
    I have to improve the performance of the one custome program. I applied SQL trace & found out that below extract of code is taking maximum time
    SELECT a~znumdos
               a~zdatctx
               a~zmotctx
               a~gpart                                 
               b~vkont
               d~zidbarcly                                     
               dzligne dzstatulig                            
               b~zmontdact                                     
               c~zrmot_statut                                 
               d~zcanal                                       
               g~crdat                                        
               p~schedpid
               f~ktokl                                        
          FROM zr025sar AS a
          INNER JOIN zr026sar AS b       ON bznumdos = aznumdos
          INNER JOIN zr027sar AS c       ON cznumdos = aznumdos
                                         AND cvkont   = bvkont
          INNER JOIN zr021sat AS d       ON czcanal = dzcanal
                                         AND czcontrat = dzcontrat
                                         AND czligne = dzligne
          INNER JOIN but000  AS g        ON agpart   = gpartner
          INNER JOIN fkkvkp  AS f        ON fvkont   = bvkont
                                        AND fgpart   = gpartner
          LEFT OUTER JOIN zr136sar AS p  ON pznumdos = aznumdos
          APPENDING TABLE t_ctr_data_2
        WHERE a~zcanal       IN r_canal                        
          AND a~zdatctx      NE c_null_date
          AND a~zdatctx       < l_date_act              
          AND a~zmotctx      IN r_motife              
          AND a~zetadoss     IN r_dossier              
          AND b~zdateevent    < l_date_his                
          AND d~zstatulig    IN r_ligne                           
          AND d~zdatstatulig NE c_null_date                         
          AND d~zdatstatulig LE l_date_mdf                   
          AND d~zplantarif   IN r_zptarif
          AND d~zstatugcr    IN r_statutgcr
          AND f~ktokl        IN r_categ.                       
    How can i use the for all entries in above code.. Will it enhance the performance of the code?

    unfortunately nobody can help you here.
    Your task depends on the actually used select-options (IN), on the actual distribution of the data and the available indexes on the z-tables.
    I would neither recommend you a view, which is just a dictionary stored join and also not a FOR ALL ENTRIES, which will not increase the performance but reduce duplicates at the end, whcih can change even the result.
    You must analyse the statement in detail and I would recommend you to get some support by somebody more experienced.
    Siegfried

  • Performance problem in select query again

    Hi Experts,
    I have another performance issue with this.
    Select matnr werks from marc
              Into table i_marc
              For all entries in i_mara
              Where matnr eq i_mara-matnr.
         Loop at I_mara.
         Read table i_marc with key matnr = I_mara-matnr.
         Endloop.
    When I showed this code to my boss he suggested me to do some performance tuning.But i do not have any idea what to do.I am already using for all entries.
    Please suggest.
    Neeti

    Read statement fetches the record from the internal table using implicit key or explicit key. When no key or index is specified for the search criteria the key in the WA of the internal table is used implicitly for searching. Here the key or index is explicitly specified which is used for searching the records from internal table. This is faster than an implicit search.
    When reading a single record in an internal table, the READ TABLE WITH KEY is not a direct READ.  Therefore, SORT the table and use READ TABLE WITH KEY BINARY SEARCH.
    Select matnr from mara
         Into table i_mara
         Where matnr in s_matnr.
         Select matnr werks from marc
         Into table i_marc
         For all entries in i_mara
    Where matnr eq i_mara-matnr.
         Sort I_marc by matnr.
    Loop at I_mara.
         Read table i_marc with key
    matnr = I_mara-matnr
    binary search.
         Endloop.

  • Performance optimization in Select query

    Hi All,
    Please suggest good performance practice for the below code.
    SELECT * FROM BKPF WHERE BUKRS IN SO_BUKRS
                            AND BELNR IN SO_BELNR
                            AND GJAHR IN SO_GJAHR
                            AND BLART IN SO_BLART
                            AND BUDAT IN SO_BUDAT
                            AND USNAM IN SO_USNAM.
         CLEAR BSEG.
         SELECT * FROM BSEG WHERE BUKRS EQ BKPF-BUKRS
                              AND BELNR EQ BKPF-BELNR
                              AND GJAHR EQ BKPF-GJAHR
                              AND KOART EQ 'K'.
           SELECT SINGLE * FROM LFA1 WHERE LIFNR EQ BSEG-LIFNR
                                       AND KTOKK IN SO_KTOKK.
           CHECK SY-SUBRC EQ 0.
           MOVE-CORRESPONDING BKPF TO ITAB2.
           MOVE BSEG-LIFNR TO ITAB2-LIFNR.
           APPEND ITAB2.
         ENDSELECT.
         PERFORM CHECK_FOR_REVERSAL.
       ENDSELECT.
    Thanks
    Sonal

    declare internal table for BKPF, BSEG & LFA1 separately.
    instead of using Select & End select, use for all entries.
    SELECT * FROM BKPF into table itab1 WHERE BUKRS IN SO_BUKRS
    AND BELNR IN SO_BELNR
    AND GJAHR IN SO_GJAHR
    AND BLART IN SO_BLART
    AND BUDAT IN SO_BUDAT
    AND USNAM IN SO_USNAM.
    if not itab1[] is initial.
      sort bkpf by belnr.
    SELECT * FROM BSEG into table itab2
    for all entries in itab1
    WHERE BUKRS EQ itab1-BUKRS
    AND BELNR EQ itab1-BELNR
    AND GJAHR EQ itab1-GJAHR
    AND KOART EQ 'K'.
    if not itab2[] is initial.
      sort itab2 by lifnr
       SELECT SINGLE * FROM LFA1 into table itab3
       for all entries in itab2
       WHERE LIFNR EQ itab2-LIFNR
    AND KTOKK IN SO_KTOKK.
    endif.
    endif.
    endif.
    sort itab1 by belnr.
    sort itab2 by belnr.
    sort itab3 by lifnr.
    loop at itab1.
    move-corresponding itab1 to itfinal.
      loop at itab2 where belnr = itab1-belnr.
        move-corresponding itab2 to itfinal.
        read itab3 with key lifnr = itab2-lifnr.
        if sy-subrc = 0.
          move-corresponding itab3 to itfinal.
        endif.
      endloop.
    append itfinal.
    clear itfinal.
    endloop.

Maybe you are looking for

  • Xml payload encoding from utf to iso

    Hi Experts, Could you please let me know how can I encode he xml payload from utf-8 to ISO-8859-1. its bit urgent any help is appreciated. Thanks & Regards, Ranganath.

  • Opening .pdf files in Firefox 3.6.13 spawns "infinite" tabs -- amazing!

    If I click a link to a .pdf file, Firefox will open up tab after tab after tab -- they go shooting across the top of the tab bar (it's incredible). I can use Task Manager to force FF to quit (and then manually end the Firefox.exe process since it doe

  • Homebrew WiFi Antenna (Proper Cable, LMR-195 GR-58?)

    Hey, I don't know if this is the best forum for my questions, and if not please direct me to one that better suits my needs. I was simply referred to this forum through another one. Anyhow, me and my friend are attempting to build our own wifi antenn

  • Please help to rewrite this logic to improve the performance.

    Hi Experts, In this procedure we are inserting data into the same table using same columns and same values with different WHERE conditions. IN the WHERE clause we have some common conditions in all select statements.   Thanks.

  • Looping in XI

    Hi All, is there is any other way to perform loop other than BPM in XI.Can you please help me in this doubt? Regards, Rama