<?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/3983990#M951741</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Christine Evans,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your answer. It really solved my problem, but I need to change the field data type into NUMC2 instead of CHAR2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess this is the better and faster way to solve the problem.&lt;/P&gt;&lt;P&gt;I never know there is a MAX feature in ABAP select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks alot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jun 2008 14:20:37 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-17T14:20:37Z</dc:date>
    <item>
      <title>Select statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983987#M951738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am currently working on an inserting records program.&lt;/P&gt;&lt;P&gt;Before the record is inserted into a table. It will perform a SELECT query to get the latest running number. My problem here is the COUNTER field in the table is designed in CHAR11.&lt;/P&gt;&lt;P&gt;With the SELECT statement showing below, it will hits a problem when the running number increased to 10. The select statement will not getting the latest number - 10. It will always getting number - 9. It is because it is descending order 10 is considering 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my program :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT charg counter FROM ztable_test UP TO 1 ROWS
  INTO (lf_charg, lv_counter)
  WHERE charg EQ ls_table-charg
    AND minch EQ ls_table-minch
    AND ccod1 EQ ls_table-ccod1
  ORDER BY counter DESCENDING.
ENDSELECT.
IF sy-subrc EQ 0.
  ls_osada-counter = lv_counter + 1.
  INSERT ztspp_osada2 FROM ls_osada.
  EXIT.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I remember in either DB2 or Oracle, the select statement can be like this: &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT charg, INT(counter) FROM ztable_test
  WHERE charg = ls_table-charg
    AND minch = ls_table-minch
    AND ccod1= ls_table-ccod1
  ORDER BY INT(counter) DESCENDING.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How should I do it in ABAP?&lt;/P&gt;&lt;P&gt;I would really appreciate if someone can help me on this.&lt;/P&gt;&lt;P&gt;Sample of code would greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2008 10:27:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983987#M951738</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-17T10:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983988#M951739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure I quite understand your problem.  But if you want to get the MAX COUNTER value from the table for the criteria in your WHERE clause, why not just use MAX?  Something like....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT charg max( counter )
INTO      var1  var2
FROM    tab
WHERE   .....
GROUP BY charg.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I'd probably define my COUNTER variable as integer and not char.  Though char should work ok since all you're doing it just selecting a value into it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;......just re-read your original message and you say the counter field in the table is defined as char.  Why would anyone want to define a counter field as char?  If it were even defined as NUMC then would get the leading zeros that would make your ordering or the use of MAX work properly.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any way that you get redefine the table column?  If not, I'm not sure what you can do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Christine Evans on Jun 17, 2008 4:01 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2008 13:35:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983988#M951739</guid>
      <dc:creator>christine_evans</dc:creator>
      <dc:date>2008-06-17T13:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983989#M951740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;myahsam  &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;i have code but am not sure how can i put here as you create block for code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you please tell me how can we create a block for code so that i can paste a code inside it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Amit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2008 14:13:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983989#M951740</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-17T14:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983990#M951741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Christine Evans,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your answer. It really solved my problem, but I need to change the field data type into NUMC2 instead of CHAR2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess this is the better and faster way to solve the problem.&lt;/P&gt;&lt;P&gt;I never know there is a MAX feature in ABAP select statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks alot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2008 14:20:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983990#M951741</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-17T14:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983991#M951742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Amit,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What do you mean by block for code?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you are trying to ask how to paste the code into this thread.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  "remove the space within the blacket&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paste your code here...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  "remove the space within the blacket&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2008 14:24:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement/m-p/3983991#M951742</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-17T14:24:42Z</dc:date>
    </item>
  </channel>
</rss>

