Skip to Content
author's profile photo
Former Member

Performance Tuning

I have to replace the existing code to increase performance tuning.

I am facing difficulty in this.

Is anyone help me out in this.

existing code is :-

tables: table1,

table2,

table3,

table4,

table5,

table6,

table6t,

table8,

table8t.

data: begin of lt_table1 occurs 0,

objek like table1-objek,

clint like table1-clint,

lkenz like table1-lkenz,

end of lt_table1,

ls_table1 like line of lt_table1,

begin of lt_table2 occurs 0,

objek like table1-objek,

clint like table1-clint,

klart like table1-klart,

class like table2-class,

kschl like table3-kschl,

imerk like table4-imerk,

end of lt_table2,

ls_table2 like line of lt_table2,

begin of itab occurs 0,

objek like table1-objek,

clint like table1-clint,

klart like table1-klart,

class like table2-class,

kschl like table3-kschl,

atinn like table8-atinn,

atzhl like table8-atzhl,

adzhl like table8-adzhl,

atwrt like table8-atwrt,

atnam like table6-atnam,

atbez like table6t-atbez,

end of itab,

irec like line of itab.

data: begin of orec.

include structure zstru_data.

data: end of orec.

select objek clint lkenz from table1

into corresponding fields of ls_table1

where objek = i_matnr.

check ls_table1-lkenz is initial.

append ls_table1 to lt_table1.

endselect.

if sy-subrc ne 0.

raise no_material_class.

endif.

loop at lt_table1 into ls_table1.

clear ls_table2.

move ls_table1-objek to ls_table2-objek.

select single clint klart class from table2

into corresponding fields of ls_table2

where clint = ls_table1-clint

and klart = '001' "Material class

and statu = '1' "Released status

and vondt le sy-datum "Valid from date

and bisdt ge sy-datum. "Valid to date

if sy-subrc = 0.

select single kschl from table3

into ls_table2-kschl

where clint = ls_table1-clint.

select imerk lkenz from table4

into corresponding fields of table4

where clint = ls_table1-clint.

check table4-lkenz is initial.

move table4-imerk to ls_table2-imerk.

append ls_table2 to lt_table2.

endselect.

endif.

endloop.

loop at lt_table2 into ls_table2.

clear irec.

move-corresponding ls_table2 to irec.

select atwrt lkenz from table5

into corresponding fields of table5

where objek = ls_table2-objek

and atinn = ls_table2-imerk.

check table5-lkenz is initial.

endselect.

if sy-subrc ne 0.

continue.

endif.

move table5-atwrt to irec-atwrt.

select aatinn aatnam

b~atbez

catzhl cadzhl

into corresponding fields of irec

from table6 as a

inner join table6t as b

on batinn = aatinn

and b~spras = i_spras

inner join table8 as c

on catinn = aatinn

and c~atwrt = table5-atwrt

where a~atinn = ls_table2-imerk.

append irec to itab.

endselect.

endloop.

loop at itab into irec.

clear orec.

move-corresponding irec to orec.

select single atwtb from table8t

into orec-atwtb

where atinn = irec-atinn

and atzhl = irec-atzhl

and spras = i_spras

and adzhl = irec-adzhl.

append orec to o_classtab.

endloop.

This is the logic as per my understanding.

Did it want any changes.Functionality should not vary:-

Please help me in this.

tables: table1,

table2,

table3,

table4,

table5,

table6,

table7,

table8,

table9.

Types: begin of ls_table1 ,

objek like table1-objek,

clint like table1-clint,

lkenz like table1-lkenz,

end of ls_table1.

Data: it_table1 type table of ls_table1 with header line,

wa_table like line of it_table1.

types: begin of ls_table2,

objek like table1-objek,

clint like table1-clint,

klart like table1-klart,

class like table2-class,

kschl like table3-kschl,

imerk like table4-imerk,

end of ls_table2.

data: it_table2 type table of ls_table2 with header line,

wa_table2 like line of it_table2.

data: begin of itab occurs 0,

objek like table1-objek,

clint like table1-clint,

klart like table1-klart,

class like table2-class,

kschl like table3-kschl,

atinn like table8-atinn,

atzhl like table8-atzhl,

adzhl like table8-adzhl,

atwrt like table8-atwrt,

atnam like table6-atnam,

atbez like table7-atbez,

end of itab,

irec like line of itab.

data: begin of orec.

include structure zstru_data.

data: end of orec.

types: begin of ls_table3,

clint like table3-clint,

kschl like table8-kschl,

end of ls_table3.

types: begin of ls_table4,

clint like table4-clint,

imerk like table4-imerk,

lkenz like table4-lkenz,

end of ls_table4.

data: it_table3 type table of ls_table3 with header line,

it_table4 type table of ls_table4 with header line.

