<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Efficient logic in a loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360620#M522183</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;my mistake.... I meant to sort itab before loop over itab not in the loop. Now I would sort Itab and I do not want to loose any data in itab. Rob or Rich could you modify my code to show your ideas....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Jun 2007 21:38:09 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-06-15T21:38:09Z</dc:date>
    <item>
      <title>Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360610#M522173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a program where I have logic something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
loop at itab.

   sort itab ascending by prueflos.

    clear   : t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    refresh : t_qals, t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    CALL FUNCTION 'XYZ'
      EXPORTING
        I_PRUEFLOS    = itab-prueflos
      IMPORTING
        E_QALS        = t_qals
      TABLES
        T_QAMR        = t_qamr
        T_QAMV        = t_qamv
        T_QAPO        = t_qapo
        T_QASR        = t_qasr
        T_QAPP        = t_qapp
      EXCEPTIONS
        LOT_NOT_FOUND = 1
        OTHERS        = 2.


     if sy-subrc = 0.

      ............

     endif.

endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table itab can have duplicate prueflos. I don't want to run the FM XYZ for same inspection lots again and again as this FM takes considerable amount of time to run. For this I sorted the itab ascending by prueflos so that the duplicate prueflos would be one below the other. Now my idea is - if we come accross a duplicate prueflos, use the values t_qamr, t_qamv, t_qapo, t_qasr, t_qapp from previous iteration in the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could someone put there efficient ideas in. Let me know if something is not clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:09:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360610#M522173</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360611#M522174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think that's the way I would do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:15:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360611#M522174</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360612#M522175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have my idea but I am struggling to put this idea in the code. Can me help me out. Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:17:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360612#M522175</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360613#M522176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Some suggestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not sort the same itab you are looping inside of your loop.  Sort once before you start looping.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After you sort, use &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM itab COMPARING prueflos. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and you'll have unique prueflos to loop through.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="---------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab ascending by prueflos.&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM itab COMPARING prueflos.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;    clear   : t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.&lt;/P&gt;&lt;P&gt;    refresh : t_qals, t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.&lt;/P&gt;&lt;P&gt;    CALL FUNCTION 'XYZ'&lt;/P&gt;&lt;P&gt;      EXPORTING&lt;/P&gt;&lt;P&gt;        I_PRUEFLOS    = itab-prueflos&lt;/P&gt;&lt;P&gt;      IMPORTING&lt;/P&gt;&lt;P&gt;        E_QALS        = t_qals&lt;/P&gt;&lt;P&gt;      TABLES&lt;/P&gt;&lt;P&gt;        T_QAMR        = t_qamr&lt;/P&gt;&lt;P&gt;        T_QAMV        = t_qamv&lt;/P&gt;&lt;P&gt;        T_QAPO        = t_qapo&lt;/P&gt;&lt;P&gt;        T_QASR        = t_qasr&lt;/P&gt;&lt;P&gt;        T_QAPP        = t_qapp&lt;/P&gt;&lt;P&gt;      EXCEPTIONS&lt;/P&gt;&lt;P&gt;        LOT_NOT_FOUND = 1&lt;/P&gt;&lt;P&gt;        OTHERS        = 2.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;     if sy-subrc = 0.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;      ............&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;     endif.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:23:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360613#M522176</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360614#M522177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   If you are have chance to edit the FM then you can create a internal table with in the function module, and you can write the logic inside the program  by importing the entire internal table at one shot. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Dj &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward, if its useful&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:24:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360614#M522177</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:24:19Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360615#M522178</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.........&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use just after sort&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM itab compairing prueflos . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if u dont want to make any changes in the original internal table, just make a temporary table, copy all data into that and then put the above query on it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this ll help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thak-You&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;vinsee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:27:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360615#M522178</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360616#M522179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Like others have suggested, do the sort before going into the LOOP, but i am thinking that you could make a copy of ITAB into ITAB2 with the same structure, SORT  ITAB2, then DELETE adjacement duplicates from ITAB2 and then LOOP at ITAB2,  and call the function.  This way, you have  your original data in ITAB and you are using ITAB2 to call the function. Of course, if you do not need the original data, you could simply delete adjacent duplicates from ITAB.  Anyway you go, you would want to do your SORT outside the LOOP just before going in.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:28:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360616#M522179</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-06-15T21:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360617#M522180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT itab ASCENDING BY prueflos.
LOOP AT itab.

  IF itab-prueflos = old_prueflos
