Application Development Discussions

Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

performance

Former Member

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 5:27 AM

200

- SAP Managed Tags:
- ABAP Development

Hi friends,

LOOP AT it_batch.

x_tabix = sy-tabix.

SELECT SUM( clabs ) SUM( cumlm ) SUM( cinsm ) SUM( ceinm )

SUM( cspem ) SUM( cretm ) SUM( cvmla ) SUM( cvmum )

SUM( cvmin ) SUM( cvmei ) SUM( cvmsp ) SUM( cvmre )

FROM mchb

INTO (x_clabs, x_cumlm, x_cinsm, x_ceinm, x_cspem, x_cretm,

x_cvmla, x_cvmum, x_cvmin, x_cvmei, x_cvmsp, x_cvmre)

WHERE matnr = it_batch-matnr

AND werks = it_batch-werks

AND charg = it_batch-charg.

IF NOT ( x_clabs EQ 0 AND

x_cumlm EQ 0 AND

x_cinsm EQ 0 AND

x_ceinm EQ 0 AND

x_cspem EQ 0 AND

x_cretm EQ 0 AND

x_cvmla EQ 0 AND

x_cvmum EQ 0 AND

x_cvmin EQ 0 AND

x_cvmei EQ 0 AND

x_cvmsp EQ 0 AND

x_cvmre EQ 0 ).

DELETE it_batch INDEX x_tabix.

*Begin of Modifications BDVK945500 by TCS941764 on 30/08/2006

ELSE.

CLEAR x_objek.

x_objek(18) = it_batch-matnr.

x_objek+18(4) = it_batch-werks.

x_objek+22(10) = it_batch-charg.

CLEAR inob.

SELECT SINGLE cuobj FROM inob INTO inob-cuobj

WHERE obtab = 'MCHA'

AND objek = x_objek

AND klart = '022'.

CONCATENATE inob-cuobj 'O' INTO it_batch-objectid.

MODIFY it_batch.

*End of Modifications BDVK945500 by TCS941764 on 30/08/2006

ENDIF.

ENDLOOP.

How to change the above code for better performance without effecting the results(i mean using for all entries and at end of is it possible?) .Please help me.

Thanks for all.

1 ACCEPTED SOLUTION

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 6:04 AM

119

- SAP Managed Tags:
- ABAP Development

Hi Bharat,

Try this piece of code.

SELECT SUM( clabs ) SUM( cumlm ) SUM( cinsm ) SUM( ceinm )

SUM( cspem ) SUM( cretm ) SUM( cvmla ) SUM( cvmum )

SUM( cvmin ) SUM( cvmei ) SUM( cvmsp ) SUM( cvmre )

FROM mchb

INTO (x_clabs, x_cumlm, x_cinsm, x_ceinm, x_cspem, x_cretm,

x_cvmla, x_cvmum, x_cvmin, x_cvmei, x_cvmsp, x_cvmre)

for all entries in it_batch

WHERE matnr = it_batch-matnr

AND werks = it_batch-werks

AND charg = it_batch-charg.

LOOP AT it_batch.

x_tabix = sy-tabix.

IF NOT ( x_clabs EQ 0 AND

x_cumlm EQ 0 AND

x_cinsm EQ 0 AND

x_ceinm EQ 0 AND

x_cspem EQ 0 AND

x_cretm EQ 0 AND

x_cvmla EQ 0 AND

x_cvmum EQ 0 AND

x_cvmin EQ 0 AND

x_cvmei EQ 0 AND

x_cvmsp EQ 0 AND

x_cvmre EQ 0 ).

move space to it_batch-matnr.

modify it_batch index x_tabix transporting matnr.

*Begin of Modifications BDVK945500 by TCS941764 on 30/08/2006

ELSE.

CLEAR x_objek.

x_objek(18) = it_batch-matnr.

x_objek+18(4) = it_batch-werks.

x_objek+22(10) = it_batch-charg.

CLEAR inob.

