Application Development and Automation 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: 
Read only

how can i improve this code ?

Former Member
0 Likes
821

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

8 REPLIES 8
Read only

Former Member
0 Likes
781

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

Read only

0 Likes
781

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 ?

Read only

0 Likes
781

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

Read only

Former Member
0 Likes
781

change the second select statment as below.

select single * from bseg into table t_bseg where belnr = t_bkpf-belnr.

Read only

guillaume-hrc
Active Contributor
0 Likes
781

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

Read only

0 Likes
781

thanks,

Guillaume Garcia.. can u demonstrate with an example mapped on my problem.

Thanks..

Read only

0 Likes
781

Hi,

what can u guys say to my second query i.e the 'at new belnr' one ?

Shehryar

Read only

abdul_hakim
Active Contributor
0 Likes
781

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