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

Former Member
0 Kudos

Hi ppl,

Am facing a problem wherin i need to process records inside an internal table which itself has huge number of records(say m).The details of each record is picked using loop on one more itab which also consists of huge number of records

(say n). hence the processing is for m*n records which is raising performance issue.

plz help.am pasting the code here.

FORM PROCESS_UNITS.

DATA : VL_TEXT(40) TYPE C.

SORT T_UNITS BY UNIT.

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. "GK_166118

SORT T_GLPCA BY AWTYP AWORG REFDOCNR. "1062

  • process GLPCA postings

LOOP AT T_GLPCA.

  • translate document number

IF T_GLPCA-AWTYP = 'BKPF' AND T_GLPCA-AWORG(4) = P_BUKRS."1062

ELSE. "1062

CALL FUNCTION 'Z_FIND_FIDOC' "1062

EXPORTING "1062

I_AWTYP = T_GLPCA-AWTYP "1062

I_AWORG = T_GLPCA-AWORG "1062

I_BUKRS = P_BUKRS "1062

I_GJAHR = P_GJAHR "1062

I_REFDOCNR = T_GLPCA-REFDOCNR "1062

IMPORTING "1062

E_FIDOCNR = T_GLPCA-REFDOCNR. "1062

ENDIF. "1062

  • at new refdocnr.

CLEAR BKPF-BLART.

SELECT SINGLE BLART BUDAT MONAT FROM BKPF

INTO (BKPF-BLART, BKPF-BUDAT, BKPF-MONAT)

WHERE BUKRS = P_BUKRS

AND BELNR = T_GLPCA-REFDOCNR

AND GJAHR = P_GJAHR.

  • endat.

  • IF ( BKPF-BLART = 'YF' AND T_GLPCA-RACCT IN R_HKONT1 "GK_166118

  • AND NOT R_HKONT1[] IS INITIAL ) "GK_166118

*OR ( BKPF-BLART = 'ZW' AND T_GLPCA-RACCT IN R_HKONT2 "GK_166118

  • AND NOT R_HKONT2[] IS INITIAL ). "GK_166118

IF BKPF-BLART IN R_BLART . "GK_151204

PERFORM ADD_TO_CORRECT_COLUMN USING T_GLPCA-HSL

BKPF-MONAT.

  • collect weekly data

CLEAR WEEKLY_ITAB.

WEEKLY_ITAB-MONAT = BKPF-MONAT.

WEEKLY_ITAB-BUDAT = BKPF-BUDAT.

WEEKLY_ITAB-PRCTR = T_UNITS-UNIT.

WEEKLY_ITAB-KTEXT = T_UNITS-UNIT_TEXT.

WEEKLY_ITAB-DMBTR = T_GLPCA-HSL.

COLLECT WEEKLY_ITAB.

ENDIF.

ENDLOOP.

  • get site

SELECT SINGLE KHINR FROM CEPC INTO T_UNITS-SITE_REF

WHERE PRCTR = T_UNITS-UNIT

AND KOKRS = V_KOKRS

AND DATBI = '99991231'.

MODIFY T_UNITS INDEX V_TABIX.

ENDLOOP.

ENDFORM. " PROCESS_UNITS

thanks in advance.

Archana

6 REPLIES 6

Former Member
0 Kudos

Hi,

Use parallal cursor approach.

Reward points if helpful.

Regards.

Srikanta Gope.

0 Kudos

Hi Srikanta,

Can u please put some points to explain parallel cursor apporach.I am not aware of this.

Thanks,

Archana

Former Member
0 Kudos

Hi Archana,

Yes, You are selectiong data into loop.

I would suggest you to collect data first and then process into an internal tables,

like for e.q:

Select data:

1. select * from A into table it_A where...

2. select * from B into table it_B for all entries in it_A where ....

Collect data:

sort tables.

loop at it_A

read table it_B key....

store data into it_ouptut.

endloop.

Reward if useful!

Former Member
0 Kudos

U have entries in t_unit.

To get data in T_GLPCA

use For all entries in t_unit. before the loops.

  • get GLPCA postings

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

INTO TABLE T_GLPCA

for all entreis in t_unit

WHERE RPRCTR = T_UNITS-UNIT

AND RACCT IN S_HKONT

AND KOKRS = V_KOKRS

