<?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 latest record from a database table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400096#M193444</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Select the record from the database table in the internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE itab INTO wa_itab INDEX 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will get the latest record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: mukesh kumar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Jul 2006 10:45:41 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-07-10T10:45:41Z</dc:date>
    <item>
      <title>select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400091#M193439</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;How do you select the latest record from a databse table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Nishant&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 10:40:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400091#M193439</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T10:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400092#M193440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SELECT MAX (document_number) FROM &amp;lt;table&amp;gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 10:42:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400092#M193440</guid>
      <dc:creator>dani_mn</dc:creator>
      <dc:date>2006-07-10T10:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400093#M193441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;IF YOU HAVE AN INCREMENTAL NUMBER IN YOUR TABLE YOU CAN USE..&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT
MAX( FIELDNAME )
INTO MYVARIABLE
FROM TABLE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also see this link ==&amp;gt;&lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="1944056"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RGDS,&lt;/P&gt;&lt;P&gt;tm&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 10:43:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400093#M193441</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T10:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400094#M193442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unless you have a DATE and TIME field in the database table, there is no way of knowing which is the latest record. If you have those fields select all the fields that match your criteria, sort them in DESC manner of DATE and TIME and READ the first row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 10:43:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400094#M193442</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T10:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400095#M193443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sort itab by field1 desending.&lt;/P&gt;&lt;P&gt;1st record is  ur   latest record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ex--&lt;/P&gt;&lt;P&gt;sort itab1 by docno decending.&lt;/P&gt;&lt;P&gt;read table itab1 index 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 10:43:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400095#M193443</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T10:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400096#M193444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Select the record from the database table in the internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE itab INTO wa_itab INDEX 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will get the latest record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: mukesh kumar&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 10:45:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400096#M193444</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T10:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400097#M193445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nishant, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the option &amp;lt;b&amp;gt;ORDER BY &amp;lt;/b&amp;gt; in your SELECT clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the SAP Documentation for &amp;lt;b&amp;gt;ORDER BY &amp;lt;/b&amp;gt; option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;Variant 1&amp;lt;/i&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;...ORDER BY PRIMARY KEY&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Effect&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;Sorts the selected lines in ascending order by the primary key of the database table. This variant is only permitted for SELECT * .... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;Notes&amp;lt;/i&amp;gt; &lt;/P&gt;&lt;P&gt;Since views do not have a primary key, specifying ORDER BY PRIMARY KEY only makes sense with database tables. If, however, you do specify ORDER BY PRIMARY KEY with a view, all fields of the view are sorted in ascending order. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;Variant 2&amp;lt;/i&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;ORDER BY f1 ... fn&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;Effect&amp;lt;/i&amp;gt; &lt;/P&gt;&lt;P&gt;Sorts the selected records in ascending order by the specified column references f1 ... fn. If a list is also specified in the SELECT clause, the column references f1, ..., fn must appear in this list. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By supplementing the statement with DESCENDING, you can sort in descending order using any of the fields f1, ..., fn. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The default sort sequence is ascending order, but you can make this explicit by adding the addition ASCENDING. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Consider this code this will select the latest 10 records form DB table(Note can use &amp;lt;b&amp;gt;Variant 2&amp;lt;/b&amp;gt; for DB tables also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zarun_1.


DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.

START-OF-SELECTION.

  SELECT * FROM mara
            INTO TABLE it_mara
            &amp;lt;b&amp;gt;UP TO 10 ROWS                "No of rows you need(give 1 here)
           ORDER BY matnr DESCENDING.    "Specify the Key Fields here.&amp;lt;/b&amp;gt;

  LOOP AT it_mara.

    WRITE : / it_mara-matnr,
              it_mara-mtart.


  ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arun Sambargi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Arun Sambargi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 11:01:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400097#M193445</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T11:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400098#M193446</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;    As far as I know there is no way you can select latest records from a table in SAP unless date &amp;amp; time field are specified. Transactional data doesn't have date &amp;amp; time fields unlike master data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   Try with Native SQL there may be some options from database end. with in SAP I don't think it is possible but try this option come from Master record for example if you want latest record in EKPO try to come from EKKO as there you have date field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Karthik.k&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 11:23:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400098#M193446</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-07-10T11:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400099#M193447</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;or look &lt;A class="jive_macro jive_macro_message" href="https://community.sap.com/" __jive_macro_name="message" modifiedtitle="true" __default_attr="1933797"&gt;&lt;/A&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;regards Andreas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2006 12:46:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400099#M193447</guid>
      <dc:creator>andreas_mann3</dc:creator>
      <dc:date>2006-07-10T12:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: select latest record from a database table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400100#M193448</link>
      <description>&lt;P&gt;Great! it works. Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 19 May 2023 19:47:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-latest-record-from-a-database-table/m-p/1400100#M193448</guid>
      <dc:creator>andresperez818</dc:creator>
      <dc:date>2023-05-19T19:47:23Z</dc:date>
    </item>
  </channel>
</rss>

