‎2008 Jul 22 11:24 AM
How to reduce the execution time of this code?
Loop at porder1.
SELECT aufnr bstmg hsdat sgtxt bwart charg FROM mseg INTO
(porder-aufnr,porder-bstmg,porder-hsdat,porder-sgtxt,porder-bwart,
porder-charg)
WHERE matnr = porder1-matnr AND
aufnr = porder1-aufnr AND
werks = porder1-pwerk AND
( bwart = '101' OR
bwart = '102' ).
Endselect.
Endloop.
Regards
Praju .
‎2008 Jul 22 11:27 AM
instead of writing select..endselect inside loop..endloop
use for all entries ...
‎2008 Jul 22 11:28 AM
Hi,
Use FOR ALL ENTRIES.
SELECT aufnr bstmg hsdat sgtxt bwart charg
FROM mseg INTO CORRESPONDING FIELDS OF TABLE porder
FOR ALL ENTRIES IN poder1
WHERE matnr = porder1-matnr AND
aufnr = porder1-aufnr AND
werks = porder1-pwerk AND
( bwart = '101' OR
bwart = '102' ).Regards
Adil
‎2008 Jul 22 11:28 AM
Hi,
Instead of fetching data using LOOP AT and SELECT ENDSELECT,
You can create one internal table and put whole Data in the table that will reduce your time of execution considerably.
Without using SELECT and ENDSELECT.
Regards
Sumit Agarwal
‎2008 Jul 22 11:29 AM
Hi,
Instead of using the select stmt inside the loop, fetch all the required values from the MESG table for all entries in the porder1 into an internal table.
Then read the internal table inside the loop.
This may reduce the execution time.
Reward if helpful.
Sharin.
‎2008 Jul 22 11:30 AM
hiii
avoid using SELECT ENDSELECT here...instead of using this you can use simple SELECT statement and get all that data in one internal table and then use LOOP statement with conditions so that server will be hit only once and then you can use loop statement for any conditions and you can use READ statement also. this way performance will be incresed..
regards
twinkal
‎2008 Jul 22 11:30 AM
Hi Prajwal,
Loop at porder1.
SELECT aufnr bstmg hsdat sgtxt bwart charg FROM mseg INTO
(porder-aufnr,porder-bstmg,porder-hsdat,porder-sgtxt,porder-bwart,
porder-charg)
WHERE matnr = porder1-matnr AND
aufnr = porder1-aufnr AND
werks = porder1-pwerk AND
( bwart = '101' OR
bwart = '102' ).
+Endselect.+
Endloop.yes i know that you can't avoid select query inside the loop because its dynamic query but still you can avoid the select endselect.
Here use into table insted of variables.
Regards,
Sandeep
Edited by: Sandeep patel on Jul 22, 2008 4:00 PM
‎2008 Jul 22 11:30 AM
Hi,
You shouldn't write a select statement in loop....endloop.
Rather first select the porder data and do a 'FOR ALL ENTRIES' while selecting from MSEG.
Your select statement should be something like this:
select data from table into porder1.
if not porder1[] is initial.
select data from mseg into porder
*for all entries* in porder1
where matnr = porder1-matnr AND
aufnr = porder1-aufnr AND
werks = porder1-pwerk AND
( bwart = '101' OR
bwart = '102' ).
endif.Regards,
Shailaja
‎2008 Jul 22 11:31 AM
Hi,
It is not advisable to use select statement inside loop..
Instead select entries outside loop and sort.
And inside loop use Read statement.
Regards,
Sachin M M
‎2008 Jul 22 11:34 AM
Hi Prajwal,
SELECT-ENDSELECT is a looping statement which selects every single record based on the condition. This raises a performance issue.
Instead you can use SELECT statement with Internal Table, as follows:
SELECT aufnr bstmg hsdat sgtxt bwart charg
FROM mseg
INTO < itab >
WHERE matnr = porder1-matnr AND
aufnr = porder1-aufnr AND
werks = porder1-pwerk AND
( bwart = '101' OR
bwart = '102' ).Here, the internal table is of the structure of the selected fields.
Hope this helps you.
Regards,
Chandra Sekhar
‎2008 Jul 22 11:36 AM
Hi prajwal.
I would like to suggest,
It is possible to reduce the time of execution by Increasing the number of fields in the WHERE clause as only those specific number of records are fetched which results in comparatively less execution time.
Also, SAP has designed such powerfull tools like Transactions - ST05, ST07, ST30, and many more
I would like to suggest you a couple of references relating to your case,
[SDN - Reference for Long execution time during processing of a select query|/thread/477540 [original link is broken];
[SDN - Reference for Reducing the Execution time of the program - Tools|;
[SDN - Reference for solutions to reduce the execution time of a program|;
Hope that's usefull.
Good Luck & Regards.
Harsh Dave
‎2008 Jul 22 11:37 AM
Hi,
try with this,
if not tb_porder1[] is initial.
select f1
f2
fn
into tb_porder
from mseg
for all entries in tb_porder1
where matnr = tb_porder1-matnr
(rest of the clause.)
if sy-subrc <> 0.
*error
endif.
endif.
if possible try to use loop at internal table into workarea.
then read statement.
‎2008 Jul 22 11:39 AM
hi....
first of all to reduce execution time first f all aoid select end select.Instead use correspinding fields of table.that will save a lot of time.
this will all the entires at a time.