AND RYEAR = P_GJAHR

AND POPER <= P_MONAT

Then u can loop for t_GLPCA alone. no need for loop at t_unit ...

0 Kudos

Hi,

thanks for the reply.But aggregate functions like sum is not allowed 'for all entries'

i took this approach but still not working.

FORM PROCESS_UNITS.

DATA : VL_TEXT(40) TYPE C,

t_hsl like glpca-hsl.

SELECT rprctr AWTYP AWORG RACCT REFDOCNR HSL FROM GLPCA "1062

INTO T_GLPCA

For all entries in t_units "Archana G Joshi180707

WHERE RPRCTR = T_UNITS-UNIT

AND RACCT IN S_HKONT

AND KOKRS = V_KOKRS

AND RYEAR = P_GJAHR

AND POPER <= P_MONAT.

endselect.

  • GROUP BY AWTYP AWORG RACCT REFDOCNR. "GK_166118

SORT T_GLPCA BY AWTYP AWORG REFDOCNR. "1062

DELETE ADJACENT DUPLICATES FROM t_units.

loop at t_glpca.

v_tabix = sy-tabix.

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

modify t_glpca index v_tabix.

endloop.

  • process GLPCA postings

LOOP AT T_GLPCA.

  • translate document number

IF T_GLPCA-AWTYP = 'BKPF' AND T_GLPCA-AWORG(4) = P_BUKRS."1062

ELSE. "1062

CALL FUNCTION 'Z_FIND_FIDOC' "1062

EXPORTING "1062

I_AWTYP = T_GLPCA-AWTYP "1062

I_AWORG = T_GLPCA-AWORG "1062

I_BUKRS = P_BUKRS "1062

I_GJAHR = P_GJAHR "1062

I_REFDOCNR = T_GLPCA-REFDOCNR "1062

IMPORTING "1062

E_FIDOCNR = T_GLPCA-REFDOCNR. "1062

ENDIF. "1062

  • at new refdocnr.

CLEAR BKPF-BLART.

SELECT SINGLE BLART BUDAT MONAT FROM BKPF

INTO (BKPF-BLART, BKPF-BUDAT, BKPF-MONAT)

WHERE BUKRS = P_BUKRS

AND BELNR = T_GLPCA-REFDOCNR

AND GJAHR = P_GJAHR.

  • endat.

  • IF ( BKPF-BLART = 'YF' AND T_GLPCA-RACCT IN R_HKONT1 "GK_166118

  • AND NOT R_HKONT1[] IS INITIAL ) "GK_166118

*OR ( BKPF-BLART = 'ZW' AND T_GLPCA-RACCT IN R_HKONT2 "GK_166118

  • AND NOT R_HKONT2[] IS INITIAL ). "GK_166118

IF BKPF-BLART IN R_BLART . "GK_151204

PERFORM ADD_TO_CORRECT_COLUMN USING T_GLPCA-HSL

BKPF-MONAT.

loop at t_units where unit = t_glpca-rprctr.

  • collect weekly data

CLEAR WEEKLY_ITAB.

WEEKLY_ITAB-MONAT = BKPF-MONAT.

WEEKLY_ITAB-BUDAT = BKPF-BUDAT.

WEEKLY_ITAB-PRCTR = T_UNITS-UNIT.

WEEKLY_ITAB-KTEXT = T_UNITS-UNIT_TEXT.

WEEKLY_ITAB-DMBTR = T_GLPCA-HSL.

endloop.

COLLECT WEEKLY_ITAB.

ENDIF.

ENDLOOP.

LOOP at t_units.

v_tabix = sy-tabix.

  • get site

SELECT SINGLE KHINR FROM CEPC INTO T_UNITS-SITE_REF

WHERE PRCTR = T_UNITS-UNIT

AND KOKRS = V_KOKRS

AND DATBI = '99991231'.

MODIFY T_UNITS INDEX V_TABIX.

endloop.

0 Kudos

Hi,

I = 1.

LOOP AT ITAB1 INTO WA1.

LOOP AT ITAB2 INTO WA2 FROM I.

IF WA2-K <> WA1-K.

I = SY-TABIX.

EXIT.

ENDIF.

" ...

ENDLOOP.

ENDLOOP.

Try this method,the parallel cursor method to improve the performance of ur loops.

regards,

Reema.