<?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: Sorted Table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202910#M763446</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi aditya.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;declaring sorted table is same as declaring the standard table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF ty_s_vbpa,&lt;/P&gt;&lt;P&gt;        vbeln TYPE vbpa-vbeln,    &lt;/P&gt;&lt;P&gt;        lifnr TYPE vbpa-lifnr,     &lt;/P&gt;&lt;P&gt;        scacd TYPE lfa1-scacd,     " Standard carrier access code&lt;/P&gt;&lt;P&gt;       END OF ty_s_vbpa,&lt;/P&gt;&lt;P&gt;     it_vbpa TYPE SORTED TABLE OF ty_s_vbpa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Reward ppoints if useful&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chandra&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chandrasekhar Velpula on Dec 17, 2007 7:27 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 17 Dec 2007 06:26:23 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-12-17T06:26:23Z</dc:date>
    <item>
      <title>Sorted Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202909#M763445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;    Please provide some scenario where we have to declare a table as sorted table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 06:11:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202909#M763445</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T06:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sorted Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202910#M763446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi aditya.,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;declaring sorted table is same as declaring the standard table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF ty_s_vbpa,&lt;/P&gt;&lt;P&gt;        vbeln TYPE vbpa-vbeln,    &lt;/P&gt;&lt;P&gt;        lifnr TYPE vbpa-lifnr,     &lt;/P&gt;&lt;P&gt;        scacd TYPE lfa1-scacd,     " Standard carrier access code&lt;/P&gt;&lt;P&gt;       END OF ty_s_vbpa,&lt;/P&gt;&lt;P&gt;     it_vbpa TYPE SORTED TABLE OF ty_s_vbpa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Reward ppoints if useful&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chandra&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chandrasekhar Velpula on Dec 17, 2007 7:27 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 06:26:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202910#M763446</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T06:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sorted Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202911#M763447</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;Sorted tables are always saved correctly sorted by key. They also have a linear key, and, like standard tables, you can access them using either the table index or the key. When you use the key, the response time is in logarithmic relationship to the number of table entries, since the system uses a binary search. The key of a sorted table can be either unique, or non-unique, and you must specify either UNIQUE or NON-UNIQUE in the table definition.  Standard tables and sorted tables both belong to the generic group index tables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This table type is particularly suitable if you want the table to be sorted while you are still adding entries to it. You fill the table using the (INSERT) statement, according to the sort sequence defined in the table key. Table entries that do not fit are recognised before they are inserted. The response time for access using the key is in logarithmic relation to the number of &lt;/P&gt;&lt;P&gt;table entries, since the system automatically uses a binary search. Sorted tables are appropriate for partially sequential processing in a LOOP, as long as the WHERE condition contains the beginning of the table key. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also check the link&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/content.htm" target="test_blank"&gt;http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/content.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Nagaraj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 06:26:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202911#M763447</guid>
      <dc:creator>former_member404244</dc:creator>
      <dc:date>2007-12-17T06:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sorted Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202912#M763448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;Sorted tables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Using Sorted table and Index while processing Internal tables&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There would have been many instances where we would have to process large entries in an internal table with a WHERE condition. This article is intended to demonstrate the comparison between three different methods in handling this situation.   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First Method: The normal method used by most of us. Standard internal table processing using WHERE condition &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second Method: Same as above, but here we would be using the Sorted table &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Third Method: Sorted table and using the Index   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Following is the demo program illustrating the above three methods:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT ZINTERNAL_TABLE_OPERATIONS.* Program to find the best method in reading the internal tables&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; Type declaration&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;TYPES:&lt;/P&gt;&lt;P&gt;  BEGIN OF TY_MARA,&lt;/P&gt;&lt;P&gt;    MATNR LIKE MARA-MATNR,&lt;/P&gt;&lt;P&gt;    MTART LIKE MARA-MTART,&lt;/P&gt;&lt;P&gt;  END OF TY_MARA.* Internal table declaration&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;  T_MARA TYPE STANDARD TABLE OF TY_MARA,&lt;/P&gt;&lt;P&gt;  T_MARA1 TYPE SORTED TABLE OF TY_MARA&lt;/P&gt;&lt;P&gt;          WITH NON-UNIQUE KEY MATNR MTART.* Variable declaration&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;  W_COUNTER TYPE I,&lt;/P&gt;&lt;P&gt;  W_RUNTIME1 TYPE I,&lt;/P&gt;&lt;P&gt;  W_RUNTIME2 TYPE I,&lt;/P&gt;&lt;P&gt;  W_TABIX LIKE SY-TABIX.* Table workarea definition&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;  WA_MARA TYPE TY_MARA.SELECT MATNR                           " Material Number&lt;/P&gt;&lt;P&gt;       MTART                           " Material Type&lt;/P&gt;&lt;P&gt;  FROM MARA&lt;/P&gt;&lt;P&gt;  INTO TABLE T_MARA.T_MARA1[] = T_MARA[].* CASE 1: Processing internal table using LOOP..WHERE ConditionGET RUN TIME FIELD W_RUNTIME1.LOOP AT T_MARA INTO WA_MARA WHERE MTART EQ 'FHMI'.&lt;/P&gt;&lt;P&gt;  ADD 1 TO W_COUNTER.&lt;/P&gt;&lt;P&gt;ENDLOOP.GET RUN TIME FIELD W_RUNTIME2.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Calculate Runtime&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.&lt;/P&gt;&lt;P&gt;WRITE W_RUNTIME2.CLEAR W_COUNTER.* CASE 2: Using a Sorted tableGET RUN TIME FIELD W_RUNTIME1.&lt;/P&gt;&lt;P&gt;LOOP AT T_MARA1 INTO WA_MARA WHERE MTART EQ 'FHMI'.&lt;/P&gt;&lt;P&gt;  ADD 1 TO W_COUNTER.&lt;/P&gt;&lt;P&gt;ENDLOOP.GET RUN TIME FIELD W_RUNTIME2.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Calculate Runtime&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.&lt;/P&gt;&lt;P&gt;WRITE W_RUNTIME2.CLEAR W_COUNTER.* CASE 3: Using INDEX on a sorted tableGET RUN TIME FIELD W_RUNTIME1.&lt;/P&gt;&lt;P&gt;READ TABLE T_MARA1 INTO WA_MARA WITH KEY MTART = 'FHMI'.&lt;/P&gt;&lt;P&gt;IF SY-SUBRC EQ 0.&lt;/P&gt;&lt;P&gt;  W_TABIX = SY-TABIX + 1.&lt;/P&gt;&lt;P&gt;  ADD 1 TO W_COUNTER.&lt;/P&gt;&lt;P&gt;  LOOP AT T_MARA1 INTO WA_MARA FROM W_TABIX.&lt;/P&gt;&lt;P&gt;    IF WA_MARA-MTART NE 'FHMI'.&lt;/P&gt;&lt;P&gt;      EXIT.&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;    ADD 1 TO W_COUNTER.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;GET RUN TIME FIELD W_RUNTIME2.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Calculate Runtime&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;W_RUNTIME2 = W_RUNTIME2 - W_RUNTIME1.&lt;/P&gt;&lt;P&gt;WRITE W_RUNTIME2.Following is the analysis report in microseconds, as per the data volume:   &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Records: 21,390 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iteration No &lt;/P&gt;&lt;P&gt; Using Normal LOOP &amp;amp; WHERE &lt;/P&gt;&lt;P&gt; Using Sorted table LOOP &amp;amp; WHERE &lt;/P&gt;&lt;P&gt; Using INDEX on Sorted table &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;1 &lt;/P&gt;&lt;P&gt; 897 &lt;/P&gt;&lt;P&gt; 887 &lt;/P&gt;&lt;P&gt; 11 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;2 &lt;/P&gt;&lt;P&gt; 839 &lt;/P&gt;&lt;P&gt; 879 &lt;/P&gt;&lt;P&gt; 10 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;3 &lt;/P&gt;&lt;P&gt; 839 &lt;/P&gt;&lt;P&gt; 877 &lt;/P&gt;&lt;P&gt; 10 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;4 &lt;/P&gt;&lt;P&gt; 834 &lt;/P&gt;&lt;P&gt; 880 &lt;/P&gt;&lt;P&gt; 9 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;5 &lt;/P&gt;&lt;P&gt; 842 &lt;/P&gt;&lt;P&gt; 837 &lt;/P&gt;&lt;P&gt; 10 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Records: 132,693 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iteration No &lt;/P&gt;&lt;P&gt; Using Normal LOOP &amp;amp; WHERE &lt;/P&gt;&lt;P&gt; Using Sorted table LOOP &amp;amp; WHERE &lt;/P&gt;&lt;P&gt; Using INDEX on Sorted table &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;1 &lt;/P&gt;&lt;P&gt; 34239  &lt;/P&gt;&lt;P&gt; 35774  &lt;/P&gt;&lt;P&gt; 3567 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;2 &lt;/P&gt;&lt;P&gt; 34271  &lt;/P&gt;&lt;P&gt; 38250  &lt;/P&gt;&lt;P&gt; 3592 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;3 &lt;/P&gt;&lt;P&gt; 34492  &lt;/P&gt;&lt;P&gt; 36534  &lt;/P&gt;&lt;P&gt; 3554 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;4 &lt;/P&gt;&lt;P&gt; 34198  &lt;/P&gt;&lt;P&gt; 35695  &lt;/P&gt;&lt;P&gt; 3584 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorted table might have given a better performance here if the field in the WHERE condition is the first field in the internal table. However, from the above statistics, we can say that method 3 is better than the other 2 methods. In production environment, the data would be huge and the performance could be much improved with this simple technique.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2007 06:31:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sorted-table/m-p/3202912#M763448</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-17T06:31:59Z</dc:date>
    </item>
  </channel>
</rss>

