Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Perfomance issue

Former Member
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

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

Rob

0 Kudos

Hi Rob i am send the rest of the code please find it

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.

**&MWB 04/08/2005 ... add additional US Bayer Tax dept requested fields

clear: t_item-basetax, t_item-accrtax, t_item-vendtax,

t_item-taxrate, t_item-invbase, t_item-invtax.

**&MWB ... end insert 04/08/2005

clear t_item-hwbas.

*

move-corresponding t_hdr to t_item.

append t_item.

clear t_item.

endselect.

endloop.

0 Kudos

I might be doing SELECT before the loop and then do READ TABLE inside the loop.

Close duplicate thread.

0 Kudos

There is still no real problem. How many records in t_hdr? That's likely the source of any problem.

Rob

And you should close the other post.

0 Kudos

Hi Rob,

There are 41 records in t_hdr.

Thanks and regards

santhosh

0 Kudos

Why do you think there is a performance problem?

Rob

0 Kudos

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