LOOP inside loop -performance  issue.

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

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.

Similar Messages

  • Loop Inside loop, time out error.

    Pls look into the below code, In this im looping inside a loop.
    Im looping thru the internal table( say 2000 records ) which has data from a select query, inside this loop  i need to calculate the total of output qty which is available in the another VIEW/TABLE which might return 10 records in each  iteration of the inner loop.
    This process takes huge time to process also gives out runtime out error.
    pls help.
    LOOP AT itablnpln INTO walnpln.
    contot = 0.
    This particular query loop takes large time to process
    SELECT distinct * INTO CORRESPONDING FIELDS OF TABLE itablnp
    FROM zvprdconf where aufnr = walnpln-aufnr and
    j_3asize = walnpln-j_3akordx and stzhl eq ' ' and stokz ne 'X'.
    IF sy-subrc EQ 0.
    *Earlier i used this looping.
    *loop at itablnp into walnp.
    contot = contot + walnp-J_3ALMNGA.
    move walnp-J_3ASIZE to walnpln-J_3ASIZE.
    endloop.
    *Currently tried with the following,
    LOOP AT itablnp ASSIGNING <fs_itablnp>.
    contot = contot + <fs_itablnp>-J_3ALMNGA.
    move <fs_itablnp>-J_3ASIZE to walnpln-J_3ASIZE.
    ENDLOOP.
    walnpln-output = contot.
    move zvprdconf-isdd to walnpln-zdate.
    move zvprdconf-isdz to walnpln-ztime.
    endif.
    ENDLOOP.
    regs,
    Raja

    Dear Naresh,
    Even after changing the code as below, i m getting the same error.pls help.
    IF SY-SUBRC = 0.
       SORT ITABLNPLN.
       DELETE ADJACENT DUPLICATE FROM ITABLNPLN COMPARING ALL FIELDS.
    ENDIF.
    pls find the complete code as below.
    code]
    *& Report  SAPMZLINEPLANRPT
    INCLUDE ZLPR_TOP.
    *Event AT Selection-Screen on Block Param.
    AT SELECTION-SCREEN ON BLOCK sorter.
      CHECK All = 'X'.
    *Event Start-Of-Selection.
    START-OF-SELECTION.
      Data: zstat type jest-stat.
      data: stklocaf type mska-lgort.
      data: stklocas type mska-lgort.
      FIELD-SYMBOLS <fs_itablnp> LIKE LINE OF itablnp.
      CLEAR it_ZVPRODDET.
      SELECT DISTINCT ZVPODbukrs ZVPODaufnr ZVPOD~objnr
      jeststat ZVPODwerks ZVPODarbpl ZVPODJ_3AKORD2
      zvpodplnbez zvpodaufnr zvpodkdauf zvpodkdpos
      zvpodj_3akord1 zvpodj_3akord2 zvpod~j_3akordx
      zvpodj_3absnr zvpodmatnr zvpod~j_4kscat
      zvpodmvgr4 zvpodj_3acada zvpodj_4krcat zvpodmenge
      zvpodposnr zvpodkunnr zvpodaufpl zvpodaplzl
      zvpodplnnr zvpodarbid zvpodsteus zvpodbismt
      zvpodwerks zvpodj_3akvgr6 zvpod~j_3arqda
      zvpodmvgr5 zvpodaudat zvpod~j_3addat
      zvpodvtweg zvpodobjnr zvpod~bukrs
      zvpodfsavd zvpodssavd zvpod~bstkd
      zvpodbstdk zvpodihrez zvpod~bstkd_e
      zvpodbstdk_e zvpodihrez_e zvpod~arbpl
      zvpodvgw01 zvpodkvgr2 zvpod~vsart
      FROM  ZVPOD
      INNER JOIN jest ON ZVPODobjnr = jestobjnr
      INTO CORRESPONDING FIELDS OF table it_ZVPRODDET where
      plnbez in FGM and arbpl in wc and werks in plant
      and SSAVD in eldate
      and J_3AKORD2 in cups and jest~inact ne 'X'.
      SORT it_ZVPRODDET BY aufnr stat.
      LOOP AT it_ZVPRODDET INTO wa_ZVPRODDET.
        IF wa_ZVPRODDET-stat = 'I0045' .  " TECO - compl
          DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr.
        ELSEIF wa_ZVPRODDET-stat = 'I0009' .  " CNF - Confirmed
          DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr.
        ELSEIF wa_ZVPRODDET-stat = 'I0012' .  " DLV - Delivered
          DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr.
        ELSEIF wa_ZVPRODDET-stat = 'I0046' .  " CLSD - Closed
          DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr.
        ELSEIF wa_ZVPRODDET-stat = 'I0076' .  " DLFL - Del Flag
          DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr.
        ELSEIF wa_ZVPRODDET-stat = 'E0003' .  " SCLS - Short Close
          CLEAR tj30t.
          SELECT SINGLE txt04
          FROM tj30t INTO tj30t-txt04
          WHERE stsma = 'PRDHOLD' AND
                estat = 'E0003' AND
                txt04 = 'SCLS' AND
                spras = 'EN'.
          IF sy-subrc = 0.
            DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr.
          ENDIF.
        ENDIF.
      Condition for Prod Order released - REL
        IF wa_ZVPRODDET-stat = 'I0002'.
          mreleased = 'Y'.
        else.
          mreleased = 'N'.
        endif.
        zstat = wa_ZVPRODDET-stat.
        IF mreleased = 'N'.
          DELETE it_ZVPRODDET WHERE aufnr = wa_ZVPRODDET-aufnr
          and stat = zstat.
        ENDIF.
      ENDLOOP.
      case mark.
        when All.
          LOOP AT it_ZVPRODDET INTO wa_ZVPRODDET.
            zaufnr = wa_zvproddet-aufnr.
            zarbid = wa_zvproddet-arbid.
            move wa_zvproddet to walnpln.
            append walnpln to itablnpln.
          endloop.
          clear walnpln.
          if not itablnpln is initial.
            SELECT distinct * INTO CORRESPONDING FIELDS OF TABLE itablnp
            FROM zvprdconf FOR ALL ENTRIES IN itablnpln
            where aufnr = itablnpln-aufnr and
            j_3asize = itablnpln-j_3akordx and stzhl eq ' ' and stokz ne 'X'.
            if sy-subrc = 0.
              sort itablnpln by aufnr j_3asize.
              DELETE ADJACENT DUPLICATES FROM ITABLNPLN COMPARING ALL     FIELDS.
            endif.
          endif.
          LOOP AT itablnpln  INTO walnpln.
            contot = 0.
            IF sy-subrc EQ 0.
              LOOP AT itablnp ASSIGNING <fs_itablnp> where aufnr = walnpln-aufnr and j_3asize = walnpln-j_3akordx.
                contot = contot + <fs_itablnp>-J_3ALMNGA.
                move <fs_itablnp>-J_3ASIZE to walnpln-J_3ASIZE.
              ENDLOOP.
              walnpln-output = contot.
              move zvprdconf-isdd to walnpln-zdate.
              move zvprdconf-isdz to walnpln-ztime.
            endif.
            walnpln-wip = walnpln-menge - contot.
            if walnpln-werks = '1000'.
              stklocaf = '1050'.
              stklocas = '1060'.
            elseif walnpln-werks = '2000'.
              stklocaf = '2150'.
              stklocas = '2160'.
            endif.
            select single kunnr into walnpln-ship from vbpa where
            vbeln = walnpln-KDAUF and PARVW = 'WE'.
            zship = walnpln-ship.
            move zship to walnpln-ship.
            select  single kalab into walnpln-zactqty from mska
            where matnr = walnpln-plnbez
            and j_3asize = walnpln-J_3AKORDX and LGORT = stklocaf.
            condense walnpln-kdauf.
            zsales = walnpln-kdauf.
            concatenate zsales 'S' into zso.
            select single kalab into walnpln-zsndqty from mska
            where matnr = walnpln-plnbez
            and j_3asize = walnpln-J_3AKORDX and LGORT = stklocas
            and J_4KSCAT = zso.
            zmatn = walnpln-plnbez.
            zsale = walnpln-KDAUF.
            walnpln-kdauf = zsale.
            walnpln-plnbez = zmatn.
            zcust = walnpln-kunnr.
            walnpln-kunnr = zcust.
            select single bezei into walnpln-season from TVV2T where
            kvgr2 = walnpln-kvgr2 and SPRAS = 'E'.
            select single bezei into walnpln-shipmode from T173T where
            vsart = walnpln-vsart and SPRAS = 'E'.
            STRL = strlen( walnpln-j_3akord2 ).
            if  strl = 4.
              move walnpln-j_3akord2 to walnpln-j_3akord3.
              clear walnpln-j_3akord2.
            endif.
            move zremk to walnpln-remk.
            MODIFY itablnpln FROM  walnpln.
            contot = 0.
            clear itablnp.
          ENDLOOP.
          PERFORM build_fieldcatalog.
          PERFORM build_layout.
          PERFORM display_alv_report.
      endcase.
    [/code]
    regs,
    raja[

  • Confusion in loop inside loop

    Hi Experts,
    i have some confution in below code:
    here am trying to calculate  Actual Billing and Planned Revenue. but here for each value am looping it_final table inside the main loop.
    but the prob is if i loop it_final for one value it is giving value, but if i try to loop 2 times for 2 values, it is not giving first value also.  
    i.e if i comment loop for Planned Revenue then Actual Billing is displaying, if i try for 2 values, then its giving zeros for 2 values.
    so could anyone check is there any mistake i did.
    CLEAR: it_prps, it_final, wa_final, wa_it_prps.
      LOOP AT it_prps.
        CASE month.
          WHEN '08'.
      ACTUAL BILLING
            LOOP AT it_final INTO wa_final
             WHERE posid = it_prps-posid
                AND wrttp = c_04
                AND beltp = c_02
                AND versn = c_0
                AND ( vorga = c_coin OR vorga = c_rku2 ).
              CLEAR act_billing.
              IF sy-subrc IS INITIAL.
                MOVE wa_final-wlp08 TO t_act_billing.
                act_billing = act_billing + t_act_billing.
              ENDIF.
              CLEAR: it_prps, it_final.
            ENDLOOP.
    *************PLANNED REVENUE
            LOOP AT it_final INTO wa_final
                             WHERE posid = it_prps-posid
                             AND wrttp = c_01
                             AND beltp = c_02
                             AND versn = c_0
                             AND ( vorga = c_sdor OR vorga = c_rkp5 ).
              CLEAR plan_rev.
              IF sy-subrc IS INITIAL.
                MOVE wa_final-wlp08 TO t_plan_rev.
                plan_rev = plan_rev + t_plan_rev.
              ENDIF.
              CLEAR: it_prps, it_final.
            ENDLOOP.
    ENDCASE.
    ENDLOOP.
    WRITE:/10 'Actual Billing is',act_billing.
    WRITE:/20 'Actual Cost is........', actu_cost.
    Thanks in advace,
    sudharsan.

    Hi SUDHARSAN RAO
    U r clearing the headers and tables. So u cannot use the values on the nested loops  as u have cleared the values. There wont be anything in the workare ur using in where clause.
    Please see the below comments that I kept.
    LOOP AT it_prps.
    ACTUAL BILLING
    LOOP AT it_final INTO wa_final
    WHERE posid = it_prps-posid
    AND wrttp = c_04
    AND beltp = c_02
    AND versn = c_0
    AND ( vorga = c_coin OR vorga = c_rku2 ).
    CLEAR act_billing.
    IF sy-subrc IS INITIAL.
    MOVE wa_final-wlp08 TO t_act_billing.
    act_billing = act_billing + t_act_billing.
    ENDIF.
    CLEAR: it_prps, it_final.
    Here IT_FINAL is cleared by u... should not be cleared
    ENDLOOP.
    *************PLANNED REVENUE
    LOOP AT it_final INTO wa_final
    WHERE posid = it_prps-posid
    AND wrttp = c_01
    AND beltp = c_02
    AND versn = c_0
    AND ( vorga = c_sdor OR vorga = c_rkp5 ).
    CLEAR plan_rev.
    IF sy-subrc IS INITIAL.
    MOVE wa_final-wlp08 TO t_plan_rev.
    plan_rev = plan_rev + t_plan_rev.
    ENDIF.
    Again ur clearing both tables.
    CLEAR: it_prps, it_final.
    ENDLOOP.
    ENDCASE.
    ENDLOOP.
    WRITE:/10 'Actual Billing is',act_billing.
    WRITE:/20 'Actual Cost is........', actu_cost.

  • Performance issue: CALL FUNCTION inside a Loop.

    Hi Friends
    I have a Performance Issue. That is, inside a loop...endloop a CALL FUNCTION has been used which gets data from another database table. Finally it's appended into another internal table. Please see this :
      LOOP AT i_mdkp.
        REFRESH lt_mdtbx.
        CLEAR lt_mdtbx.
        CALL FUNCTION 'READ_MRP_LIST'
          EXPORTING
            idtnum        = i_mdkp-dtnum
            icflag        = 'X'
          tables
            mdtbx         = lt_mdtbx
        APPEND LINES OF lt_mdtbx TO i_mdtb.
      ENDLOOP.
    It happens for each record available in i_mdkp. Suppose, i_mdkp have around 50000 records, it needs to call the function module till that much time.
    So, I want to split it. Can I?
    Please give me your valueable suggestions.
    Regards
    Senthil

    If internal table i_mdkp has 50,000 records it does not mean that you need to run 50,000 iterations. You just need dtnum from internal table i_mdkp so you number of iterations should be eqaul to the unique number of dtnum in the internal table. Sort the internal table by dtnum and delete adjacent duplicates from the internal table comparing dtnum before looping. Look at the code below.
    DATA i_mdkp_tmp LIKE TABLE OF i_mdkp.
    IF NOT i_mdkp[] IS INITIAL.
      i_mdkp_tmp[] = i_mdkp[].
      SORT i_mdkp BY dtnum.
      DELETE ADJACENT DUPLICATES FROM i_mdkp COMPARING dtnum.
      REFRESH i_mdtb.
      LOOP AT i_mdkp.
        CALL FUNCTION 'READ_MRP_LIST'
          EXPORTING
            idtnum = i_mdkp-dtnum
            icflag = 'X'
          TABLES
            mdtbx = lt_mdtbx.
        APPEND LINES OF lt_mdtbx TO i_mdtb.
        REFRESH lt_mdtbx.
      ENDLOOP.
      i_mdkp[] = i_mdkp_tmp[]
    ENDIF.

  • Performance issue with Loop under Loop

    Hi,
    I have an issue with the performance, as per the requirement I have to use the Loop under Loop logic.
    I have sorted the Where condition field in Parent Loop and also in Child Loop like below :
    SELECT GUID_PRCTSC   "Primary Key as GUID in "RAW" Format
             GUID_PR       "Primary Key as GUID in "RAW" Format
             STCTS         "Numbering Scheme for Customs Tariff System
             DATAB         "Definitive Date (Valid-From Time)
             GUID_CTSNUMC  "Primary Key as GUID in "RAW" Format
             FROM /SAPSLL/PRCTSC
             INTO TABLE T_PRCTSC
             WHERE STCTS IN S_STCTS.
      IF T_PRCTSC IS INITIAL.
        MESSAGE : I007(ZMSSG) WITH 'Data not available for this entry'.
        STOP.
      ENDIF.
    SORT T_PRCTSC BY GUID_PR.
      SELECT GUID_PRGEN  "Primary Key as GUID in "RAW" Format "+  DG1K902277
             GUID_PR     "Primary Key as GUID in "RAW" Format
             ATTR05A     "Materail Type
             ATTR05B     "Sub-Family
             ATTR05C     "SPEC BUS + DG1K902190
             ATTR10A     "Materail Group
             ATTR20A     "SUBSTANCE ID
             FROM /SAPSLL/PRGEN
             INTO TABLE T_PRGEN
             FOR ALL ENTRIES IN T_TCOATV20
             WHERE ATTR20A EQ T_TCOATV20-ATTRV20
               AND ATTR05A IN S_ATR5A " +DG1K902168
               AND ATTR05C IN S_ATR5C. " + DG1K902190
      IF T_PRGEN IS INITIAL.
        MESSAGE : I007(ZMSSG) WITH 'Data not available for this entry'.
        STOP.
      ENDIF.
    *N-23
    SORT T_PRGEN BY GUID_PR.
    There are 90,000 records available in the table T_PRGEN.
    LOOP AT T_PRGEN INTO WA_PRGEN.
        IF SY-SUBRC = 0.
           WA_FINAL-ATTR05A       = WA_PRGEN-ATTR05A.
           WA_FINAL-ATTR05B       = WA_PRGEN-ATTR05B.
           WA_FINAL-ATTR05C       = WA_PRGEN-ATTR05C. " + DG1K902190
           WA_FINAL-ATTR10A       = WA_PRGEN-ATTR10A.
           WA_FINAL-ATTR20A       = WA_PRGEN-ATTR20A.
        ENDIF.
        READ TABLE T_V_TCAV201 INTO WA_V_TCAV201 WITH KEY ATTRV20 = WA_PRGEN-ATTR20A.
        IF SY-SUBRC = 0.
          WA_FINAL-TEXT1   = WA_V_TCAV201-TEXT1.    "SUBID-TEXT1
        ENDIF.
        READ TABLE T_PNTPR INTO WA_PNTPR WITH KEY GUID_PR = WA_PRGEN-GUID_PR.
        IF SY-SUBRC = 0.
           WA_FINAL-PRVSY  = WA_PNTPR-PRVSY.   "PROD NO
           WA_FINAL-GRVSY  = WA_PNTPR-GRVSY.   "LOGICAL SYS GROUP
        ENDIF.
    * TO Remove the Leading Zeros from prvsy
        SHIFT WA_FINAL-PRVSY LEFT DELETING LEADING '0'.
        READ TABLE T_CORSTA INTO WA_CORSTA WITH KEY GUID_MOBJ = WA_PNTPR-GUID_PR.
        IF SY-SUBRC = 0.
          WA_FINAL-QUAL_STA  = WA_CORSTA-QUAL_STA.
        ENDIF.
        READ TABLE T_PR INTO WA_PR WITH KEY GUID_PR = WA_PNTPR-GUID_PR.
    *& IN THE PROD MASTER PRODUCT CHANGED ON VALUE HAS BEEN   &
    *& MAINTAINED AS SINGLE '0', THIS WILL CAUSE ISSUES WHILE &
    *&  USING CONVERSION EXIT TO DISPLAY THE DATE FORMAT IN   &
    *&  MM/DD/YYYY HH:MM:SEC                                  &
        IF SY-SUBRC = 0.
          IF WA_PR-CHTSP = '0'.
            WA_FINAL-CRTSP   = WA_PR-CRTSP.
            wa_final-chtsp   = W_DATE.
          ENDIF.
          IF WA_PR-CHTSP NE '0'.
            WA_FINAL-CRTSP   = WA_PR-CRTSP.
            wa_final-chtsp   = WA_PR-CHTSP.
          ENDIF.
        ENDIF.
        READ TABLE T_PRT INTO WA_PRT WITH KEY GUID_PR = WA_PR-GUID_PR.
        IF SY-SUBRC = 0.
          WA_FINAL-PRTXT   = WA_PRT-PRTXT.
        ENDIF.
    LOOP AT T_PRCTSC INTO WA_PRCTSC WHERE GUID_PR = WA_PRGEN-GUID_PR. "+DG1K902258  - Performance issue
            IF SY-SUBRC = 0.
    *& TO FILL ATTR20A,PRVSY FOR DIFF STCTS AND CCNGN FOR     |
    *&  EACH LOOP                                             |
              IF WA_FINAL-ATTR20A  IS INITIAL
              AND  WA_FINAL-PRVSY IS INITIAL.
                IF WA_PRGEN-GUID_PR = WA_PNTPR-GUID_PR. "This condition is to fill up all the rows for the same
                                                        " Subid which have multiple stcts fields.
               IF SY-SUBRC = 0.
                  WA_FINAL-ATTR05A       = WA_PRGEN-ATTR05A.
                  WA_FINAL-ATTR05B       = WA_PRGEN-ATTR05B.
                  WA_FINAL-ATTR05C       = WA_PRGEN-ATTR05C. " + DG1K902190
                  WA_FINAL-ATTR10A       = WA_PRGEN-ATTR10A.
                  WA_FINAL-ATTR20A       = WA_PRGEN-ATTR20A.
                 ENDIF.
                  IF SY-SUBRC = 0.
                    WA_FINAL-TEXT1   = WA_V_TCAV201-TEXT1.    "SUBID-TEXT1
                  ENDIF.
                  IF SY-SUBRC = 0.
                    WA_FINAL-PRVSY  = WA_PNTPR-PRVSY.   "PROD NO
                    WA_FINAL-GRVSY  = WA_PNTPR-GRVSY.   "LOGICAL SYS GROUP
                  ENDIF.
    * TO Remove the Leading Zeros from prvsy
                  SHIFT WA_FINAL-PRVSY LEFT DELETING LEADING '0'.
                  IF SY-SUBRC = 0.
                    WA_FINAL-QUAL_STA  = WA_CORSTA-QUAL_STA.
                  ENDIF.
                  IF SY-SUBRC = 0.
                    IF WA_PR-CHTSP = '0'.
                      WA_FINAL-CRTSP   = WA_PR-CRTSP.
                      WA_final-chtsp   = W_DATE.
                    ENDIF.
                    IF WA_PR-CHTSP NE '0'.
                      WA_FINAL-CRTSP   = WA_PR-CRTSP.
                      WA_final-chtsp   = WA_PR-CHTSP.
                    ENDIF.
                  ENDIF.
                  IF SY-SUBRC = 0.
                    WA_FINAL-PRTXT   = WA_PRT-PRTXT.
                  ENDIF.
                ENDIF.
              ENDIF.
          IF SY-SUBRC = 0. " + DG1K902198
                WA_FINAL-GUID_PR      = WA_PRCTSC-GUID_PR.
                WA_FINAL-STCTS        = WA_PRCTSC-STCTS.
                WA_FINAL-DATAB        = WA_PRCTSC-DATAB.       " + DG1K902198
              ENDIF.
             READ TABLE T_CTSNUMC INTO WA_CTSNUMC WITH KEY GUID_CTSNUMC = WA_PRCTSC-GUID_CTSNUMC.
              IF SY-SUBRC = 0.
                WA_FINAL-CCNGN        = WA_CTSNUMC-CCNGN.
              ENDIF.
              APPEND WA_FINAL TO T_FINAL.
              CLEAR WA_FINAL.
            ENDIF.
        ENDLOOP.
        APPEND WA_FINAL TO T_FINAL.
        CLEAR WA_FINAL.
      ENDLOOP.
    Any suggestions to improve the performance will be appreciated!
    Thanks & Regards,
    Kittu
    Edited by: Kittu on Mar 23, 2009 4:03 PM

    Hi
    Instead of using the LOOP under LOOP directly. use the read statement for second loop and from that index u start the loop.
    eg:
    LOOP AT ITAB1.
    read table itab2 with key field1 = itab1 - field1.
    if sy-subrc = 0.
    loop at itab2 index sy-tabix.
    if  itab2-field1 = itab1 - field1.
    < do u  r operations >
    else.
      exit.
    endif.
    ENDLOOP.
    this will increase the performance

  • Avoiding performance issue due to loop within loop on internal tables

    Hi Experts,
                    I have a requirement where in i want to check whether each of the programs stored in one internal table are called from any of the programs stored in another internal table. In this case i am looping on two internal tables (Loop within a loop) which is causing a major performance issue. Program is running very very slow.
    Can any one advise how to resolve this performance issue so that program runs faster.
    Thanks in advance.
    Regards,
    Chetan.

    Forget the parallel cursur stuff, it is much to complicated for general usage and helps nearly nothing. I will publish a blog in the next days where this is shown in detail.
    Loop on loop is no problem if the inner table is a hashed or sorted table.
    If it must be a standard table, then you must make a bit more effort and faciliate a binary search (read binary search / loop from index exit)
    see here the exact coding Measurements on internal tables: Reads and Loops:
    /people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables
    And don't forget, the other table must not be sorted, the loop reaches anyway every line. The parallel cursor requires both tables to be sorted. The additional sort
    consumes nearly the whole advantage of the parallel cursor compared to the simple but good loop in loop solutions.
    Siegfried

  • How to avoid the loop inside the loop? as it reduces the performance.

    hi masters,
    i have 2 internal tables having 1 same field. eg table itab having f1, f2, f3 fields and itab1 having f1, f4 and f5 fields. let us consider the data in the itab and itab1 is like below given
    itab-f1   itab-f2   itab-f3                 itab1-f1     itab1-f4   itab1-f5
    10        aa         11                      10             abc       456
    10        bb         15                      10             def        655
    10        ff           13                      10             ghi        456
    11        dd         16                      10             tre         455
    11        zz         24                      11             ftr          256
    11        ii           54                      11             kjh         556
    12        hh         24                      12             fjk          751
    now i want the result in final table like below
    f1         f2       f3         f4         f5
    10        aa      11      abc      456
    10        aa      11      def       655
    10        aa      11      ghi       456
    10        aa      11      tre       455
    10        bb      15      abc      456
    10        bb      15      def       655
    10        bb      15      ghi       456
    10        bb      15      tre       455
    10        ff        13      abc      456
    10        ff        13      def      655
    10        ff        13      ghi      456
    10        ff        13      tre       455
    11        dd      16      ftr        256
    11        dd      16      kjh      556
    11        zz      24      ftr       256
    11        zz      24      kjh      556
    11        ii        54      ftr       256
    11        ii        54      kjh      556
    12        hh      24      fjk       751
    i can get this result using the
    Loop at itab.
    loop at itab1 where f1 = itab-f1.
    process....
    endloop.
    endloop.
    but it is very slow. i want to avoid this loop inside the loop and i want to implement the same program using read table.. like below..
    Loop at itab.
    Read table itab1 with key ....
    process...
    endloop.
    Is it possible? to get multiple records from itab2 using read statement or with READ statement that using CASE Statement or IF statemetnt.
    Plz help me...

    hi,
    please try the following code
    TYPES:
      begin of ty_itab2,
       f1
       f2
       f3
       f4
       f5
      end of ty_itab2.
    DATA:
      lw_tab2tmp type ty_itab2,
      lt_tab2tmp type standard table of ty_itab2.
    sort it_itab by f1.
    loop at it_itab into lw_itab.
      at new f1.
        CLEAR lt_tab2tmp[].
        loop at it_itab1 into lw_itab1 where f1 = lw_itab-f1.
          CLEAR lw_tab2tmp.
          move-corresponding lw_itab1 to lw_tab2tmp.
          append lw_tab2tmp into lt_tab2tmp.
        end loop.
        "while there is no data with f1 in it_itab1
        if lt_tab2tmp is initial.
          lw_tab2tmp-f1 = lw_itab-f1.
          append lw_tab2tmp into lt_tab2tmp.
        endif.
      end at.
      CLEAR lw_tab2tmp.
      MOVE-CORRESPONDING lw_itab to lw_tab2tmp.
      modify lt_tab2tmp from lw_tab2tmp TRANSPORTING f2 f3 where not f1 is initial.
      append lines of lt_tab2tmp into lt_itab2.
    end loop.
    lt_itab2 is the final table.
    There may be some syntactically errors.
    I have not a system to test it now, please test it.

  • XSL-How to get value of a variable from inside loop-- to the outside loop?

    Pls help
    hi im currently working on this xsl file..
    This works on generating a txt file,my problem right now is
    ' how can i get the value of a variable generated from the inside forloop,
    i have to get the total,sum value of this variables after performing the loop
    ***this is the for loop
    <xsl:for-each select="OutboundPayment">
    <xsl:variable name='id' select='generate-id(OutboundPayment)'/>
    <xsl:sort select="PaymentNumber/CheckNumber" data-type="text" />
    <xsl:variable name='PValue' select='format-number(100*PaymentAmount/Value,"0000000000000")'/>
    <xsl:value-of select='$id'/>
    <xsl:text>D</xsl:text>
    <xsl:value-of select='$DDate'/>
    <xsl:value-of select='$Batch'/>
    <xsl:text>3</xsl:text>
    <xsl:value-of select='format-number(PaymentNumber/PaymentReferenceNumber,"0000000000")'/>
    <xsl:value-of select='format-number(PayeeBankAccount/BankAccountNumber,"0000000000")'/>
    <xsl:value-of select='substring(Payee/Name,1,20)'/>
    <xsl:value-of select='$PValue'/>
    <xsl:variable name='Addend' select='concat($DDate,substring($DAcct,5,5),$Batch)'/>
    <xsl:variable name="LHash">
    <xsl:call-template name="GetHash">
    <xsl:with-param name="A1" select="$PValue" />
    <xsl:with-param name="A2" select="$Addend" />
    </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="concat('[',$LHash,']')" />
    <!--LHash*i have to get the total amount of this one from the outside loop /---->
    <xsl:call-template name='NewLine'/>
    </xsl:for-each>
    <!--I have to put in here the total value of that LHash/---->
    <!--This is the template on how to get the value of that variable in the inside loop/---->
    <xsl:template name="GetHash">
    <xsl:param name='A1'/>
    <xsl:param name='A2'/>
    <xsl:variable name='TwoSum' select='format-number($A1+$A2,"000000000000000")'/>
    <xsl:variable name='Weight' select='317191314191112'/>
    <xsl:call-template name="WDigit">
    <xsl:with-param name="Cnt" select="15"/>
    <xsl:with-param name="Sum" select="$TwoSum"/>
    <xsl:with-param name="Wgt" select="$Weight"/>
    <xsl:with-param name="Tot" select="0"/>
    </xsl:call-template>
    </xsl:template>
    <xsl:template name='WDigit'>
    <xsl:param name='Cnt'/>
    <xsl:param name='Sum'/>
    <xsl:param name='Wgt'/>
    <xsl:param name='Tot'/>
    <xsl:choose>
    <xsl:when test="$Cnt > 0">
    <xsl:variable name='Multip' select='substring($Wgt,$Cnt,1)'/>
    <xsl:variable name='Factor' select='substring($Sum,$Cnt,1)'/>
    <xsl:variable name='Prduct' select='$Multip$Factor'/>
    <!--xsl:value-of select="concat($Tot,'[',$Cnt,']')"/-->
    <!--xsl:value-of select="concat($Multip,'x',$Factor,'=',$Prduct)"/-->
    <!--xsl:call-template name='NewLine'/-->
    <xsl:call-template name="WDigit">
    <xsl:with-param name="Cnt" select="$Cnt - 1"/>
    <xsl:with-param name="Sum" select="$Sum"/>
    <xsl:with-param name="Wgt" select="$Wgt"/>
    <xsl:with-param name="Tot" select="$Tot+$Prduct"/>
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:variable name="Rem" select="$Tot mod 11"/>
    <xsl:variable name="Chk" select="11 - $Rem"/>
    <xsl:value-of select="format-number(concat($Tot,$Chk),'00000')"/>
    </xsl:otherwise>
    </xsl:choose>
    <xsl:template name='GetTotal'>
    </xsl:template>
    Thanks in advance for those who are willing to help.
    -Leighya

    It would have helped if you had posted your code as CODE but as it is, I could hardly read it. My guess about what you are asking is, if you want a template to return a value, just write that value to the result stream inside the template.
    If that wasn't what you were asking, then please post your code in a readable format.

  • Will using for loop decrease the performance

    Hi,
    Will using for loop with a query decrease the performance.
    for r_row in (select * from table) Loop
    end loop.
    This is done inside another for loop, most of the cases it returns only one value.
    will it decrease the peformance of the procedure.
    kindly advice.......
    Regards,
    Balu

    user575682 wrote:
    Will using for loop with a query decrease the performance.
    for r_row in (select * from table) Loop
    end loop.
    This is done inside another for loop, most of the cases it returns only one value.
    will it decrease the peformance of the procedure.Perhaps it is better to understand just what this PL/SQL loop construct does.
    PL/SQL is two languages. It is PL (programming logic code) like Pascal or C or Java. You can use a 2nd language inside it called SQL. The PL engine is clever enough to recognise when the 2nd language is used. And it compiles all the stuff that is needed for the PL engine to call the SQL engine, pass data to the SQL engine and get data back, etc. (compare this with the complexity of using the SQL language in Pascal or C or Java).
    So what does that loop do? The PL engine recognises the SQL SELECT statement. It creates an implicit cursor by calling the SQL engine to parse it (hopefully a soft parse) and then execute it.
    As part of the PL loop, the PL engine now calls the SQL engine to fetch the data (rows) from the cursor. With 10g and later, the PL engine is smart enough to use implicit bulk processing.
    Prior to 10g it used to fetch a row from the SQL engine, do the loop, fetch the next row, do the loop, etc. This means if there is a 1000 rows to fetch, it will call the SQL engine a 1000 times.
    With 10g and later it will fetch a 100 rows, store that in an internal buffer and then do the loop a 100 times. With a 1000 rows to fetch, it now only requires 10 bulk fetches instead of a 1000 single row fetches.
    These fetches require a context switch - as the PL engine has to step out and into the SQL engine and back, to fetch a row. This is an overhead and thus can become slow the more context switching there is.
    And this is the basics for this loop (and most other cursor loops) construct in PL/SQL.
    The ideal is to reduce the number of context switches. This is an overhead that can impact on performance.
    What about using a loop within a loop. Also "bad". This uses the outer loop to fetch data. This data is then used to drive the fetch in the inner or nested loop. So the outside loop pulls data from the SQL engine into PL variables. The inside loop pushes that very same data back to the SQL engine.
    Why? It would have been a lot faster no to pull and push that data between the loops using PL.
    It will be a lot faster doing it via SQL only. Write both loops as a single SQL statement and have the SQL engine directly drive these loops itself. This is called a JOIN in SQL. And the SQL engine can do it not only faster, but it has some froody algorithms that can be used that are even faster than a nested loop process (called merge joins, hash joins, etc).
    Bottom line. Maximise SQL. Minimise PL.*
    Do as much of your data crunching in SQL as possible. SQL is the best and fastest "place" to process data. Not PL (or Pascal/C/Java).

  • Making .mov to loop inside flash

    I have a seamless quicktime .mov of clouds I want to use as a background.
    I set my flash animation to loop...but at the end of the .mov file instead of looping it just quits.
    How do I get the quicktime .mov file to loop within flash?
    Using Flash CS4

    Re: Loop inside a loop making performance poor!!!Yup, it probably will be.
    Your nested loops have an advantage in that they give you control over the process of what is happening. Unfortunately due to several factors including context switching between pl/sql and the sql engine this process is all but certain to be slower than doing the work in SQL.
    Instead of nested loops which call a procedure define a cursor directly your routine to get the data, then use a bulk collect - you can read about them in the documentation - to load your collection. One select with a bulk collect is all but certain to be faster than loading each row one item at a time.

  • While loop inside a timed loop

    Hi everybody!
       I'm using:
           - LV 7.1 + RealTime;
           - compactFieldpoint;
       I've noticed a strange behaviour, when I put a while loop inside a timed loop.  Let's fix timed loop with these settings:
           - 1 KHz clock
           - 1 ms period (yes, I know it's short....)
           - offset 0 ms
           - Phase 0
           - Discard missed period (ON) and MAintain original Phase (ON);
           - Timeout: -1.
       If inside this loo, I put a traditional while loop, waiting (say) for an event to occur, and if this event does not arrive, my cFP-2020 hangs! I mean, it becomes unreachable for the debugger, and, more, if I run a ping to it's address, after some cycles it becomes unreachable also from ping!
       Clearly, this code statement lock the fieldPoint, because if I remove the inner while loop all works.
      I know that with 1 ms period, timed loop always finishes late, but I set to discard missed period and timeout to -1. 
       It seems to me that sometimes Timed Loop add heavi overhead to programs, I'm turning to all while loop based tasks, even if my application has to be real-time!
       Advices welcomed! Have a nice day!
    graziano
    Solved!
    Go to Solution.

    I think the issue here is that putting your while loop inside a Timed Loop increases the priority for that task. Timed Loops can have dynamic priorities set over eachother, but they all run between Above Normal and Time Critical priority. My guess is that the debugger and built-in TCP functions run at Above Normal priority or less. This means your cFP isn't hanging, it's doing what it thinks is best. It's trying to finish this task before handling any lower-priority tasks.
    The suggestion to put a Wait function in your loop is an OK one. Keep in mind that you can actually set your wait time to zero instead of one and get the same positive benefit of handling other tasks. I would also suggest that you might look into waiting for this event in a lower priority (non-Timed) loop, and then transmit the appropriate data to your Timed Loop using an RT-FIFO or something. That might give you better handling. Just a thought....
    Jarrod S.
    National Instruments

  • Can I put Read inside loop?

    Hi Folks
    Can I put Read inside loop?
    Performance wise is it acceptable?
    Regards,
    Sreeram

    Hi
    there is no problem to put READ statement inside the LOOP
    its a better way to put
    to avoid SELECT in a LOOP
    see this example
    i had used that in my program
    in the performance point of view it is a good method
    LOOP AT IT_SOBID INTO WA_SOBID." where otype eq s_otype and objid eq s_objid.
        READ TABLE IT_HRP1026 WITH KEY OBJID = WA_SOBID-SOBID OTYPE = WA_SOBID-SCLAS INTO WA_HRP1026.
        IF SY-SUBRC EQ 0.
          READ TABLE IT_HRP1000 WITH KEY OBJID = WA_SOBID-SOBID INTO WA_HRP1000.
          WA_OUTPUT-OBJID = WA_HRP1026-OBJID.
          WA_OUTPUT-BEGDA = WA_SOBID-BEGDA.
          WA_OUTPUT-ENDDA = WA_SOBID-ENDDA.
          WA_OUTPUT-AEDTM = WA_HRP1026-AEDTM.
          WA_OUTPUT-UNAME = WA_HRP1026-UNAME.
          WA_OUTPUT-STEXT = WA_HRP1000-STEXT.
          READ TABLE IT_REASON WITH KEY CANCR = WA_HRP1026-CANCR INTO WA_REASON.
          WA_OUTPUT-CANCRT = WA_REASON-CANCRT.
          CLEAR WA_REASON-CANCRT.
          READ TABLE IT_LOCATION1 WITH KEY OBJID = WA_HRP1026-OBJID INTO WA_LOCATION1..
          READ TABLE IT_LSTEXT WITH KEY OBJID = WA_LOCATION1-SOBID OTYPE = 'F' INTO WA_LSTEXT.
                 WA_OUTPUT-LSTEXT = WA_LSTEXT-LSTEXT.
                 CLEAR WA_LSTEXT-LSTEXT.
          APPEND WA_OUTPUT TO IT_OUTPUT.
          CLEAR WA_OUTPUT.
          CLEAR WA_OUTPUT-CANCRT.
        ENDIF.
      ENDLOOP.
    <b>Reward if usefull</b>

  • Smart form - loop inside a loop

    Dear Techies,
      I am new to smartforms. I have a query, in one of the code examples there is a context menu on the main window called "complex selection", but i dont find the same in my editor, what is the reason.
      I want this because i have data in two internal tables. Different tables are generated from secondary depending on the entries in first table. how do i achieve this on the main window.
    Similar to loop inside a loop, depending on my first table entries, all the entries belonging to that entry are to be put in table of second entry. i will have tables equal to the entries in first internal table. hope my question is clear.
    Please help.
    Regards
    imran.

    Hye..
      Loop in main area will fill only the current table, but i want several tables depending on entries in the first internal table.  The number of tables in the main window will be the number records in the first table.
    Regards
    imran.

  • I have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    i have a for loop inside of while loop.when i press stop for while loop, i also would like to stop for loop.how can i solve this problem?thanks

    Hi fais,
    Following through with what JB suggested. The steps involved in replacing the inner for loop with a while loop are outlined below.
    You can replace the inner for loop with a while by doing the following.
    1) Right-click of the for loop and select "Repalce" then navigate to the "while loop".
    2) Make sure the tunnels you where indexing on with the for loop are still indexing.
    3) Drop an "array size" node on your diagram. Wire the array that determines the number of iterations your for loop executes into this "array size".
    4) Wire the output of the array size into the new while loop.
    5) Set the condition terminal to "stop if true".
    6)Drop an "OR" gate inside the while loop and wire its output to the while loops condition terminal.
    7) C
    reate a local of the boolean "stop" button, and wire it into one of the inputs of your OR gate. This will allow you to stop the inner loop.
    8) Drop a "less than" node inside the inner while loop.
    9) Wire your iteration count into the bottom input of the "less than".
    10) Wire the count (see step 4 above) into the top input of the less than. This will stop the inner loop when ever the inner loop has processed the last element of your array.
    Provided I have not mixed up my tops and bottoms this should accomplish the replacement.
    I will let others explain how to takle this task using the "case solution".
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How do I break a for loop (inside) and a while loop (outside) at the same time by a control button

    I have a while loop (outside) and a for loop (inside) and a control button within the for loop.  I want to stop the program by click the botton without finishing the for loop.  How can I do that?
    Thank you in advance.

    HI Please find attached snapshot Regards, Santosh
    Message Edited by SanRac on 12-17-2009 05:12 AM
    Message Edited by SanRac on 12-17-2009 05:13 AM
    Attachments:
    Snap1.png ‏4 KB

Maybe you are looking for

  • How to get the name of workspace on htmd db local installation

    Hello to all, I have been working with my html db Xe version on my pc for a while now. I forgot the workspace name. I am trying to run the sample application and for that I need the admin for username and workspace name for password. But forgot the w

  • Message mapping - dependencies is disabled?

    Hi,gurus: In IR,message mapping ->dependencies,it was disabled.Can you tell me why?Thanks in advance.

  • When I click on an image, it won't show up in photoshop

    I'll restart the computer, and then photoshop and it will let me work on it for a short time, then it won't pull up an image. I had CS4 and decided to upgrade to the monthly photoshop to see if that would fix it and nope, it started again! HELP!

  • Sidebar Question

    I just upgraded from 10.4.11 to 10.5.4 tonight, all when smoothly. Right away I noticed that the font size in the Finder Sidebar is a little small for these old eyes. Is there a way to increase the font size in the Sidebar? thanks,

  • Prompts for old user's password when DL or updating apps?

    I have a used IPhone 3G. I had signed out of previous user's account and made my own. Everything was fine, DL apps and suddenly I went to update an app and when prompted for password it is old user's email!? I do not understand as I've gone into sett