<?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 optimize code in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587218#M592115</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please give the optimise code for following and please give reason.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.C4A = '000'.               &lt;/P&gt;&lt;P&gt;	SELECT * FROM T100         &lt;/P&gt;&lt;P&gt;WHERE SPRSL = 'D' AND    &lt;/P&gt;&lt;P&gt;ARBGB = '00'.      &lt;/P&gt;&lt;P&gt;CHECK: T100-MSGNR &amp;gt; C4A. &lt;/P&gt;&lt;P&gt;C4A = T100-MSGNR.        &lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3.		LOOP AT TAB.              &lt;/P&gt;&lt;P&gt;IF TAB-FLAG IS INITIAL. &lt;/P&gt;&lt;P&gt;TAB-FLAG = 'X'.       &lt;/P&gt;&lt;P&gt;ENDIF.                  &lt;/P&gt;&lt;P&gt;MODIFY TAB.             &lt;/P&gt;&lt;P&gt;    ENDLOOP.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4.	&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	DESCRIBE TABLE: TAB1 LINES L1,       &lt;/P&gt;&lt;P&gt;TAB2 LINES L2.       &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF L1 &amp;lt;&amp;gt; L2.                         &lt;/P&gt;&lt;P&gt;	TAB_DIFFERENT = 'X'.               &lt;/P&gt;&lt;P&gt;ELSE.                                &lt;/P&gt;&lt;P&gt;TAB_DIFFERENT = SPACE.             &lt;/P&gt;&lt;P&gt;LOOP AT TAB1.                      &lt;/P&gt;&lt;P&gt;READ TABLE TAB2 INDEX SY-TABIX.  &lt;/P&gt;&lt;P&gt;IF TAB1 &amp;lt;&amp;gt; TAB2.                 &lt;/P&gt;&lt;P&gt;     TAB_DIFFERENT = 'X'. EXIT.     &lt;/P&gt;&lt;P&gt;ENDIF	.                           &lt;/P&gt;&lt;P&gt;ENDLOOP.                           &lt;/P&gt;&lt;P&gt;ENDIF.                               &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF TAB_DIFFERENT = SPACE.            &lt;/P&gt;&lt;P&gt;" ...                              &lt;/P&gt;&lt;P&gt;ENDIF.           &lt;/P&gt;&lt;P&gt;     5. LOOP AT TAB_SRC.               &lt;/P&gt;&lt;P&gt;	APPEND TAB_SRC TO TAB_DEST.  &lt;/P&gt;&lt;P&gt;ENDLOOP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Jul 2007 09:45:14 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-07-26T09:45:14Z</dc:date>
    <item>
      <title>optimize code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587218#M592115</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please give the optimise code for following and please give reason.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.C4A = '000'.               &lt;/P&gt;&lt;P&gt;	SELECT * FROM T100         &lt;/P&gt;&lt;P&gt;WHERE SPRSL = 'D' AND    &lt;/P&gt;&lt;P&gt;ARBGB = '00'.      &lt;/P&gt;&lt;P&gt;CHECK: T100-MSGNR &amp;gt; C4A. &lt;/P&gt;&lt;P&gt;C4A = T100-MSGNR.        &lt;/P&gt;&lt;P&gt;    ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3.		LOOP AT TAB.              &lt;/P&gt;&lt;P&gt;IF TAB-FLAG IS INITIAL. &lt;/P&gt;&lt;P&gt;TAB-FLAG = 'X'.       &lt;/P&gt;&lt;P&gt;ENDIF.                  &lt;/P&gt;&lt;P&gt;MODIFY TAB.             &lt;/P&gt;&lt;P&gt;    ENDLOOP.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4.	&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	DESCRIBE TABLE: TAB1 LINES L1,       &lt;/P&gt;&lt;P&gt;TAB2 LINES L2.       &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF L1 &amp;lt;&amp;gt; L2.                         &lt;/P&gt;&lt;P&gt;	TAB_DIFFERENT = 'X'.               &lt;/P&gt;&lt;P&gt;ELSE.                                &lt;/P&gt;&lt;P&gt;TAB_DIFFERENT = SPACE.             &lt;/P&gt;&lt;P&gt;LOOP AT TAB1.                      &lt;/P&gt;&lt;P&gt;READ TABLE TAB2 INDEX SY-TABIX.  &lt;/P&gt;&lt;P&gt;IF TAB1 &amp;lt;&amp;gt; TAB2.                 &lt;/P&gt;&lt;P&gt;     TAB_DIFFERENT = 'X'. EXIT.     &lt;/P&gt;&lt;P&gt;ENDIF	.                           &lt;/P&gt;&lt;P&gt;ENDLOOP.                           &lt;/P&gt;&lt;P&gt;ENDIF.                               &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF TAB_DIFFERENT = SPACE.            &lt;/P&gt;&lt;P&gt;" ...                              &lt;/P&gt;&lt;P&gt;ENDIF.           &lt;/P&gt;&lt;P&gt;     5. LOOP AT TAB_SRC.               &lt;/P&gt;&lt;P&gt;	APPEND TAB_SRC TO TAB_DEST.  &lt;/P&gt;&lt;P&gt;ENDLOOP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 09:45:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587218#M592115</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T09:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: optimize code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587219#M592116</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Javed,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the code no 2. do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Keep the no of database access small.&lt;/P&gt;&lt;P&gt;2. Keep the data transfer between the database and the application server small.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so, you can do the same using internal tables for the entire operation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C4A = '000'. &lt;/P&gt;&lt;P&gt;       select * &lt;/P&gt;&lt;P&gt;          from  T100&lt;/P&gt;&lt;P&gt;   into table  lt_itab&lt;/P&gt;&lt;P&gt;         where  SPRSL = 'D'&lt;/P&gt;&lt;P&gt;             and ARBGB = '00'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;// error code&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at lt_itab.&lt;/P&gt;&lt;P&gt;if lt_itab-msgnr &amp;gt; C4A.&lt;/P&gt;&lt;P&gt;C4A = T100-MSGNR.&lt;/P&gt;&lt;P&gt;Modify lt_itab from wa_itab where msgnr GE C4A.&lt;/P&gt;&lt;P&gt;if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;// error code&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endif.&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;Else you can modify the existing code as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C4A = '000'. &lt;/P&gt;&lt;P&gt;SELECT * FROM T100 &lt;/P&gt;&lt;P&gt;WHERE SPRSL = 'D' AND &lt;/P&gt;&lt;P&gt;ARBGB = '00'. &lt;/P&gt;&lt;P&gt;if T100-MSGNR &amp;gt; C4A. &lt;/P&gt;&lt;P&gt;C4A = T100-MSGNR. &lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the no 3 code - Use an Array operation on the same rather than row by row. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the no 4 code - It looks fine to me... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the no 5 code - use append lines of Itab instead of single append. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Samantak,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Rewards for useful answers.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 10:27:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587219#M592116</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T10:27:25Z</dc:date>
    </item>
    <item>
      <title>Re: optimize code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587220#M592117</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Q2 looks to be trying to get the highest value of MSGNR for message library '00'... so rather than read every matching record from the table I'd pick something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select max( msgnr ) into c4a
   from t100 
   where sprsl = 'D'                 
   and   arbgb = '00'.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q3 could probably be achieved without the loop via something like&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;tab-flag = 'X'.
