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: 

LOOP inside loop -performance issue.

Former Member
0 Kudos

hi ppl,

I want to put the select query mentioned below outside the loop to resolve performance issue. The 'for all entries' does not support aggregate functions like 'sum' and 'group by'. plz have a look at my approach and suggest some changes.

the code:

LOOP AT T_UNITS.

V_TABIX = SY-TABIX.

CONCATENATE TEXT-S01 T_UNITS-UNIT INTO VL_TEXT SEPARATED BY ' '.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'

EXPORTING

  • PERCENTAGE = 0

TEXT = VL_TEXT.

  • get GLPCA postings

SELECT AWTYP AWORG RACCT REFDOCNR SUM( HSL ) FROM GLPCA "1062

INTO TABLE T_GLPCA

WHERE RPRCTR = T_UNITS-UNIT

AND RACCT IN S_HKONT

AND KOKRS = V_KOKRS

AND RYEAR = P_GJAHR

AND POPER <= P_MONAT

GROUP BY AWTYP AWORG RACCT REFDOCNR.

lopp at t_glpca.

...

...

endloop.

endloop.

my approach:

all this put outside the loop 'loop at t_units'.

SELECT rprctr AWTYP AWORG RACCT REFDOCNR HSL FROM GLPCA "1062

INTO TABLE T_GLPCA

For all entries in t_units

WHERE RPRCTR = T_UNITS-UNIT

AND RACCT IN S_HKONT

AND KOKRS = V_KOKRS

AND RYEAR = P_GJAHR

AND POPER <= P_MONAT.

loop at t_glpca.

v_tabix = sy-tabix.

select sum( hsl ) from glpca into t_glpca-hsl.

modify t_glpca index v_tabix.

endloop.

The select query 'select sum( hsl ) from glpca into t_glpca-hsl' is consuming lot of time.

thanks in advance

Archana

6 REPLIES 6

Former Member
0 Kudos

Hi archna,

Is this program working fine.

From your code it seems that in table t_glpca and the column hsl

you are putting same value i mean to say sum value.

why are u doing like that.

Wat exactly ur requirment is?

Just explain.

Regards

Azad.

0 Kudos

hi ,

u can use sum function while displaying also .

u have selected some values into itab na .aftyer that use the below code.

loop at itab.

at end of <fielname>.

sum.

write:/ itab-<fieldname>.

endat.

like this also u can some .so u can use for all entries in select statement .

hopw it's usefull for u .

or use

on change of <fielname>

endon.

instead of at endof.

EXAMPLE CODE

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

0 Kudos

Hi Azad,

Yep i dont need sum there.

Thanks for the response i removed the code.But i somehow want to improve the performance of the program but avoiding loop inside loop.

Regards,

Archana

0 Kudos

hi.... u can use read table

please reward points if it was of help

0 Kudos

Hi Archana,

Use Read statement instead the loop instead of loop statement.

Regards

Arun

Former Member
0 Kudos

.

Message was edited by:

Arun Shekhar