<?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 group by  please help in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047775#M88396</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am tryinf group by in my select statement which is not working . please correct the code.&lt;/P&gt;&lt;P&gt;thanks &lt;/P&gt;&lt;P&gt;Vinayak &lt;/P&gt;&lt;P&gt;tables : ekko,ekpo,lfa1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;         ebeln like ekko-ebeln,&lt;/P&gt;&lt;P&gt;         bedat like ekko-bedat,&lt;/P&gt;&lt;P&gt;         lifnr like ekko-lifnr,&lt;/P&gt;&lt;P&gt;         netwr like ekpo-netwr,&lt;/P&gt;&lt;P&gt;         name1 like lfa1-name1,&lt;/P&gt;&lt;P&gt;         count type i,&lt;/P&gt;&lt;P&gt;      end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select-options: s_bedat for ekko-bedat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a&lt;SUB&gt;ebeln a&lt;/SUB&gt;lifnr a&lt;SUB&gt;bedat sum( b&lt;/SUB&gt;netwr )&lt;/P&gt;&lt;P&gt;    into corresponding fields of itab&lt;/P&gt;&lt;P&gt;    from ekko as a inner join ekpo as b on b&lt;SUB&gt;ebeln = a&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;     where a&lt;SUB&gt;bedat in s_bedat group by a&lt;/SUB&gt;ebeln a&lt;SUB&gt;lifnr a&lt;/SUB&gt;bedat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    select single name1 from lfa1 into itab-name1&lt;/P&gt;&lt;P&gt;       where lifnr = itab-lifnr.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on change of itab-lifnr.&lt;/P&gt;&lt;P&gt;  skip.&lt;/P&gt;&lt;P&gt;  write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; itab-lifnr, itab-name1.&lt;/P&gt;&lt;P&gt;endon.&lt;/P&gt;&lt;P&gt;write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; itab-ebeln, itab-bedat,itab-netwr.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 29 Oct 2005 06:02:30 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-10-29T06:02:30Z</dc:date>
    <item>
      <title>group by  please help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047775#M88396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am tryinf group by in my select statement which is not working . please correct the code.&lt;/P&gt;&lt;P&gt;thanks &lt;/P&gt;&lt;P&gt;Vinayak &lt;/P&gt;&lt;P&gt;tables : ekko,ekpo,lfa1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;         ebeln like ekko-ebeln,&lt;/P&gt;&lt;P&gt;         bedat like ekko-bedat,&lt;/P&gt;&lt;P&gt;         lifnr like ekko-lifnr,&lt;/P&gt;&lt;P&gt;         netwr like ekpo-netwr,&lt;/P&gt;&lt;P&gt;         name1 like lfa1-name1,&lt;/P&gt;&lt;P&gt;         count type i,&lt;/P&gt;&lt;P&gt;      end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select-options: s_bedat for ekko-bedat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a&lt;SUB&gt;ebeln a&lt;/SUB&gt;lifnr a&lt;SUB&gt;bedat sum( b&lt;/SUB&gt;netwr )&lt;/P&gt;&lt;P&gt;    into corresponding fields of itab&lt;/P&gt;&lt;P&gt;    from ekko as a inner join ekpo as b on b&lt;SUB&gt;ebeln = a&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;     where a&lt;SUB&gt;bedat in s_bedat group by a&lt;/SUB&gt;ebeln a&lt;SUB&gt;lifnr a&lt;/SUB&gt;bedat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    select single name1 from lfa1 into itab-name1&lt;/P&gt;&lt;P&gt;       where lifnr = itab-lifnr.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;endselect.&lt;/P&gt;&lt;P&gt;loop at itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on change of itab-lifnr.&lt;/P&gt;&lt;P&gt;  skip.&lt;/P&gt;&lt;P&gt;  write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; itab-lifnr, itab-name1.&lt;/P&gt;&lt;P&gt;endon.&lt;/P&gt;&lt;P&gt;write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; itab-ebeln, itab-bedat,itab-netwr.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Oct 2005 06:02:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047775#M88396</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-29T06:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: group by  please help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047776#M88397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See my comments below. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Dear All,&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; I am tryinf group by in my select statement which is&lt;/P&gt;&lt;P&gt;&amp;gt; not working . please correct the code.&lt;/P&gt;&lt;P&gt;&amp;gt; thanks &lt;/P&gt;&lt;P&gt;&amp;gt; Vinayak &lt;/P&gt;&lt;P&gt;&amp;gt; tables : ekko,ekpo,lfa1.&lt;/P&gt;&lt;P&gt;You do not need any tables statement. Just leave it away&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; data : begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;&amp;gt;          ebeln like ekko-ebeln,&lt;/P&gt;&lt;P&gt;&amp;gt;          bedat like ekko-bedat,&lt;/P&gt;&lt;P&gt;&amp;gt;          lifnr like ekko-lifnr,&lt;/P&gt;&lt;P&gt;&amp;gt;          netwr like ekpo-netwr,&lt;/P&gt;&lt;P&gt;&amp;gt;          name1 like lfa1-name1,&lt;/P&gt;&lt;P&gt;&amp;gt;          count type i,&lt;/P&gt;&lt;P&gt;&amp;gt;       end of itab.&lt;/P&gt;&lt;P&gt;personally I do not like the declaration of table with &lt;/P&gt;&lt;P&gt;header lines and occurs and I did not figure out what you want to do with the count column in your internal table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; select-options: s_bedat for ekko-bedat.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; select a&lt;SUB&gt;ebeln a&lt;/SUB&gt;lifnr a&lt;SUB&gt;bedat sum( b&lt;/SUB&gt;netwr )&lt;/P&gt;&lt;P&gt;&amp;gt;     into corresponding fields of itab&lt;/P&gt;&lt;P&gt;&amp;gt; from ekko as a inner join ekpo as b on b~ebeln =&lt;/P&gt;&lt;P&gt;&amp;gt; ln = a~ebeln&lt;/P&gt;&lt;P&gt;&amp;gt; where a&lt;SUB&gt;bedat in s_bedat group by a&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt;&amp;gt; ebeln a&lt;SUB&gt;lifnr a&lt;/SUB&gt;bedat.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt;     select single name1 from lfa1 into itab-name1&lt;/P&gt;&lt;P&gt;&amp;gt;        where lifnr = itab-lifnr.&lt;/P&gt;&lt;P&gt;&amp;gt; append itab.&lt;/P&gt;&lt;P&gt;&amp;gt; endselect.&lt;/P&gt;&lt;P&gt;&amp;gt; endselect.&lt;/P&gt;&lt;P&gt;There are tons of threads here advising not to use nested selects - in this case you could read the name of lfa1 right before you write it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select a&lt;SUB&gt;ebeln a&lt;/SUB&gt;lifnr a&lt;SUB&gt;bedat sum( b&lt;/SUB&gt;netwr )&lt;/P&gt;&lt;P&gt;     into table itab&lt;/P&gt;&lt;P&gt; from ekko as a inner join ekpo as b &lt;/P&gt;&lt;P&gt;              on b&lt;SUB&gt;ebeln =   a&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt; where a&lt;SUB&gt;bedat in s_bedat group by a&lt;/SUB&gt;ebeln&lt;/P&gt;&lt;P&gt; ebeln a&lt;SUB&gt;lifnr a&lt;/SUB&gt;bedat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;should work &lt;/P&gt;&lt;P&gt;(corresponding is not necessary but would not work, unless you do not use " sum( b~netwr ) as netwr ".&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;make sure to sort the table before loop over it&lt;/P&gt;&lt;P&gt;&amp;gt; loop at itab.&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; on change of itab-lifnr.&lt;/P&gt;&lt;P&gt;&amp;gt;   skip.&lt;/P&gt;&lt;P&gt;here you could read your name if you must. &lt;/P&gt;&lt;P&gt;select single name1 from lfa1 into itab-name1&lt;/P&gt;&lt;P&gt;        where lifnr = itab-lifnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;   write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; itab-lifnr, itab-name1.&lt;/P&gt;&lt;P&gt;&amp;gt; endon.&lt;/P&gt;&lt;P&gt;&amp;gt; write &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; itab-ebeln, itab-bedat,itab-netwr.&lt;/P&gt;&lt;P&gt;&amp;gt; endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH Christian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Oct 2005 07:26:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047776#M88397</guid>
      <dc:creator>ChristianFi</dc:creator>
      <dc:date>2005-10-29T07:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: group by  please help</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047777#M88398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It doesn't like you selecting sum( b&lt;SUB&gt;netwr ) into corresponding fields of itab because there is no field name &amp;lt;b&amp;gt;sum( b&lt;/SUB&gt;netwr ).&amp;lt;/b&amp;gt; Try:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TABLES: ekko,ekpo,lfa1.

