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

Code taking too much time to output

Former Member
0 Likes
1,469

Following code is taking too much time to execute . (some time giving Time_out )

ind = sy-tabix.

SELECT SINGLE * FROM mseg INTO mseg

WHERE bwart = '102' AND

lfbnr = itab-mblnr AND

ebeln = itab-ebeln AND

ebelp = itab-ebelp.

IF sy-subrc = 0.

DELETE itab INDEX ind.

CONTINUE.

Is there any other way to write this code to reduce the output time.

Thanks

Following code is taking too much time to execute . (some time giving Time_out )

ind = sy-tabix.

SELECT SINGLE * FROM mseg INTO mseg

WHERE bwart = '102' AND

lfbnr = itab-mblnr AND

ebeln = itab-ebeln AND

ebelp = itab-ebelp.

IF sy-subrc = 0.

DELETE itab INDEX ind.

CONTINUE.

Is there any other way to write this code to reduce the output time.

Thanks

11 REPLIES 11
Read only

Former Member
0 Likes
1,412

Why dont you select all the data from MSEG once??? Outside the loop

SELECT * FROM mseg INTO mseg

WHERE bwart = '102'.

sort mseg.

Now Read table mseg where mseg = itab-mblnr AND

ebeln = itab-ebeln AND

ebelp = itab-ebelp Binary Search.

This might work in a lesser time

Read only

Former Member
0 Likes
1,412

Hi,

u can select what are all the field s u need to display in out put screen instead of taking all fields from the MSEG,

(other wise try UPTO ONE ROW statement .)

thanks

Read only

Former Member
0 Likes
1,412

Hi,

I think you are executing this code in a loop which is causing the problem. The rule is "Never put SELECT statements inside a loop".

Try to rewrite the code as follows:


* Outside the loop
SELECT *
from MSEG
into table lt_mseg
for all entries in itab
where bwart = '102' AND
lfbnr = itab-mblnr AND
ebeln = itab-ebeln AND
ebelp = itab-ebelp.

Then inside the loop, do a READ on the internal table


Loop at itab.

*******

read table lt_mseg with key bwart = '102'. "plus other conditions
if sy-subrc ne 0.
delete itab. "index is automatically determined here from SY-TABIX
endif.

******

endloop.

I think this should optimise performance. You can check your code's performance using SE30 or ST05.

Hope this helps! Please revert if you need anything else!!

Cheers,

Shailesh.

Always provide feedback for helpful answers!

Read only

0 Likes
1,412

Hi sir, I tried your idea like

LOOP AT itab.

ind = sy-tabix.

SELECT SINGLE * FROM mseg INTO mseg

WHERE bwart = '102'.

loop at mseg .

read table itab with key bwart = '102'

mblnr = mseg-lfbnr

ebeln = mseg-ebeln

ebelp = mseg-ebelp binary search.

IF sy-subrc ne 0.

DELETE itab INDEX ind.

endif.

endloop.

It increase the performance but it is not deleting itab for condition bwart 102. Please do check me , what m doing wrong ?

Thanks

Read only

0 Likes
1,412

>

> Please do check me , what m doing wrong ?

Moderator message - Please see before posting - post locked

Read only

Former Member
0 Likes
1,412

Hi,

You can try with creating secondary index with the same combination .It will reduce your time.

Thanks,

Ankita

Read only

Former Member
0 Likes
1,412

hi,

i think the problem is that you are extracting the data from the same place and replacing it in the same place in the table....

try putting the extracted data into an internal table first and then use the update statement to update the table with the given data.

Read only

Former Member
0 Likes
1,412

Try This

SELECT SINGLE * FROM mseg INTO mseg
WHERE bwart = '102'.

loop at mseg into wa_mseg.
read table itab into wa_itab with key mblnr = wa_mseg-lfbnr
                                      ebeln = wa_mseg-ebeln
                                      ebelp = wa_mseg-ebelp.
if sy-subrc eq 0.
 ind = sy-tabix.
 DELETE itab INDEX ind.
endif.
endloop.

Regards

Vinod

Read only

Former Member
0 Likes
1,412

Within standard SAP there's no appropriate index on MSEG to support your query. Thus instead of selecting the material document directly from MSEG via the purchase order number, you should first get the material documents via the purchase order history table EKBE. Then you can read the MSEG data you need using the material document number (mseg-mblnr=ekbe-belnr, mseg-mjahr=ekbe-gjahr, mseg-zeile=ekbe-buzei) or simply use a join on EKBE and MSEG.

This should give you the speed you're looking for...

Cheers, harald

Read only

sivaprasad_ml
Participant
0 Likes
1,412

Hello,

Try this way.

sELECT SINGLE * FROM mseg INTO mseg

WHERE

lfbnr = itab-mblnr AND

ebeln = itab-ebeln AND

ebelp = itab-ebelp and

bwart = '102'.

IF sy-subrc = 0.

DELETE itab INDEX ind.

CONTINUE.

This may help out.

Rgds

Siva

Read only

sivaprasad_ml
Participant
0 Likes
1,412

I welcome Mr Harold's suggestion too. You can try with that too.

Cheers

Siva