<?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 statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524753#M240488</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SELECT xref1 shkzg sum(saknr)&lt;/P&gt;&lt;P&gt;FROM bseg&lt;/P&gt;&lt;P&gt;INTO TABLE itab.&lt;/P&gt;&lt;P&gt;group by xref1 shkzg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab.&lt;/P&gt;&lt;P&gt;Loop at itab.&lt;/P&gt;&lt;P&gt;  if itab-shkzg = 'S'.&lt;/P&gt;&lt;P&gt;     lrev = itab-saknr.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;     lcost = itab-saknr.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;  at end of xref1.&lt;/P&gt;&lt;P&gt;     ldiff = lrev - lcost.&lt;/P&gt;&lt;P&gt;     lperc = ldiff * 100 / 4300.&lt;/P&gt;&lt;P&gt;     write : / itab-xref1, lrev, lcost, ldiff, lperc.   &lt;/P&gt;&lt;P&gt;  endat.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 07 Sep 2006 09:58:55 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-09-07T09:58:55Z</dc:date>
    <item>
      <title>select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524750#M240485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi to all,&lt;/P&gt;&lt;P&gt; help me in wrting trhe select statement&lt;/P&gt;&lt;P&gt;input is jobno revenue cost(both from same table and field)&lt;/P&gt;&lt;P&gt;Job Number Revenue Cost Difference Percentage&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;IE1111     5000   2500  2500       2500/4300*100&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;IE2222     3000   1200  1800       1800/4300*100&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; Total     8000   3700  4300&lt;/P&gt;&lt;P&gt; here job no is from bseg-xref1&lt;/P&gt;&lt;P&gt;revenue is from bseg-saknr&lt;/P&gt;&lt;P&gt;cost is from bseg-saknr&lt;/P&gt;&lt;P&gt;differnece is revenue-cost&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;kiran kumar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Sep 2006 20:30:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524750#M240485</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-06T20:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524751#M240486</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;I would be inclined to do a basic select to get the data from the table and then loop through the results to perform the calculations, something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT xref1 saknr shkzg
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE itab_tmp.

* Make sure table is sorted by job number
SORT itab_tmp BY xref1.

LOOP AT itab_tmp INTO wa_itab_tmp.

* Using AT control so copy the work area
  wa_itab_1 = wa_itab_tmp.

* If the line is a debit
  If wa_itab_1-shkzg = 'S'. 

*   Record value as a cost and add to the total
    wa_itab_2-cost = wa_itab_1-saknr.
    total_cost = total_cost + wa_itab_1-saknr.

* Otherwise it is a credit
  ELSE.  

*   Record value as revenue and add to the total
    wa_itab_2-rev = wa_itab_1-saknr.
    total_rev = total_rev + wa_itab_1-saknr.
  ENDIF.

* At the end of each job number calculate the difference
* and percentage and append line to a new table
  AT END OF xref1.
    wa_itab_2-xref1 = wa_itab_1-xref1.
    wa_itab_2-diff = wa_itab_2-rev - wa_itab_2-cost.
    wa_itab_2-perc = wa_itab_2-diff / 4300 * 100.
    APPEND wa_itab_2 TO itab_result.

ENDLOOP.
* At end of loop calculate the total difference
total_diff = total_rev - total_cost.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've not tested this but it should give you an idea of what to do, you'll obviously need to declare all the variables etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 09:43:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524751#M240486</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T09:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524752#M240487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SELECT xref1 saknr shkzg&lt;/P&gt;&lt;P&gt;FROM bseg&lt;/P&gt;&lt;P&gt;INTO CORRESPONDING FIELDS OF TABLE itab.&lt;/P&gt;&lt;P&gt;IF sy-subrc&amp;lt;&amp;gt;0.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*do the neccassary operations on itab.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 09:46:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524752#M240487</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T09:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524753#M240488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SELECT xref1 shkzg sum(saknr)&lt;/P&gt;&lt;P&gt;FROM bseg&lt;/P&gt;&lt;P&gt;INTO TABLE itab.&lt;/P&gt;&lt;P&gt;group by xref1 shkzg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab.&lt;/P&gt;&lt;P&gt;Loop at itab.&lt;/P&gt;&lt;P&gt;  if itab-shkzg = 'S'.&lt;/P&gt;&lt;P&gt;     lrev = itab-saknr.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;     lcost = itab-saknr.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;  at end of xref1.&lt;/P&gt;&lt;P&gt;     ldiff = lrev - lcost.&lt;/P&gt;&lt;P&gt;     lperc = ldiff * 100 / 4300.&lt;/P&gt;&lt;P&gt;     write : / itab-xref1, lrev, lcost, ldiff, lperc.   &lt;/P&gt;&lt;P&gt;  endat.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 09:58:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524753#M240488</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T09:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524754#M240489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi to all&lt;/P&gt;&lt;P&gt;loop at it_bseg2.&lt;/P&gt;&lt;P&gt;move it_bseg2-saknr1 to it_final-saknr1.&lt;/P&gt;&lt;P&gt;move it_bseg2-wrbtr to it_final-wrbtr1.&lt;/P&gt;&lt;P&gt;append it_final.&lt;/P&gt;&lt;P&gt;clear it_final.&lt;/P&gt;&lt;P&gt;here wrbtr is coming to herader line not body&lt;/P&gt;&lt;P&gt;what is command used to keep it in body&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;&lt;P&gt;kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 10:07:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524754#M240489</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T10:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524755#M240490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry can you be more specific about the problem it is in header line and body ???&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 10:12:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524755#M240490</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T10:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524756#M240491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi it is in header line not in body how to insert it in body&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 10:18:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524756#M240491</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T10:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524757#M240492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kiran&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not entirely sure I understand your question.  When you loop through an internal table with a header line then the contents of each row are copied into the header line.  You can then make changes to the data but these will not be 'saved' back into the table unless Append/Modify the table.  Your code seems OK to me, you loop through it_bseg2, copy the contents from one header line to anther and then append the second header line, which should add the contents to the table it_final.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming it_final is declared with a header line then using the CLEAR command should only clear the contents of the header row for such tables so that should be fine too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could be more specific about what exaclt is happening and what you are trying to achieve.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 10:20:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524757#M240492</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T10:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524758#M240493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi it is in header line not in body how to insert it in body&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 10:21:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524758#M240493</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T10:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: select statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524759#M240494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Kiran&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So at the end of each iteration, the header line of it_final contains the data copied from the header line of it_bseg2.  The Append it_final command is executed but the contents of the it_final header line are not added to the table itself.  Presumably the clear statement then empties the header line.  Is this correct?&lt;/P&gt;&lt;P&gt;Could you please post your table declarations? I think the code you have posted should work!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Sep 2006 10:39:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/1524759#M240494</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-09-07T10:39:34Z</dc:date>
    </item>
  </channel>
</rss>