SELECT SINGLE cuobj FROM inob INTO inob-cuobj

WHERE obtab = 'MCHA'

AND objek = x_objek

AND klart = '022'.

CONCATENATE inob-cuobj 'O' INTO it_batch-objectid.

MODIFY it_batch index x_tabix transporting objectid.

*End of Modifications BDVK945500 by TCS941764 on 30/08/2006

ENDIF.

ENDLOOP.

DELETE it_batch where matnr = space.

Use the select statement outside the loop and the delete statement leads to the loss of index which leads to more processing time. So, I have removed delete outside the loop and also whenever u are using modify statements use it along with index. All these changes will definetely lead to a better performance.

Regards,

Geeta

12 REPLIES 12

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 5:30 AM

119

- SAP Managed Tags:
- ABAP Development

hi

instead of loop inside loop ...

better use read statement in loop statement....

loop at header.

read table item with key <condition>

............

..............

endloop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 5:33 AM

119

- SAP Managed Tags:
- ABAP Development

hi

since u used select statement in the loop...

it reduces the performance very much...

what u do is write a select statement above that loop using all entries and store all records into an internal table...

then use read statement in loop....

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 5:33 AM

119

- SAP Managed Tags:
- ABAP Development

Hi Bharat,

Remove your select query from the Loop and select using for all entries.

It will improve the performance of the code.

Reward points if useful.

Regards,

Atish

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 5:39 AM

119

- SAP Managed Tags:
- ABAP Development

Hi Bharat ,

Using select inside the loop will bring down the performance . wht can u do is

create a internal table with the fields (x_clabs, x_cumlm, x_cinsm, x_ceinm, x_cspem, x_cretm, x_cvmla, x_cvmum, x_cvmin, x_cvmei, x_cvmsp, x_cvmre) -itabsum

write the select outside the loop

SELECT SUM( clabs ) SUM( cumlm ) SUM( cinsm ) SUM( ceinm )

SUM( cspem ) SUM( cretm ) SUM( cvmla ) SUM( cvmum )

SUM( cvmin ) SUM( cvmei ) SUM( cvmsp ) SUM( cvmre )

FROM mchb

INTO table itabsum

for all entires in it_batch.

WHERE matnr = it_batch-matnr

AND werks = it_batch-werks

AND charg = it_batch-charg.

LOOP AT it_batch.

x_tabix = sy-tabix.

read table itabsum with key matnr = it_batch-matnr werks = it_batch-werks charg = it_batch-charg into ls_sum .

if sy-subrc eq 0 .

do rest processing similarly u have done

endif .

endloop .

similarly u can do same for the SELECT SINGLE cuobj FROM inob INTO inob-cuobj

WHERE obtab = 'MCHA'

AND objek = x_objek

AND klart = '022'.

select all the entires before the loop and use the read statement inside the loop .

please reward points if helpfull.

Message was edited by:

Sridhar Srirama

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 6:06 AM

119

- SAP Managed Tags:
- ABAP Development

Hi first of all thanks.

I am not able to write the select sum() query with for all entries syntax.Then how to write the query.Please help me.

Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 6:20 AM

119

- SAP Managed Tags:
- ABAP Development

HI Bharat ,

sorry for that . the sum wont work for all entires ,

U can just select the values for all entires in the internal table called itab1

SELECT clabscumlm cinsm ceinm

cspem cretm cvmum

cvmin cvmei cvmsp cvmre

FROM mchb

INTO table itab1

for all entires in it_batch

WHERE matnr = it_batch-matnr

AND werks = it_batch-werks

AND charg = it_batch-charg.

Do the sum calculation manually on the table itab1 .

loop at itab1 into wa1.

sum the values from the wa .

at new charg .

append the sum value into aonther internal table itabsum

clear sum values .

end at .

endloop.

Message was edited by:

Sridhar Srirama

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 6:23 AM

119

- SAP Managed Tags:
- ABAP Development

Can you please explain the following part.

loop at itab1 into wa1.

