<?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 V.S read in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765045#M905856</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi check this..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the main difference between the loop and read..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose i had one record for every record there may be so many records ...like a record in the mara-matnr there may be many in the mard table ..in this case we use the loop in the loop..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_mara .&lt;/P&gt;&lt;P&gt;loop at it_mard where matnr = it_mara-matnr.&lt;/P&gt;&lt;P&gt;it_final[] = it_mard[].&lt;/P&gt;&lt;P&gt;append it_final.&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;for every record if there is only one record...the we will use the read statement...in the loop..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_mara .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_marc with key matnr = it_mara-matnr.&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;regards,&lt;/P&gt;&lt;P&gt;venkat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 May 2008 11:12:09 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-05-05T11:12:09Z</dc:date>
    <item>
      <title>loop V.S read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765042#M905853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question here (kinda stupid)...I wrote two codes..both return me same result.&lt;/P&gt;&lt;P&gt;But I have to know which way better....The Loop  V.S  The Read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below are my codes:&lt;/P&gt;&lt;P&gt;The Loop way........&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT it_table WHERE mtart = 'ZTG' OR mtart = 'ZPM'.
  EXIT.
ENDLOOP.

IF sy-subrc = 0.
  READ TABLE it_table WITH KEY mtart = 'ZSM' BINARY SEARCH.
  IF sy-subrc = 0.
    lv_flag = 1.           
  ELSE.
    lv_flag = 0.           
  ENDIF.
ELSE.
  lv_flag = 0.          
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and the Read way.....&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE it_table WITH KEY mtart = 'ZTG' BINARY SEARCH.
IF sy-subrc NE 0.
  READ TABLE it_table WITH KEY mtart = 'ZPM' BINARY SEARCH.
  IF sy-subrc = 0.
    lv_flag1 = 0.       
  ELSE.
    lv_flag1 = 1.        
  ENDIF.
ELSE.
  lv_flag1 = 0.        
ENDIF.

READ TABLE it_table WITH KEY mtart = 'ZSM' BINARY SEARCH.
IF sy-subrc = 0.
  IF lv_flag1 = 0.          
    lv_flag = 1.            
  ELSE.                    
    lv_flag = 0.           
  ENDIF.
ELSE.
  lv_flag = 0.           
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please tell me which way better?&lt;/P&gt;&lt;P&gt;The fastest and most effective.&lt;/P&gt;&lt;P&gt;I tried SE30, and I got different duration every time I run above codes.&lt;/P&gt;&lt;P&gt;I tried ST05, I can't get what I want....the duration of these codes...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please advice and help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Law&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 May 2008 10:57:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765042#M905853</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-05T10:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: loop V.S read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765043#M905854</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;Read statement with binary search is the best option...&lt;/P&gt;&lt;P&gt;But make sure that ur funtionality is fine....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If both the codes work in the same way , go for the second one...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;lavanya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 May 2008 11:03:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765043#M905854</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-05T11:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: loop V.S read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765044#M905855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm...but the 2nd way uses more indicator (lv_flag1) and more lines of codes. Doesn't this affected the performance as well?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way....before perform both ways, the internal table was sorted by the field mtart.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 May 2008 11:06:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765044#M905855</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-05T11:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: loop V.S read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765045#M905856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi check this..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the main difference between the loop and read..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;suppose i had one record for every record there may be so many records ...like a record in the mara-matnr there may be many in the mard table ..in this case we use the loop in the loop..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_mara .&lt;/P&gt;&lt;P&gt;loop at it_mard where matnr = it_mara-matnr.&lt;/P&gt;&lt;P&gt;it_final[] = it_mard[].&lt;/P&gt;&lt;P&gt;append it_final.&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;for every record if there is only one record...the we will use the read statement...in the loop..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_mara .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_marc with key matnr = it_mara-matnr.&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;regards,&lt;/P&gt;&lt;P&gt;venkat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 May 2008 11:12:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765045#M905856</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-05T11:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: loop V.S read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765046#M905857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Go for the second way...even SAP recommends read table compared to loop at..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 May 2008 11:12:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/loop-v-s-read/m-p/3765046#M905857</guid>
      <dc:creator>jaideepsharma</dc:creator>
      <dc:date>2008-05-05T11:12:50Z</dc:date>
    </item>
  </channel>
</rss>

