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

I need help in this code!!

Former Member
0 Likes
763

Hi!

I try to resolve my problem of the performance in my code but is slow yet.

I put here my selects and loops to see if someone know a way to make a better performance.

Thanks!!


  SELECT ryear rpmax rtcur racct rbukrs prctr
         kslvt ksl01 ksl02 ksl03 ksl04 ksl05
         ksl06 ksl07 ksl08 ksl09 ksl10 ksl11
         ksl12 ksl13 ksl14 ksl15 ksl16
     FROM faglflext
     INTO CORRESPONDING FIELDS OF TABLE t_itab1
    WHERE  ryear eq p_date+0(4)
       and rldnr  eq '0L'
       AND rbukrs IN p_bukrs.

DELETE ADJACENT DUPLICATES FROM t_itab1.
DELETE t_itab1 where racct = ''.  "I put this because in the mandant exist records with the account empty.
sort t_itab1 by prctr ascending.
  READ TABLE t_itab1 INTO wa_low INDEX 1.
  DESCRIBE TABLE t_itab1 LINES firstline.
  READ TABLE t_itab1 INTO wa_high INDEX firstline.

  profit-sign    = 'I'.
  profit-option  = 'BT'.
  profit-low     = wa_low-prctr.
  profit-high    = wa_high-prctr.
  APPEND profit.

clear wa_low.
clear wa_high.
sort t_itab1 by racct ascending.
  READ TABLE t_itab1 INTO wa_low INDEX 1.
  DESCRIBE TABLE t_itab1 LINES firstline.
  READ TABLE t_itab1 INTO wa_high INDEX firstline.

  account-sign    = 'I'.
  account-option  = 'BT'.
  account-low     = wa_low-racct.
  account-high    = wa_high-racct.
  APPEND account.

  SELECT day_a racct prctr per_day average agregate 
         accumulate average_sap
    FROM zavg_bal_table INTO TABLE t_zavg
    WHERE bukrs in p_bukrs
     AND  prctr IN profit
     AND  day_a = p_date.

  SELECT ktopl saknr txt20
     FROM skat INTO  TABLE it_skat
         WHERE spras EQ sy-langu
         AND ktopl EQ 'CAPI'
         AND saknr in account.

  SORT t_itab1 BY racct prctr.
  SORT t_zavg BY racct prctr.

  LOOP AT t_itab1 INTO wa_itab where racct  NE ''.

    READ TABLE t_zavg INTO wa_zavg WITH KEY racct =   
                             wa_itab-racct  prctr =
                             wa_itab-prctr day_a = 
                             p_date binary search.

    READ TABLE it_skat WITH TABLE KEY saknr = wa_itab-
                                                racct .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
727

Carlos,

Individually set breakpoints on all the database selects in your program. Later use ST05 transaction, to start a trace and stop the trace after it executes a SELECT statement. We can then investigate what is going on, in terms of

a. whether the right index is used or

b. if records are read sequentially etc

6 REPLIES 6
Read only

Former Member
0 Likes
728

Carlos,

Individually set breakpoints on all the database selects in your program. Later use ST05 transaction, to start a trace and stop the trace after it executes a SELECT statement. We can then investigate what is going on, in terms of

a. whether the right index is used or

b. if records are read sequentially etc

Read only

Former Member
0 Likes
727

Hi Carlos - you might find you get more help if you started closing the other threads you have open on this and other subjects.

The only problem I see here is the last part (and only if it_skat is a standard table):


  LOOP AT t_itab1 INTO wa_itab where racct  NE ''.
 
    READ TABLE t_zavg INTO wa_zavg WITH KEY racct =   
                             wa_itab-racct  prctr =
                             wa_itab-prctr day_a = 
                             p_date binary search.
 
    READ TABLE it_skat WITH TABLE KEY saknr = wa_itab-
                                                racct .

Change it to


<b>  SORT it_skat by saknr.</b>
    LOOP AT t_itab1 INTO wa_itab where racct  NE ''.
 
    READ TABLE t_zavg INTO wa_zavg WITH KEY racct =   
                             wa_itab-racct  prctr =
                             wa_itab-prctr day_a = 
                             p_date binary search.
 
    READ TABLE it_skat WITH TABLE KEY saknr = wa_itab-
                                                racct 
      BINARY SEARCH.

What are the key fields of tables faglflext and zavg_bal_table (primary and secondary)? And how large are they?

Rob

Read only

Former Member
0 Likes
727

Hi , ROB:

Yes I try know to close all my message jeje, know, the Faglflext have this key fields: RCLNT, RYEAR, OBJNR00 and other but the fields that the funtional needs are not key fields and this is my problem. With the other table zavg_bal_table I don't have much problems because I use the key fields.

I use the sorts before the loops for the tree tables and now the execution is better from one day to 41 secs.

I see now if exist some others things that I can correct to make a better performance.

Thanks!

Read only

0 Likes
727

Are there secondary indexes on this table?

Rob

Read only

Former Member
0 Likes
727

No Rob.

Thanks!

Read only

0 Likes
727

Well then, if you got it down from a day to less than a minute, I'd give it a rest. If the users insist, then you might look for a way to get the keys before going to this table.

Also, as I said eariler, make sure the read on it_skat is searching efficiently.

Rob