<?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: select query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781951#M336962</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : v_abc like dbtab-abc.&lt;/P&gt;&lt;P&gt;data : itab like dbtab occurs 0 with header line.&lt;/P&gt;&lt;P&gt;select max( abc ) into v_abc from bdtab group by abc.&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select single * from dbtab into corresponding fields  of itab where abc = v_abc. &lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;shiba dutta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 11 Dec 2006 06:27:03 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-12-11T06:27:03Z</dc:date>
    <item>
      <title>select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781949#M336960</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;My requirement is to select records from a table based on a field (say abc )which has the max value.i.e. if field abc has value 2 &amp;amp; corresponding to this no. of records is 3 &amp;amp; the other value of abc is 4 which has the no. of records corresponding to it as 5 then i have to select first  record with field abc = 4 &amp;amp; if two values of abc have equal no. of records then select whichever comes first.&lt;/P&gt;&lt;P&gt;pls guide me for the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Helpful answers will be rewarded.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sipra&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 05:50:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781949#M336960</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T05:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781950#M336961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sipra&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please use a logic similar to below one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;select fld count( * ) into table itab
       from &amp;lt;table&amp;gt;
       where &amp;lt;cond&amp;gt;
       group by fld.
       
sort itab by count fld.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 06:03:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781950#M336961</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T06:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781951#M336962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : v_abc like dbtab-abc.&lt;/P&gt;&lt;P&gt;data : itab like dbtab occurs 0 with header line.&lt;/P&gt;&lt;P&gt;select max( abc ) into v_abc from bdtab group by abc.&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select single * from dbtab into corresponding fields  of itab where abc = v_abc. &lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;shiba dutta&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 06:27:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781951#M336962</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T06:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781952#M336963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Eswar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thnx but how to select record based on this field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pls help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 06:35:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781952#M336963</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T06:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781953#M336964</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;&lt;/P&gt;&lt;P&gt;If you need field's maximum value,then you need to use group by and max function as suggested.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need max no. of occurence of a particular field's value,thne use have to use count(*).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think if you break the query rather than going for sub query,it would be easy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 06:46:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781953#M336964</guid>
      <dc:creator>jayanthi_jayaraman</dc:creator>
      <dc:date>2006-12-11T06:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781954#M336965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check this, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA : BEGIN OF ITAB OCCURS 0,
       F1 TYPE I,
       F2 TYPE I,
       END OF ITAB.

       ITAB-F1 = 2.
       ITAB-F2 = 3.
       APPEND ITAB.

       ITAB-F1 = 4.
       ITAB-F2 = 5.
       APPEND ITAB.

       ITAB-F1 = 2.
       ITAB-F2 = 7.
       APPEND ITAB.

SORT ITAB BY F1 DESCENDING F2 DESCENDING.
       LOOP AT ITAB.

       WRITE:/ ITAB-F1,
               ITAB-F2.

       ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;O/P IS  &lt;/P&gt;&lt;P&gt;           4            5          "selection priority to 4 first &lt;/P&gt;&lt;P&gt;           2            7 &lt;/P&gt;&lt;P&gt;           2            3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOW BY CHANGING SORT ITAB BY F2 DESCENDING F1 DESCENDING&lt;/P&gt;&lt;P&gt;TO SORT ITAB BY F1 DESCENDING F2 DESCENDING&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CASE B.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA : BEGIN OF ITAB OCCURS 0,
       F1 TYPE I,
       F2 TYPE I,
       END OF ITAB.

       ITAB-F1 = 2.
       ITAB-F2 = 3.
       APPEND ITAB.

       ITAB-F1 = 4.
       ITAB-F2 = 5.
       APPEND ITAB.

       ITAB-F1 = 2.
       ITAB-F2 = 7.
       APPEND ITAB.

SORT ITAB BY F2 DESCENDING F1 DESCENDING.  "IF U WANT TO GIVE F2 PRIORITY
       LOOP AT ITAB.

       WRITE:/ ITAB-F1,
               ITAB-F2.

       ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;O/P IS   2   7    " if i make f2 priority &lt;/P&gt;&lt;P&gt;             4   5&lt;/P&gt;&lt;P&gt;             2   3&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;i think u r option is case A .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps just try to rearrange the format in ur value selection based on the sorttation .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;vijay&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;like try to fetch the values of ur field ABC into an internal table as shown above and make a selection from the other table by using for all entries .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select ,,,,from XXXX&lt;/P&gt;&lt;P&gt;for all entries where f1 = itab-f1 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is this case not possible in ur criteria.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the only thing is just the operation on the itab has to be sorted down . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        vijay k&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 07:07:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781954#M336965</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T07:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: select query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781955#M336966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hope this example can give you some idea:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;tables: vbap.
select-options: s_aedat for vbap-aedat,
                s_vbeln for vbap-vbeln.

types: begin of t_data,
         vbeln type vbeln,
         cnt type i,
       end of t_data.
data: it_data type table of t_data,
      wa_data type t_data.
data: it_vbap type table of vbap.


select vbeln count( * ) into table it_data
       from vbap
       where aedat in s_aedat
       and   vbeln in s_vbeln
       group by vbeln.
sort it_data by cnt descending vbeln.

read table it_data into wa_data index 1.

select * into table it_vbap from vbap where vbeln = wa_data-vbeln.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Eswar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 11 Dec 2006 07:21:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-query/m-p/1781955#M336966</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-12-11T07:21:30Z</dc:date>
    </item>
  </channel>
</rss>