select objek clint lkenz from table1

into corresponding fields of wa_table1

where objek = i_matnr.

check wa_table1-lkenz is initial.

append wa_table1 to it_table1.

endselect.

if sy-subrc ne 0.

raise no_material.

endif.

select clint klart class from table2

into table it_table2

where klart = '001'

and statu = '1'

and vondt le sy-datum

and bisdt ge sy-datum.

if sy-subrc = 0.

select clint kschl from table3

into table it_table3

for all entries in it_table1.

if not it_table3 is initial.

sort it_table3 by clint.

endif.

select clint imerk lkenz from table4

into table it_table4

for all entries in it_table1.

if not it_table4 is initial.

sort it_table4 by clint.

endif.

endif.

loop at it_table1.

read table it_table2 with key clint = it_table1-clint

binary search.

if sy-subrc = 0.

read table it_table3 with key clint = it_table1-clint

binary search.

if sy-subrc = 0.

move:it_table3-kschl to it_table2-kschl.

modify it_table2 transporting kschl.

read table it_table4 with key clint = it_table2-clint

binary search.

if sy-subrc = 0.

check it_table4-lkenz is initial.

move: it_table4-imerk to it_table2-imerk.

modify it_table2 transporting imerk.

endif.

endif.

endif.

endloop.

select objek atinn atwrt lkenz

for all entries in it_table2.

from table5

into it_table5

where it_table5-lkenz ='0'.

if sy-subrc = 0.

sort it_table5 by objek attin.

delete adjacent duplicates.

endif.

select aatinn aatnam

b~atbez

catzhl cadzhl

for all entries in it_table1

into table itab

from table6 as a

inner join table7 as b

on batinn = aatinn

and b~spras = i_spras

inner join table8 as c

on catinn = aatinn

and c~atwrt = ausp-atwrt.

loop at it_table2.

read table it_table5 with key objek atinn

where objek = it_table2-objek

atinn = it_table2-atinn

binary search.

if sy-subrc = 0.

read table itab with key atinn

where atinn = it_table2-imerk

binary search.

if sy-subrc = 0.

move: it_table5-atwrt to itab-atwrt.

modify itab transporting atwrt.

endif.

endif.

endloop.

select atinn atzhl adzhl atwtb from table9

into it_table9

where spras = i_spras.

if not it_table9 is initial.

sort it_table9 by atwtb.

delete adjacent duplicates.

endif.

loop at itab into irec.

clear orec.

move-corresponding irec to orec.

read table it_table9 with key atwtb where atinn = irec-atinn

atzhl = irec-atzhl

adzhl = irec-adzhl

binary search.

if sy-subrc = 0.

append orec to o_classtab.

endif.

endloop.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • author's profile photo
    Former Member
    Posted on Aug 08, 2007 at 12:06 PM

    Hi Dipika,

    You have a couple of points to work on, to enhance the performance of this code that you have placed. I have gone through your code and observed these points.

    1) Usage of 'INTO CORRESPONDING FIELDS OF' should be avoided. Instead define the order of the fields of the internal table in the same order of that of the table and use 'INTO TABLE <Internal Table name>.

    2) Avoid using SELECT....ENDSELECT. Try to use SELECT ... INTO TABLE..

    3) Do not use SELECT SINGLE.. or any SELECT... statements within a LOOP ... ENDLOOP. Instead use FOR ALL ENTRIES OF, in the beginning of the code in the SELECT statements and read those tables wherever and whenever needed.

    If you take care of the above points you shall be able to improve code's <b>performance by more than 40%.</b>

    <b>Reward points if this helps,</b>

    Kiran

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 08, 2007 at 12:07 PM

    Hi,

    Dont use select inside the loop. Try to avoid this by using for all entries it will increase your performance.

    Try to follow the following guide line while coding it will boost the performance of your program,

    Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.

    Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.

    Design your Query to Use as much index fields as possible from left to right in your WHERE statement

    Either enable buffering in your database table or create Indexes to speed up the query.

    Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.

    Avoid using nested SELECT statement, SELECT within LOOPs.

    Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.

    Avoid using SELECT * and Select only the required fields from the table.

    Avoid nested loops when working with large internal tables.

    Use assign instead of into in LOOPs for table types with large work areas

    When in doubt call transaction SE30 and use the examples and check your code

    Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search.

    Use "CHECK" instead of IF/ENDIF whenever possible.

    Use "CASE" instead of IF/ENDIF whenever possible.

    Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING", creates more coding but is more effcient.

    Hope it will solve your problem.

    <b>Reward if helpful.</b>

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 08, 2007 at 12:10 PM

    Hi Dipika,

    in extension to the above inputs try finding an alternate solution to using an inner join if it is posssible.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 10:22 AM

    Thanks

    Add comment
    10|10000 characters needed characters exceeded