modify tab transporting flag
  where flag is initial.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q4 can be done simply without loops by comparing the body of the tables via&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;if tab1[] = tab2[]. 
...
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Q5 save the loops again..&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;append lines of tab_src to tab_dest.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jul 2007 10:46:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587220#M592117</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T10:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: optimize code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587221#M592118</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have seen this example several times, and I do not understand what is good&lt;/P&gt;&lt;P&gt;for? To compare 2 tables is more complicated, the knowledge that the number&lt;/P&gt;&lt;P&gt;of lines is equal helps nothing, the sort order is completely neglected, and&lt;/P&gt;&lt;P&gt;both tables can have the same number of lines, but different different keys.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The coding here works only for identically sorted tables, where a non-key field&lt;/P&gt;&lt;P&gt;is different. If the number of lines is different, then it provides no solution.   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DESCRIBE TABLE: TAB1 LINES L1, &lt;/P&gt;&lt;P&gt;TAB2 LINES L2. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF L1 &amp;lt;&amp;gt; L2. &lt;/P&gt;&lt;P&gt;TAB_DIFFERENT = 'X'. &lt;/P&gt;&lt;P&gt;ELSE. &lt;/P&gt;&lt;P&gt;TAB_DIFFERENT = SPACE. &lt;/P&gt;&lt;P&gt;LOOP AT TAB1. &lt;/P&gt;&lt;P&gt;READ TABLE TAB2 INDEX SY-TABIX. &lt;/P&gt;&lt;P&gt;IF TAB1 &amp;lt;&amp;gt; TAB2. &lt;/P&gt;&lt;P&gt;TAB_DIFFERENT = 'X'. EXIT. &lt;/P&gt;&lt;P&gt;ENDIF . &lt;/P&gt;&lt;P&gt;ENDLOOP. &lt;/P&gt;&lt;P&gt;ENDIF. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF TAB_DIFFERENT = SPACE. &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;2. Don't use check inside select ... endselect, add the condition the where clause&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. Use assigning and modify directly&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4. What is the task? See above.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;5  is 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>Thu, 26 Jul 2007 12:02:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-code/m-p/2587221#M592118</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-26T12:02:06Z</dc:date>
    </item>
  </channel>
</rss>

