<?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: Loop at...where problem in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554027#M1075198</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think that LOOP is setting SY-SUBRC &lt;EM&gt;inside&lt;/EM&gt; the loop. Which means that in some cases SY-SUBRC ne 0 could "survive" from the preceding READ statement (no entry in IT_OPBAL).&lt;/P&gt;&lt;P&gt;From my point of view you can remove the IF SY-SUBRC = 0 statement inside the LOOP AT IT_BSID1 altogether, because you will not be inside the loop anymore, should SY-SUBRC be not equal 0.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. just looked it up in ABAP docu: LOOP is &lt;EM&gt;not&lt;/EM&gt; setting SY-SUBRC, only when there were no LOOP passes at all due to the WHERE condition, SY-SUBRC will be 4 &lt;EM&gt;after&lt;/EM&gt; the ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Sep 2008 11:27:05 GMT</pubDate>
    <dc:creator>ThomasZloch</dc:creator>
    <dc:date>2008-09-30T11:27:05Z</dc:date>
    <item>
      <title>Loop at...where problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554026#M1075197</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;&lt;/P&gt;&lt;P&gt;SELECT-OPTIONS: SO_KUNNR  FOR KNA1-KUNNR OBLIGATORY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; SORT IT_BSID1 BY KUNNR.&lt;/P&gt;&lt;P&gt;  SORT IT_KNA1 BY KUNNR.&lt;/P&gt;&lt;P&gt;  SORT IT_OPBAL BY KUNNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT IT_KNA1 INTO WA_KNA1.&lt;/P&gt;&lt;P&gt;    CLEAR : WA_OUTPUT.&lt;/P&gt;&lt;P&gt;    WA_OUTPUT-KUNNR = WA_KNA1-KUNNR.&lt;/P&gt;&lt;P&gt;    WA_OUTPUT-NAME1 = WA_KNA1-NAME1.&lt;/P&gt;&lt;P&gt;    READ TABLE IT_OPBAL WITH KEY KUNNR = WA_KNA1-KUNNR&lt;/P&gt;&lt;P&gt;                                                 BINARY SEARCH.&lt;/P&gt;&lt;P&gt;    IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;      WA_OUTPUT-OPNBAL = IT_OPBAL-LC_BAL.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    LOOP AT IT_BSID1 INTO WA_BSID1 WHERE KUNNR = WA_KNA1-KUNNR.&lt;/P&gt;&lt;P&gt;      IF SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;        CASE WA_BSID1-BLART.&lt;/P&gt;&lt;P&gt;          WHEN 'RV'.&lt;/P&gt;&lt;P&gt;            IF WA_BSID1-SHKZG = 'S'.&lt;/P&gt;&lt;P&gt;              WA_OUTPUT-SALE = WA_BSID1-DMBTR.&lt;/P&gt;&lt;P&gt;            ENDIF.&lt;/P&gt;&lt;P&gt;    ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both  WA_KNA1  AND  WA_BSID1 contains the same KUNNR .&lt;/P&gt;&lt;P&gt;But after LOOP AT .....WHERE  i am  not getting SY-SUBRC  = 0.&lt;/P&gt;&lt;P&gt;For example if i give the KUNNR = 2 in the selection-screen everything is fine but if i give  KUNNR = 7002 in the selection-screen  the above problem is arising.&lt;/P&gt;&lt;P&gt;when i checked in debugging at &lt;/P&gt;&lt;P&gt;LOOP AT ...WHERE statement&lt;/P&gt;&lt;P&gt;wa_kna1-kunnr  =  0000007002 and wa_bsid1-kunnr = 0000007002.But iam getting sy-subrc  = 8. Please suggest soln .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards&lt;/P&gt;&lt;P&gt;Venkat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Sep 2008 11:08:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554026#M1075197</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-09-30T11:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: Loop at...where problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554027#M1075198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think that LOOP is setting SY-SUBRC &lt;EM&gt;inside&lt;/EM&gt; the loop. Which means that in some cases SY-SUBRC ne 0 could "survive" from the preceding READ statement (no entry in IT_OPBAL).&lt;/P&gt;&lt;P&gt;From my point of view you can remove the IF SY-SUBRC = 0 statement inside the LOOP AT IT_BSID1 altogether, because you will not be inside the loop anymore, should SY-SUBRC be not equal 0.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. just looked it up in ABAP docu: LOOP is &lt;EM&gt;not&lt;/EM&gt; setting SY-SUBRC, only when there were no LOOP passes at all due to the WHERE condition, SY-SUBRC will be 4 &lt;EM&gt;after&lt;/EM&gt; the ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Sep 2008 11:27:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554027#M1075198</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2008-09-30T11:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Loop at...where problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554028#M1075199</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;that IF condition in the second loop is useless. That second loop goes only over records which fulfill the condition in WHERE. You can also combine conditions in your WHERE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT IT_BSID1 INTO WA_BSID1 WHERE KUNNR = WA_KNA1-KUNNR AND 
                                     SHKZG = 'S' AND
                                     BLART = 'RV'.
        WA_OUTPUT-SALE = WA_BSID1-DMBTR.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Sep 2008 23:25:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554028#M1075199</guid>
      <dc:creator>mvoros</dc:creator>
      <dc:date>2008-09-30T23:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Loop at...where problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554029#M1075200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hey,&lt;/P&gt;&lt;P&gt;In the case of LOOPS there is no need to check the SY-SUBRC ok,&lt;/P&gt;&lt;P&gt;Chage the code as,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT IT_BSID1 INTO WA_BSID1 WHERE KUNNR = WA_KNA1-KUNNR.&lt;/P&gt;&lt;P&gt;CASE WA_BSID1-BLART.&lt;/P&gt;&lt;P&gt;WHEN 'RV'.&lt;/P&gt;&lt;P&gt;IF WA_BSID1-SHKZG = 'S'.&lt;/P&gt;&lt;P&gt;WA_OUTPUT-SALE = WA_BSID1-DMBTR.&lt;/P&gt;&lt;P&gt;ENDCASE.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Midhun Abraham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Oct 2008 11:56:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554029#M1075200</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-05T11:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Loop at...where problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554030#M1075201</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 are getting result of READ TABLE IT_OPBAL WITH KEY KUNNR = WA_KNA1-KUNNR BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can get result for LOOP after the ENDLOOP statement.system will give 0 or 4. 0 for LOOP has gone inside. 4 for LOOP didn't go to inside.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Oct 2008 08:30:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554030#M1075201</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-06T08:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Loop at...where problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554031#M1075202</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT-OPTIONS: SO_KUNNR FOR KNA1-KUNNR OBLIGATORY.

