Skip to Content
author's profile photo Former Member
Former Member

Perfomance issue

Hi Gui's.

I am facing performance problem.

In t_hdr i have 15 fields and in t_item i have 40 fields I used forall entries but out put is changing

please anybody help me.

loop at t_hdr.

select buzei buzid koart shkzg mwskz dmbtr hwbas sgtxt vbund kostl

aufnr anln1 anln2 hkont kunnr lifnr matnr werks ebeln ebelp

zekkn rewrt prctr txjcd projk

into (t_item-buzei, t_item-buzid, t_item-koart, t_item-shkzg,

t_item-mwskz, t_item-dmbtr, t_item-hwbas, t_item-sgtxt,

t_item-vbund, t_item-kostl, t_item-aufnr, t_item-anln1,

t_item-anln2, t_item-hkont, t_item-kunnr, t_item-lifnr,

t_item-matnr, t_item-werks, t_item-ebeln, t_item-ebelp,

t_item-zekkn, t_item-rewrt, t_item-prctr, t_item-txjcd,

t_item-projk)

from bseg

where bukrs = t_hdr-bukrs

and belnr = t_hdr-belnr

and gjahr = t_hdr-gjahr

and hkont in s_hkont

and mwskz in s_mwskz

and kostl in s_kostl

and prctr in s_prctr

and werks in s_werks.

  • Skip record if not in selection screen range for state

check t_item-txjcd(2) in s_state.

if t_item-shkzg = c_debit. "S

endif.

if t_item-shkzg = c_credit. "H

t_item-dmbtr = t_item-dmbtr * ( -1 ).

t_item-rewrt = t_item-rewrt * ( -1 ).

t_item-hwbas = t_item-hwbas * ( -1 ).

endif.

Thanks and regards

santhosh

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Jan 14, 2009 at 04:52 PM

    I see no real performance problem here. What is the rest of the code inside the LOOP?

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi

      There are couple of things that need to be carefully assessed in your logic.

      1. BSEG is a cluster table, doing SELECT .. ENDSELECT will surely have worse performance than SELECT..INTO TABLE.

      2. Since BSEG is a cluster table and only have BUKRS, BELNR, GJAHR and BUZEI as it's primary key, it would cost more to use additional key in where condition. The reason is in cluster table, other fields that is not included as primary key will be stored in database as Raw type. Which mean if you put more field in where condition, the selection process will not be executed directly in DB server. SAP application will need to translate that raw data into each fields and do filtering.

      3. It is better to do one by one MOVE instead of move corresponding especially if a lot of field involved since there is overhead cost to search field that has the same name before moving the value.

      Hence, I would suggest the logic be changed into something like below :

      if t_hdr[] is not initial.
      select bukrs belnr gjahr buzei buzid koart shkzg mwskz dmbtr hwbas sgtxt vbund kostl
      aufnr anln1 anln2 hkont kunnr lifnr matnr werks ebeln ebelp
      zekkn rewrt prctr txjcd projk
      into table t_item
      from bseg
      for all entries in t_hdr
      where bukrs = t_hdr-bukrs
      and belnr = t_hdr-belnr
      and gjahr = t_hdr-gjahr.
      *as far as i know, you should use only primary key for selection,
      *however you're free to try combine all the selection criteria
      *in where condition and compare the performance
          if sy-subrc = 0.
      	delete t_item where not hkont in s_hkont.
      	delete t_item where not mwskz in s_mwskz.
      	delete t_item where not kostl in s_kostl.
      	delete t_item where not prctr in s_prctr.
      	delete t_item where not werks in s_werks.
          endif.
      endif.
      
      loop at t_item assigning <fs_item>.
      Skip record if not in selection screen range for state 
        if <fs_item>-txjcd(2) not in s_state.
          delete <fs_item>.
          continue.
        endif.
        if <fs_item>-shkzg = c_credit. "H
          <fs_item>-dmbtr = <fs_item>-dmbtr * ( -1 ).
          <fs_item>-rewrt = <fs_item>-rewrt * ( -1 ).
          <fs_item>-hwbas = <fs_item>-hwbas * ( -1 ).
        endif.
      **&MWB 04/08/2005 ... add additional US Bayer Tax dept requested fields
      clear: <fs_item>-basetax, <fs_item>-accrtax, <fs_item>-vendtax,
      <fs_item>-taxrate, <fs_item>-invbase, <fs_item>-invtax.
      **&MWB ... end insert 04/08/2005
      
      clear <fs_item>-hwbas.
      *
      *assume t_hdr is already sorted by bukr belnr gjahr
      read table t_hdr into w_hdr with key bukrs = <fs_item>-bukrs
                                           belnr = <fs_item>-belnr
                                           gjahr = <fs_item>-gjahr
                                  binary search.
      
      *move your neccesary header data here
      ...
      endloop.

      Do try it and compare the performance. Hope it's help.

      Regards,

      Abraham

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.