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 Optimization

Former Member
0 Likes
626

Hi Master's,

Can any one please guide me?

How to optimize the following code,

v_cond = 'MWST'.
perform seg_value using v_cond.
v_cond = 'ZAO1'.
perform seg_value using v_cond.
v_cond = 'ZAO2'.
perform seg_value using v_cond.
v_cond = 'ZAD3'.
perform seg_value using v_cond.
v_cond = 'ZADD'.
perform seg_value using v_cond.
.
.
. It goes like this....

Form seg_value using v_cond_type.
CLEAR: v_frt,int_edidd, int_z1eds02.
  LOOP AT i_cond WHERE  kschl = v_cond_type.
    v_frt = v_frt + i_cond-kwert.
  ENDLOOP.
  CASE l_tcurx.
    WHEN 0.
      int_z1eds02-summe = v_frt * 100.
    WHEN 1.
      int_z1eds02-summe = v_frt * 10.
    WHEN 2.
      int_z1eds02-summe = v_frt.
    WHEN 3.
      int_z1eds02-summe = v_frt / 10.
    WHEN 4.
      int_z1eds02-summe = v_frt / 100.
    WHEN 5.
      int_z1eds02-summe = v_frt / 1000.
  ENDCASE.
  SELECT SINGLE * FROM t685t WHERE spras = 'E' AND kschl = v_cond_type.
  int_z1eds02-kotxt = t685t-vtext.
  CONDENSE int_z1eds02-summe NO-GAPS.
  int_z1eds02-sumid = v_cond_type.
  int_edidd-segnam = 'Z1EDS02'.
  int_edidd-sdata = int_z1eds02.
  IF v_frt <> 0.
    APPEND int_edidd.
  ENDIF.
endform.

Edited by: sai.bala on Sep 4, 2010 2:56 PM

Edited by: sai.bala on Sep 4, 2010 2:58 PM

Edited by: sai.bala on Sep 4, 2010 2:58 PM

Edited by: Thomas Zloch on Sep 4, 2010 9:53 PM

4 REPLIES 4
Read only

ThomasZloch
Active Contributor
0 Likes
591

Optimize in what respect, apart from adding code tags (now done)?

Thomas

Read only

Former Member
0 Likes
591

why do you want to optimize? Is it slow? How slow?

Read only

ravi_lanjewar
Contributor
0 Likes
591

Hi,


 LOOP AT i_cond WHERE  kschl = v_cond_type.
    v_frt = v_frt + i_cond-kwert.
  ENDLOOP.

Define i_cond table as sorted table with non-unique key kschl.


  SELECT SINGLE * FROM t685t WHERE spras = 'E' AND kschl = v_cond_type.
  int_z1eds02-kotxt = t685t-vtext.

You can make changes as follows


Define it_t685t as hashed table with unique key kschl.
clear wa_int_t685t.
Read table it_t685t into wa_t685t with table key kschl = v_cond_type.
if sy-subrc ne 0.
  SELECT SINGLE kschl  vtext into wa_t685t
 FROM t685t WHERE spras = 'E' AND kschl = v_cond_type.
 insert wa_t685t into table it_t685t.
endif
int_z1eds02-kotxt = t685t-vtext

Read only

Former Member
0 Likes
591

@Ravishankar,

please ask before you recommend something which might be wrong!!!

LOOP AT i_cond

i_cond is probably very small, no optimization necessary

t685t is a buffered table, there is no hashed table copy necessary, the SELOECT SINGLE is fine !!!

I would that there is not performance problem at all, the code was only found be some useless code inspection!

So please analyse before you want to change

Siegfried