‎2006 Jul 28 9:37 PM
DATA: t_bkpf TYPE bkpf.
DATA: t_bseg type bseg_t.
DATA: wa_bseg like line of t_bseg.
select * from bkpf into t_bkpf where document type ='KZ' and bldat in s_bldat.
select single * from bseg into wa_bseg where belnr = t_bkpf-belnr.
append wa_bseg to t_bseg.
endselect.
loop at t_bseg into wa_bseg.
at new belnr.
if wa_bseg-koart EQ 'K'.
// pick vendor wrbtr
else
// pick other line item's wrbtr
endif.
endat.
endloop.
i am guessing my select statements arnt efficient performance wise, secondly in the loop when i use 'at new belnr' it aint showing my any values whereas i get all the vendors(KOART EQ 'K') when i dont use 'at new belnr' .
why is this so and how can i make the code efficient ?
Thanks..
Shehryar
‎2006 Jul 28 9:43 PM
Don't to do a SELECT inside another one, instead us FOR ALL ENTRIES.
select * from bkpf into t_bkpf where document type ='KZ' and bldat in s_bldat.
<b>
if NOT t_bkpf[] is initial.</b>
select * from bseg <b>
for all entries in t_bkpf
append corresponding fields of t_bseg</b>
into wa_bseg where belnr = t_bkpf-belnr.
<b>endif.</b>
Regards,
Ravi
Note : Please mark all the helpful answers
‎2006 Aug 01 7:43 AM
Hello,
Ravi, is this a correct code snippet u advised me.?
select * from bkpf into t_bkpf where document type ='KZ' and bldat in s_bldat.
<b>if NOT t_bkpf[] is initial.</b>
select * from bseg
<b>for all entries in t_bkpf
append corresponding fields of t_bseg</b>
into wa_bseg where belnr = t_bkpf-belnr.
<b>endif.</b>
is it in the correct order .. are they two separate codes ?
‎2006 Aug 01 7:47 AM
Hello,
Include BUKRS BLDAT BSTAT in your first selection query.
select * from bkpf into t_bkpf
where bukrs = '0001'
and bldat in s_bldat
and bstat = ' '
and document type ='KZ' .
if not sy-dbcnt is initial.
select * from bseg
for all entries of t_bkpf
into t_bseg
where bukrs = t_bkpf-bukrs
and belnr = t_bkpf-belnr
and gjahr = t_bkpf-gjahr.
endif.
Regards,
Naimesh
‎2006 Jul 28 9:43 PM
change the second select statment as below.
select single * from bseg into table t_bseg where belnr = t_bkpf-belnr.
‎2006 Jul 28 9:44 PM
Hi,
Possible hints for performance optimisation.
<b>SELECT</b>
1) Try using a JOIN for the selection on 2 different tables
2) Do not use '*' but specify only the fields you really use afterwards in the processing
<b>LOOP</b>
1) Field-symbols can improve performance significantly
LOOP AT ... INTO ... is less efficient than LOOP AT ... ASSIGNING ...
To check this, use transaction SE30 to benchmark the different solutions.
Best regards,
Guillaume
‎2006 Jul 28 10:02 PM
thanks,
Guillaume Garcia.. can u demonstrate with an example mapped on my problem.
Thanks..
‎2006 Jul 28 10:05 PM
Hi,
what can u guys say to my second query i.e the 'at new belnr' one ?
Shehryar
‎2006 Jul 28 10:09 PM
Hi,
1.Dont read all the fields from the table unless it is required in your program.
This will tremendously improve your performance.
2.Make use of the key fields of the table wherever possible
In your scenario you could use the fields BUKRS,BELNR,GJAHR of the table BKPF in the WHERE Clause rather than
other fields.This will improve your performance a lot..
3.As BSEG is a cluster table it will cause performance problem in most cases.So try to read
the required fields from it rather than reading all the fields.Again Make use of the key fields in the WHERE Clause
here too to improve the performance..
4.Remove SELECT..ENDSELECT and replace it with FOR ALL ENTRIES to improve the performance.
Cheers,
Abdul Hakim
Mark all useful answers..