<?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 Z table count issue. Database or code in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173078#M1372056</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've got an issue with counting records in a Z table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I select all the valid entries into an internal table. My program must then count the occurance of 3 fields (ie Field 1, A, B) where the content is the same. If there are 10 occurances then update the count field at each occurance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on a condition, the program also does the same but for Field 2 instead of Field 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that the count for Field 2, A, B is taking considerable longer (even though it has less records) than the count for Field 1, A, B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field 1 and Field 2 are set as keys in the table and there are no indexes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my SQL trace I can see that the duration of the initial select is in red (149.239) to retrieve 40,000 records. However, why would the count for (Field 1, A, B) be less?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 09 Oct 2009 12:37:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-10-09T12:37:01Z</dc:date>
    <item>
      <title>Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173078#M1372056</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I've got an issue with counting records in a Z table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I select all the valid entries into an internal table. My program must then count the occurance of 3 fields (ie Field 1, A, B) where the content is the same. If there are 10 occurances then update the count field at each occurance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on a condition, the program also does the same but for Field 2 instead of Field 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem is that the count for Field 2, A, B is taking considerable longer (even though it has less records) than the count for Field 1, A, B.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field 1 and Field 2 are set as keys in the table and there are no indexes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my SQL trace I can see that the duration of the initial select is in red (149.239) to retrieve 40,000 records. However, why would the count for (Field 1, A, B) be less?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone help?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 12:37:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173078#M1372056</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T12:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173079#M1372057</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is hard to understand your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please don't get confused by the red color of the SQL-Trace, just ignore it, 150msec for 40.000 is not an issue.&lt;/P&gt;&lt;P&gt;The meaning of this time depends highly on your used database, there are bigs differences between the platforms.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So what is your problem, how much time does the total execution need?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use the Summary by SQL statements (see menu trace-list), there you see totals and one line per statement, it is the much better display!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 13:42:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173079#M1372057</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T13:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173080#M1372058</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_ztable,
         f1(30)    TYPE c,
         f2(30)    TYPE c,
         fa(30)    TYPE c,
         fb(30)    TYPE c,
         cnt_cmb1  TYPE c,
         cnt_cmb2  TYPE c,
       END OF ty_ztable,

       BEGIN OF ty_comb1,
         f1(30) TYPE c,
         fa(30) TYPE c,
         fb(30) TYPE c,
         count  TYPE i,
       END OF ty_comb1,

       BEGIN OF ty_comb2,
         f2(30) TYPE c,
         fa(30) TYPE c,
         fb(30) TYPE c,
         count  TYPE i,
       END OF ty_comb2.

DATA: w_ztable TYPE                ty_ztable,
      w_comb1  TYPE                ty_comb1 ,
      w_comb2  TYPE                ty_comb2 ,
      w_index  TYPE                sy-tabix ,

      t_ztable TYPE TABLE OF ty_ztable,
      t_comb1  TYPE SORTED TABLE OF ty_comb1
        WITH UNIQUE KEY f1 fa fb,
      t_comb2  TYPE SORTED TABLE OF ty_comb2
        WITH UNIQUE KEY f2 fa fb.


SELECT f1
       f2
       fa
       fb
  FROM ztable
  INTO TABLE t_ztable.

LOOP AT t_ztable INTO w_ztable.

  READ TABLE t_comb1 INTO w_comb1
    WITH KEY f1 = w_ztable-f1
             fa = w_ztable-fa
             fb = w_ztable-fb.

  IF sy-subrc EQ 0.

    w_index = sy-tabix.

    ADD 1 TO w_comb1-count.

    MODIFY t_comb1 FROM w_comb1
      INDEX w_index
      TRANSPORTING
        count.

  ELSE.

    w_comb1-f1    = w_ztable-f1.
    w_comb1-fa    = w_ztable-fa.
    w_comb1-fb    = w_ztable-fb.
    w_comb1-count = 1          .

    INSERT w_comb1 INTO TABLE t_comb1.

    CLEAR w_comb1.

  ENDIF.

  READ TABLE t_comb2 INTO w_comb2
    WITH KEY f2 = w_ztable-f2
             fa = w_ztable-fa
             fb = w_ztable-fb.

  IF sy-subrc EQ 0.

    w_index = sy-tabix.

    ADD 1 TO w_comb2-count.

    MODIFY t_comb2 FROM w_comb2
      INDEX w_index
      TRANSPORTING
        count.

  ELSE.

    w_comb2-f2    = w_ztable-f2.
    w_comb2-fa    = w_ztable-fa.
    w_comb2-fb    = w_ztable-fb.
    w_comb2-count = 1          .

    INSERT w_comb2 INTO TABLE t_comb2.

    CLEAR w_comb2.

  ENDIF.

ENDLOOP.


LOOP AT t_comb1 INTO w_comb1.

  UPDATE ztable
    SET cnt_cmb1 = w_comb1-count
    WHERE f1 = w_comb1-f1
    AND   fa = w_comb1-fa
    AND   fb = w_comb1-fb.

ENDLOOP.


LOOP AT t_comb2 INTO w_comb2.

  UPDATE ztable
    SET cnt_cmb2 = w_comb2-count
    WHERE f2 = w_comb1-f2
    AND   fa = w_comb1-fa
    AND   fb = w_comb1-fb.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 14:09:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173080#M1372058</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T14:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173081#M1372059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When I loop through these records I need to count where the data in Field 1 , A and B are the same and where Field 2, A and b are the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example this is what my internal table would be like,&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*bold* Field 1  Field 2     A       B      Count
              XY                        D3     3        2
              XY                        D3     3        2
              XY                        D2     4        1
                             FF         D3     6        2
                             FF         D3     6        2
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then i loop though it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF B &amp;lt; 5&lt;/P&gt;&lt;P&gt;count field 1, A  and B&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;count Field 2, A and B&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I count the combination of XY, D3, A3 or XY, D2, J3 there is no problem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I count the combination of FF, D3, S6 my program can take up to 6/7 times longer to process.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 14:10:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173081#M1372059</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T14:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173082#M1372060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Damien,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to share your code with us for us to help you. In the mean time you can also try using the logic I have shown in my previous post and see it helps any.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 14:11:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173082#M1372060</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T14:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173083#M1372061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;Thanks very much for that reply. I'm sorry but I can't post my code.My code is very similar so I'll compare them and see if your code is quicker.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 14:24:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173083#M1372061</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T14:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Z table count issue. Database or code</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173084#M1372062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;Your code runs twice as fast as mine so in my DEV system. Thanks for your help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2009 15:17:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/z-table-count-issue-database-or-code/m-p/6173084#M1372062</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-09T15:17:58Z</dc:date>
    </item>
  </channel>
</rss>

