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.
cancel
Showing results for 
Search instead for 
Did you mean: 

Performance question.

Former Member
0 Kudos

Hi people!

I'm confuse here! I need to compute the balance of some months in a program for the GL module. I use the table faglflext to make that, but I need good performance and I don't know if I make the code correct or I need to change it to take a better performance. Some one can check that! Thanks!

Code:


  LOOP AT t_itab1 INTO wa_itab WHERE racct  NE ''.

    itab_kslvt = itab_kslvt + wa_itab-kslvt. 
    itab_ksl01 = itab_ksl01 + wa_itab-ksl01. 
    itab_ksl02 = itab_ksl02 + wa_itab-ksl02.
    itab_ksl03 = itab_ksl03 + wa_itab-ksl03. 
    itab_ksl04 = itab_ksl04 + wa_itab-ksl04.
    itab_ksl05 = itab_ksl05 + wa_itab-ksl05. 
    itab_ksl06 = itab_ksl06 + wa_itab-ksl06.
    itab_ksl07 = itab_ksl07 + wa_itab-ksl07. 
    itab_ksl08 = itab_ksl08 + wa_itab-ksl08.
    itab_ksl09 = itab_ksl09 + wa_itab-ksl09. 
    itab_ksl10 = itab_ksl10 + wa_itab-ksl10.
    itab_ksl11 = itab_ksl11 + wa_itab-ksl11. 
    itab_ksl12 = itab_ksl12 + wa_itab-ksl12.

        IF p_date+4(2) >= '01'.

          COMPUTE: balance_month_01 =   itab_bal00 + itab_bal01.

        ENDIF.

        IF p_date+4(2) >= '02'.

          COMPUTE: balance_month_02 = itab_bal00 + itab_bal01 + itab_bal02.

        ENDIF.

        IF p_date+4(2) >= '03'.

          COMPUTE: balance_month_03 = itab_bal00 + itab_bal01 + itab_bal02 + 
                                                           itab_bal03.

        ENDIF.

        IF p_date+4(2) >= '04'.

          COMPUTE: balance_month_04 = itab_bal00 + itab_bal01 + itab_bal02 + 
                                                           itab_bal03 + itab_bal04.

        ENDIF.

        IF p_date+4(2) >= '05'.

          COMPUTE: balance_month_05 = itab_bal00 + itab_bal01 + itab_bal02 + 
                                                           itab_bal03 + itab_bal04 + itab_bal05.

        ENDIF.

        IF p_date+4(2) >= '06'.

          COMPUTE: balance_month_06 =  itab_bal00 + itab_bal01 + itab_bal02 + 
                                                            itab_bal03 + itab_bal04 + itab_bal05 + 
                                                            itab_bal06.

        ENDIF.

        IF p_date+4(2) >= '07'.

          COMPUTE: balance_month_07 =  itab_bal00 + itab_bal01 + itab_bal02 + 
                                                            itab_bal03 + itab_bal04 + itab_bal05 + 
                                                            itab_bal06 + itab_bal07.

        ENDIF.

        IF p_date+4(2) >= '08'.

          COMPUTE: balance_month_08 =  itab_bal00 + itab_bal01 + itab_bal02 + 
                                                            itab_bal03 + itab_bal04 + itab_bal05 + 
                                                            itab_bal06 + itab_bal07 + itab_bal08.

        ENDIF.

        IF p_date+4(2) >= '09'.

          COMPUTE: balance_month_09 =  itab_bal00 + itab_bal01 + itab_bal02 + 
                                                            itab_bal03 + itab_bal04 + itab_bal05 +   
                                                            itab_bal06 + itab_bal07 + itab_bal08 + 
                                                            itab_bal09.

        ENDIF.

        IF p_date+4(2) >= '10'.

          COMPUTE: balance_month_10 =  itab_bal00 + itab_bal01 + itab_bal02 + 
                                                            itab_bal03 + itab_bal04 + itab_bal05 + 
                                                            itab_bal06 + itab_bal07 + itab_bal08 + 
                                                            itab_bal09 + itab_bal10.

        ENDIF.

        IF p_date+4(2) >= '11'.

          COMPUTE: balance_month_11 = itab_bal00 + itab_bal01 + itab_bal02 + 
                                                           itab_bal03 + itab_bal04 + itab_bal05 + 
                                                           itab_bal06 + itab_bal07 + itab_bal08 + 
                                                           itab_bal09 + itab_bal10 + itab_bal11.

        ENDIF.

        IF p_date+4(2) >= '12'.

          COMPUTE: balance_month_12 =  itab_bal00 + itab_bal01 + itab_bal02 + 
                                                            itab_bal03 + itab_bal04 + itab_bal05 + 
                                                            itab_bal06 + itab_bal07 + itab_bal08 + 
                                                            itab_bal09 + itab_bal10 + itab_bal11 + 
                                                            itab_bal12.

        ENDIF.