sum the values from the wa .

at new charg .

append the sum value into aonther internal table itabsum

clear sum values .

end at .

endloop.

Thanks & Regards,

Bharat.V

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 6:31 AM

119

- SAP Managed Tags:
- ABAP Development

the internal table itab1 as all the entires without summing .

know u need to sum all the entires which has same value of matnr werks and charg .

loop at itab1 into wa1 .

sum the values from the wa . " add the values to the another structure similar to wa say like wa1 (the fields in the wa1 contains corresponding sum ) . the sum keep getting acummalted in this structure .

at new of charg " this control of code is entred inside this when there is a change in either matnr werks or charg .

append the structure wa1 to itsum .

clear wa1 . " the sum is reset when a new entry has to be created in itsum

endat.

endloop .

I hope this clears ur doubt . please let me know any more queries

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 7:09 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 7:26 AM

119

- SAP Managed Tags:
- ABAP Development

Dear

i am little bit confusing with that sum logic.If u don't mine please send me the sample logic for that sum .

Thank u very much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 7:35 AM

119

- SAP Managed Tags:
- ABAP Development

data : wa1 like line of itab1 ,

wa2 like wa1

clear wa2 .

LOOP at itab1 into wa1 .

wa2-clabs = wa2-clabs + wa1-clabs.

wa2- cumlm = wa2- cumlm + wa1- cumlm,

*do similarly for all the fields .

At new of charg .

append wa2 to itabsum

clear wa2 .

end at .

endloop.

please do give the points if usefull .

Former Member

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2007 May 21 6:04 AM

120

- SAP Managed Tags:
- ABAP Development

Hi Bharat,

Try this piece of code.

SELECT SUM( clabs ) SUM( cumlm ) SUM( cinsm ) SUM( ceinm )

SUM( cspem ) SUM( cretm ) SUM( cvmla ) SUM( cvmum )

SUM( cvmin ) SUM( cvmei ) SUM( cvmsp ) SUM( cvmre )

FROM mchb

INTO (x_clabs, x_cumlm, x_cinsm, x_ceinm, x_cspem, x_cretm,

x_cvmla, x_cvmum, x_cvmin, x_cvmei, x_cvmsp, x_cvmre)

for all entries in it_batch

WHERE matnr = it_batch-matnr

AND werks = it_batch-werks

AND charg = it_batch-charg.

LOOP AT it_batch.

x_tabix = sy-tabix.

IF NOT ( x_clabs EQ 0 AND

x_cumlm EQ 0 AND

x_cinsm EQ 0 AND

x_ceinm EQ 0 AND

x_cspem EQ 0 AND

x_cretm EQ 0 AND

x_cvmla EQ 0 AND

x_cvmum EQ 0 AND

x_cvmin EQ 0 AND

x_cvmei EQ 0 AND

x_cvmsp EQ 0 AND

x_cvmre EQ 0 ).

move space to it_batch-matnr.

modify it_batch index x_tabix transporting matnr.

*Begin of Modifications BDVK945500 by TCS941764 on 30/08/2006

ELSE.

CLEAR x_objek.

x_objek(18) = it_batch-matnr.

x_objek+18(4) = it_batch-werks.

x_objek+22(10) = it_batch-charg.

CLEAR inob.

SELECT SINGLE cuobj FROM inob INTO inob-cuobj

WHERE obtab = 'MCHA'

AND objek = x_objek

AND klart = '022'.

CONCATENATE inob-cuobj 'O' INTO it_batch-objectid.

MODIFY it_batch index x_tabix transporting objectid.

*End of Modifications BDVK945500 by TCS941764 on 30/08/2006

ENDIF.

ENDLOOP.

DELETE it_batch where matnr = space.

Use the select statement outside the loop and the delete statement leads to the loss of index which leads to more processing time. So, I have removed delete outside the loop and also whenever u are using modify statements use it along with index. All these changes will definetely lead to a better performance.

Regards,

Geeta