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

reduce execution time

Former Member
0 Likes
1,352

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 .

12 REPLIES 12
Read only

Former Member
0 Likes
1,315

instead of writing select..endselect inside loop..endloop

use for all entries ...

Read only

Former Member
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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.

Read only

Former Member
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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

Read only

sachin_mathapati
Contributor
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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

Read only

Former Member
0 Likes
1,315

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.

Read only

Former Member
0 Likes
1,315

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.