SORT IT_BSID1 BY KUNNR.
SORT IT_KNA1 BY KUNNR.
SORT IT_OPBAL BY KUNNR.

LOOP AT IT_KNA1 INTO WA_KNA1.
  CLEAR : WA_OUTPUT.
  WA_OUTPUT-KUNNR = WA_KNA1-KUNNR.
  WA_OUTPUT-NAME1 = WA_KNA1-NAME1.
  
  READ TABLE IT_OPBAL 
            WITH KEY KUNNR = WA_KNA1-KUNNR
            BINARY SEARCH.
  IF SY-SUBRC = 0.
    WA_OUTPUT-OPNBAL = IT_OPBAL-LC_BAL.
  ENDIF.

    LOOP AT IT_BSID1 
           INTO WA_BSID1 
          WHERE KUNNR = WA_KNA1-KUNNR.
     IF SY-SUBRC = 0.
       CASE WA_BSID1-BLART.
       WHEN 'RV'.
          IF WA_BSID1-SHKZG = 'S'.
       WA_OUTPUT-SALE = WA_BSID1-DMBTR.
      ENDIF.
   ENDLOOP.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What you need a better performaning solution&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT-OPTIONS: SO_KUNNR FOR KNA1-KUNNR OBLIGATORY.

SORT IT_BSID1 BY KUNNR.
SORT IT_KNA1 BY KUNNR.
SORT IT_OPBAL BY KUNNR.

LOOP AT IT_KNA1 INTO WA_KNA1.
  CLEAR : WA_OUTPUT.
  WA_OUTPUT-KUNNR = WA_KNA1-KUNNR.
  WA_OUTPUT-NAME1 = WA_KNA1-NAME1.
  
  READ TABLE IT_OPBAL 
            WITH KEY KUNNR = WA_KNA1-KUNNR
            BINARY SEARCH.
  IF SY-SUBRC = 0.
    WA_OUTPUT-OPNBAL = IT_OPBAL-LC_BAL.
  ENDIF.

  READ TABLE IT_BSID1 
           TRANSPORTING NO FIELDS
            WHERE KUNNR = WA_KNA1-KUNNR.
            BINARY SEARCH.
  IF SY-SUBRC = 0.
    TABIX = SY-TABIX.

     LOOP AT IT_BSID1 
             INTO WA_BSID1 
             FROM INDEX tabix.

       IF ( WA_BSID1-KUNNR NE WA_KNA1-KUNNR ).
          EXIT.
        ELSE.
           IF ( WA_BSID1-BLART = 'RV'
              AND WA_BSID1-SHKZG = 'S' ).
            WA_OUTPUT-SALE = WA_BSID1-DMBTR.
           ENDIF.
          WA_OUTPUT-OPNBAL = IT_OPBAL-LC_BAL.
        ENDIF.   
      ENDLOOP.
   ENDIF.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are maybe some smaller bugs, which you will easily figure out with the syntax check, but the structurse should be o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Oct 2008 09:14:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-at-where-problem/m-p/4554031#M1075202</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-06T09:14:04Z</dc:date>
    </item>
  </channel>
</rss>