*Logic to assign old value of variables here

  ELSE.

    old_prueflos = itab-prueflos.

    CLEAR   : t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
  REFRESH : t_qals, t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    CALL FUNCTION 'XYZ'
      EXPORTING
        i_prueflos    = itab-prueflos
      IMPORTING
        e_qals        = t_qals
      TABLES
        t_qamr        = t_qamr
        t_qamv        = t_qamv
        t_qapo        = t_qapo
        t_qasr        = t_qasr
        t_qapp        = t_qapp
      EXCEPTIONS
        lot_not_found = 1
        OTHERS        = 2.


    IF sy-subrc = 0.



    ENDIF.

  ENDIF.

ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:29:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360617#M522180</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360618#M522181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Its good to use AT NEW logic like below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;At new prueflos.&lt;/P&gt;&lt;P&gt;         clear the variables.&lt;/P&gt;&lt;P&gt;         call FM.....&lt;/P&gt;&lt;P&gt;Endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;use the values returned by FM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT NEW prueflos will be triggerred for evry new prueflos. You can clear all variables &amp;amp; call the function module .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dont sort itab inside the loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:34:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360618#M522181</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360619#M522182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can as the others have suggested, copy to a second table. But then you'll likely have to copy the results back to the first table. I prefer the way I suggested, but the other way will work as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:37:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360619#M522182</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360620#M522183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;my mistake.... I meant to sort itab before loop over itab not in the loop. Now I would sort Itab and I do not want to loose any data in itab. Rob or Rich could you modify my code to show your ideas....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:38:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360620#M522183</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360621#M522184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sticking with the copy of the table here is the example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

* Here TTAB represents the type used to describe ITAB
data: itab2 type table of ttab with header line.

itab2[] = itab[].
sort itab2 ascending by prueflos.
delete adjacent duplicates from itab2 comparing prueflos.

loop at itab2.
 

    clear   : t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    refresh : t_qals, t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    CALL FUNCTION 'XYZ'
      EXPORTING
        I_PRUEFLOS    = itab2-prueflos
      IMPORTING
        E_QALS        = t_qals
      TABLES
        T_QAMR        = t_qamr
        T_QAMV        = t_qamv
        T_QAPO        = t_qapo
        T_QASR        = t_qasr
        T_QAPP        = t_qapp
      EXCEPTIONS
        LOT_NOT_FOUND = 1
        OTHERS        = 2.
 
 
     if sy-subrc = 0.
 
      ............
 
     endif.
 
endloop.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some adjustments&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:46:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360621#M522184</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2007-06-15T21:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360622#M522185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rob,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your logic may not work for what I am asking for. If the itab-prueflos = old_prueflos then I have to do whatever I am doing after the FM ie., in the if sy-subrc = 0 loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:48:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360622#M522185</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360623#M522186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I modified your code. The posting is somewhere above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:48:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360623#M522186</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360624#M522187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming you are keeping everything you need from the FM call and can just move it in if the numbers are the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IE - at my comment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Rob Burbank&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 21:50:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360624#M522187</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T21:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360625#M522188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rich / Rob ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May be I did not explain my requirement clearly. I have to loop on ITAB and do the steps 1, 2 and 3 for each and every prueflos where FM returns subrc 0. Here is my code again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

data : old_prueflos like qals-prueflos.

*  sort ITAB so the duplicates are one below the other
sort itab ascending by prueflos.   

clear : old_prueflos.
loop at itab.
  
    clear   : t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    refresh : t_qals, t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    CALL FUNCTION 'XYZ'
      EXPORTING
        I_PRUEFLOS    = itab-prueflos
      IMPORTING
        E_QALS        = t_qals
      TABLES
        T_QAMR        = t_qamr
        T_QAMV        = t_qamv
        T_QAPO        = t_qapo
        T_QASR        = t_qasr
        T_QAPP        = t_qapp
      EXCEPTIONS
        LOT_NOT_FOUND = 1
        OTHERS        = 2.
 

     if sy-subrc = 0.
 
      step 1
      step 2
      step 3
 
     endif.
 
  old_prueflos = itab-prueflos.

endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I need a logic something like - if old_prueflos = itab-Prueflos do not call FM and if FM return for this prueflos = 0 then do steps 1,2 and 3. If old_prueflos &amp;lt;&amp;gt; itab-Prueflos then call FM and if FM return is 0 do steps 1,2 and 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like this....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 22:07:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360625#M522188</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T22:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360626#M522189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Raju,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you use &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM itab2 COMPARING prueflos&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you are removing the duplicates from itab2 (which is the copied table), so you won't be processing them twice - which should meet your requirements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No need to keep a reference to the previous prueflos, since they will all be unique.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Jun 2007 22:34:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360626#M522189</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-15T22:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Efficient logic in a loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360627#M522190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The logic I showed earlier would work, but this is better and includes your steps:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT itab ASCENDING BY prueflos.
LOOP AT itab.
 
  IF itab-prueflos &amp;lt;&amp;gt; old_prueflos

    old_prueflos = itab-prueflos.
 
    CLEAR   : t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    REFRESH : t_qals, t_qamr, t_qamv, t_qapo, t_qasr, t_qapp.
    CALL FUNCTION 'XYZ'
      EXPORTING
        i_prueflos    = itab-prueflos
      IMPORTING
        e_qals        = t_qals
      TABLES
        t_qamr        = t_qamr
        t_qamv        = t_qamv
        t_qapo        = t_qapo
        t_qasr        = t_qasr
        t_qapp        = t_qapp
      EXCEPTIONS
        lot_not_found = 1
        OTHERS        = 2.
 
    IF sy-subrc &amp;lt;&amp;gt; 0.
* Message?
    ENDIF.

  ENDIF.

*   STEP 1
*   STEP 2
*   STEP #
 
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Jun 2007 01:49:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/efficient-logic-in-a-loop/m-p/2360627#M522190</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-16T01:49:51Z</dc:date>
    </item>
  </channel>
</rss>