endloop.

7 REPLIES 7

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Maybe you could try to get rid of the records that you don't want to process before the LOOP.

* Delete all unwanted records here.
 delete t_itab1 where racct <> space.


  LOOP AT t_itab1 INTO wa_itab.     "<- get rid of the WHERE clause

Regards,

Rich Heilman

0 Kudos

Also, using field symbols, might help as well.

field-symbols: <fs> like line of t_itab1.



loop at t_itab1 assigning <fs>.


endloop.

Regards,

Rich Heilman

Former Member
0 Kudos

Besides you can use CASE instead of IF/ENDIF

Please go through this,

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/abapPerformanceand+Tuning&

Regards

Kathirvel

Former Member
0 Kudos

You can always increase performance, but there comes a point where the extra work isn't worth it, so I wouldn't bother with it.

However, there seems to me to be a logic error:


IF p_date+4(2) >= '01'.
  COMPUTE: balance_month_01 =   itab_bal00 + itab_bal01.
ENDIF.

ELSEIF p_date+4(2) >= '02'.                <=====
  COMPUTE: balance_month_02 = itab_bal00 + itab_bal01 +
itab_bal02.
ENDIF.

(Which will help performance).

Rob

Message was edited by:

Rob Burbank

Former Member
0 Kudos

Hi Carlos,

have a look at this, for sure faster:

...

IF p_date+4(2) >= '01'.
 
          COMPUTE: balance_month_01 =   itab_bal00 + itab_bal01.
 
        ENDIF.
 
        IF p_date+4(2) >= '02'.
 
          COMPUTE: balance_month_02 = balance_month_01 + itab_bal02.
 
        ENDIF.
 
        IF p_date+4(2) >= '03'.
 
          COMPUTE: balance_month_03 = balance_month_02  + itab_bal03.
 
        ENDIF.
 
        IF p_date+4(2) >= '04'.
 
          COMPUTE: balance_month_04 = balance_month_03  + itab_bal04.
 
        ENDIF.
 
        IF p_date+4(2) >= '05'.
 
          COMPUTE: balance_month_05 = balance_month_04  + itab_bal05.
 
        ENDIF.
 
        IF p_date+4(2) >= '06'.
 
          COMPUTE: balance_month_06 =  balance_month_05  + itab_bal06.
 
        ENDIF.
 
        IF p_date+4(2) >= '07'.
 
          COMPUTE: balance_month_07 =  balance_month_06  + itab_bal07.
 
        ENDIF.
 
        IF p_date+4(2) >= '08'.
 
          COMPUTE: balance_month_08 =  balance_month_07  + itab_bal08.
 
        ENDIF.
 
        IF p_date+4(2) >= '09'.
 
          COMPUTE: balance_month_09 =  balance_month_08 + itab_bal09.
 
        ENDIF.
 
        IF p_date+4(2) >= '10'.
 
          COMPUTE: balance_month_10 =  balance_month_09  + itab_bal10.
 
        ENDIF.
 
        IF p_date+4(2) >= '11'.
 
          COMPUTE: balance_month_11 = balance_month_11  + itab_bal11.
 
        ENDIF.
 
        IF p_date+4(2) >= '12'.
 
          COMPUTE: balance_month_12 =  balance_month_12  +  itab_bal12.
 
        ENDIF.

obviously at the beginning set balance_month_1 ... balance_month_12 to 0

and another thing is this:

       IF p_date+4(2) >= '01'.
 
          COMPUTE: balance_month_01 =   itab_bal00 + itab_bal01.
        ELSE.
CONTINUE.
        ENDIF.
        IF p_date+4(2) >= '02'.
          COMPUTE: balance_month_02 = itab_bal00 + itab_bal01 + itab_bal02.
        ENDIF.

if pdate is not greater that 01 for sure is not as well greater then 02 so skip all the checks and go on using CONTINUE.

Hope it helps.

Regards,

Sergio

Former Member
0 Kudos

What is better if I don't want to take an empty field.

Check the field in the select or delete the records that exist in the internal table that have the field empty?

0 Kudos

Since this seems like a separate question, why not close this post (if answered) and start a new one?

Rob