DATA : BEGIN OF itab OCCURS 0,
  ebeln LIKE ekko-ebeln,
  bedat LIKE ekko-bedat,
  lifnr LIKE ekko-lifnr,
  netwr LIKE ekpo-netwr,
  name1 LIKE lfa1-name1,
  count TYPE i,
END OF itab.

SELECT-OPTIONS: s_bedat FOR ekko-bedat.

SELECT a~ebeln a~lifnr a~bedat SUM( b~netwr )
  INTO (itab-ebeln, itab-lifnr, itab-bedat, itab-netwr)
  FROM ekko AS a INNER JOIN ekpo AS b ON b~ebeln = a~ebeln
  WHERE a~bedat IN s_bedat
  GROUP BY A~EBELN a~lifnr A~BEDAT.

  SELECT SINGLE name1 FROM lfa1 INTO itab-name1
    WHERE lifnr = itab-lifnr.
  APPEND itab.
ENDSELECT.

LOOP AT itab.
  ON CHANGE OF itab-lifnr.
    SKIP.
    WRITE :/ itab-lifnr, itab-name1.
  ENDON.
  WRITE :/ itab-ebeln, itab-bedat,itab-netwr.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can also use the other sugestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Rob Burbank&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 29 Oct 2005 17:31:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/group-by-please-help/m-p/1047777#M88398</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-10-29T17:31:07Z</dc:date>
    </item>
  </channel>
</rss>

