<?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: Question on Select query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252290#M1213408</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;After retrieving data from db tab to int tab say it_tab,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT it_tab DESCENDING BY zident date. "Now for each zident latest date will be the first entry
  DELETE ADJACENT DUPLICATES FROM it_tab COMPARING zident. "Now only status with latest 
                                          "date remains and others deleted&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Manoj Kumar P&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Manoj Kumar on Feb 11, 2009 3:55 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 11 Feb 2009 14:54:46 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-02-11T14:54:46Z</dc:date>
    <item>
      <title>Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252288#M1213406</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 need to prepare a select query which can fetch the below mentioned scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ztable has fields zident, date, time, status. (zident, date, time are key fields)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;zident      date        time               status       &lt;/P&gt;&lt;P&gt;10001    02/09/09    111111                s&lt;/P&gt;&lt;P&gt;10001    02/08/09    222222                p&lt;/P&gt;&lt;P&gt;10001    02/07/09     333333               s        from this set only one ident should come which               &lt;/P&gt;&lt;P&gt;10001    02/01/09     333333               s        has latest status&lt;/P&gt;&lt;P&gt;10001    02/02/09     333333               s&lt;/P&gt;&lt;P&gt;10001    02/03/09     333333               s&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;10002    02/09/09    111111                s&lt;/P&gt;&lt;P&gt;10002    02/08/09    222222                p&lt;/P&gt;&lt;P&gt;10002    02/07/09     333333               s      from this set only one ident should come which               &lt;/P&gt;&lt;P&gt;10002    02/01/09     333333               s      has latest status&lt;/P&gt;&lt;P&gt;10002    02/02/09     333333               s&lt;/P&gt;&lt;P&gt;10002    02/03/09     333333               s&lt;/P&gt;&lt;P&gt;              and so on.............&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from one set of ident one record should come in this way so many set of idents will be there.&lt;/P&gt;&lt;P&gt;My question is how to form the select query&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 14:34:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252288#M1213406</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T14:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252289#M1213407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Chandra,&lt;/P&gt;&lt;P&gt;Your solution lies in the concept of Control-Break Statements.&lt;/P&gt;&lt;P&gt;AT NEW.. &lt;/P&gt;&lt;P&gt;AT END OF &lt;/P&gt;&lt;P&gt;AT LAST, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;DATA:
  BEGIN OF fs_table,
    zident TYPE char20,
    date   TYPE sy-datum,
    time  TYPE sy-uzeit,
    status TYPE C,
  END OF fs_table.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA:&lt;/P&gt;&lt;P&gt;        t_table LIKE&lt;/P&gt;&lt;P&gt; STANDARD TABLE&lt;/P&gt;&lt;P&gt;              of   fs_table.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

" Populate the data in Internal Table.

" While displaying data.

LOOP AT t_table INTO fs_table.
  AT NEW status.
     WRITE:/ fs_table-status.
  ENDAT.
     WRITE:/ fs_table-zident,
                  fs_table-date,
                  fs_table-time.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also use ON CHANGE OF fs_table-status, instead of AT NEW, if you get ***&lt;STRONG&gt;/&lt;/STRONG&gt;&lt;STRONG&gt;/&lt;/STRONG&gt;* for date and time.&lt;/P&gt;&lt;P&gt;With this, status will be displayed once and remaining will following under it.&lt;/P&gt;&lt;P&gt;If you want everything to be displayed on change of each new field, apply that to every field,&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt; AT NEW zident.&lt;/P&gt;&lt;P&gt;   WRITE:/ fs_table-zident.&lt;/P&gt;&lt;P&gt;  ENDAT.&lt;/P&gt;&lt;P&gt; AT NEW date.&lt;/P&gt;&lt;P&gt;   WRITE: fs_table-date.&lt;/P&gt;&lt;P&gt; ENDAT.&lt;/P&gt;&lt;P&gt;.. so on and so forth.&lt;/P&gt;&lt;P&gt;This is just a test-case, try using the control break statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks: Zahack&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 14:51:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252289#M1213407</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T14:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252290#M1213408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;After retrieving data from db tab to int tab say it_tab,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT it_tab DESCENDING BY zident date. "Now for each zident latest date will be the first entry
  DELETE ADJACENT DUPLICATES FROM it_tab COMPARING zident. "Now only status with latest 
                                          "date remains and others deleted&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Manoj Kumar P&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Manoj Kumar on Feb 11, 2009 3:55 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 14:54:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252290#M1213408</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T14:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252291#M1213409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SQL is your friend.  Let the database do the work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select 
zident date time status
from ztable as
where z~date = (select max(zz~date)
                from ztable as zz
                where zz~zident = z~zident)
and z~time = ( select max(zz~time)
                from ztable as zz
                where zz~zident = z~zident
                and zz~date = z~date)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 15:08:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252291#M1213409</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T15:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252292#M1213410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jerry,&lt;/P&gt;&lt;P&gt;I think nested SQL queries may be costly to use.&lt;/P&gt;&lt;P&gt;Does it not effect the performance.&lt;/P&gt;&lt;P&gt;Please guide.&lt;/P&gt;&lt;P&gt;Thanks: Zahack&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 15:10:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252292#M1213410</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T15:10:59Z</dc:date>
    </item>
    <item>
      <title>Re: Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252293#M1213411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all, this is not a nested query, it is a "&lt;STRONG&gt;correlated subquery&lt;/STRONG&gt;".  Secondly, according to the OP  zident, date, time are key fields, and the subquery will use the index.  Thirdly, reducing IO and network traffic is almost always a good thing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 15:14:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252293#M1213411</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T15:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Question on Select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252294#M1213412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jerry,&lt;/P&gt;&lt;P&gt;I didn't know about it.&lt;/P&gt;&lt;P&gt;Thanks for guidance.&lt;/P&gt;&lt;P&gt;Zahack&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Feb 2009 15:24:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/question-on-select-query/m-p/5252294#M1213412</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-11T15:24:20Z</dc:date>
    </item>
  </channel>
</rss>

