<?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 Sort Operation on Date and Time fields in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512673#M1559733</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; I am trying to SORT the data in descending order based on date and time. System is behaving weird and I am not able to get the actual results. Please suggest me regarding SORT operation on date and time fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: In my actual scenario my internal table has many fields along with date and time fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF temp,&lt;/P&gt;&lt;P&gt;         lv_date TYPE d,&lt;/P&gt;&lt;P&gt;         lv_time TYPE t,&lt;/P&gt;&lt;P&gt;       END OF temp.&lt;/P&gt;&lt;P&gt;DATA: itab TYPE TABLE OF temp,&lt;/P&gt;&lt;P&gt;      wa TYPE temp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101218'.  " yyyymmdd&lt;/P&gt;&lt;P&gt;wa-lv_time = '050505'.    " hhmmss&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101219'.&lt;/P&gt;&lt;P&gt;wa-lv_time = '050504'.&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101218'.&lt;/P&gt;&lt;P&gt;wa-lv_time = '050506'.&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab STABLE BY lv_date lv_time DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO wa.&lt;/P&gt;&lt;P&gt;    write:/ wa-lv_date, lv_time.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result: Date             Time&lt;/P&gt;&lt;P&gt;            20101218    050506&lt;/P&gt;&lt;P&gt;            20101218    050505&lt;/P&gt;&lt;P&gt;            20101219    050504&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expected Result:&lt;/P&gt;&lt;P&gt;             Date             Time&lt;/P&gt;&lt;P&gt;            20101219    050504&lt;/P&gt;&lt;P&gt;            20101218    050506&lt;/P&gt;&lt;P&gt;            20101218    050505&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;Regards,&lt;/P&gt;&lt;P&gt;Somu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Dec 2010 05:05:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-12-07T05:05:10Z</dc:date>
    <item>
      <title>Sort Operation on Date and Time fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512673#M1559733</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; I am trying to SORT the data in descending order based on date and time. System is behaving weird and I am not able to get the actual results. Please suggest me regarding SORT operation on date and time fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: In my actual scenario my internal table has many fields along with date and time fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF temp,&lt;/P&gt;&lt;P&gt;         lv_date TYPE d,&lt;/P&gt;&lt;P&gt;         lv_time TYPE t,&lt;/P&gt;&lt;P&gt;       END OF temp.&lt;/P&gt;&lt;P&gt;DATA: itab TYPE TABLE OF temp,&lt;/P&gt;&lt;P&gt;      wa TYPE temp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101218'.  " yyyymmdd&lt;/P&gt;&lt;P&gt;wa-lv_time = '050505'.    " hhmmss&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101219'.&lt;/P&gt;&lt;P&gt;wa-lv_time = '050504'.&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101218'.&lt;/P&gt;&lt;P&gt;wa-lv_time = '050506'.&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab STABLE BY lv_date lv_time DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO wa.&lt;/P&gt;&lt;P&gt;    write:/ wa-lv_date, lv_time.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result: Date             Time&lt;/P&gt;&lt;P&gt;            20101218    050506&lt;/P&gt;&lt;P&gt;            20101218    050505&lt;/P&gt;&lt;P&gt;            20101219    050504&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expected Result:&lt;/P&gt;&lt;P&gt;             Date             Time&lt;/P&gt;&lt;P&gt;            20101219    050504&lt;/P&gt;&lt;P&gt;            20101218    050506&lt;/P&gt;&lt;P&gt;            20101218    050505&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;Regards,&lt;/P&gt;&lt;P&gt;Somu.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 05:05:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512673#M1559733</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-07T05:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Operation on Date and Time fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512674#M1559734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Try this &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab STABLE BY lv_date DESCENDING&lt;/P&gt;&lt;P&gt;                                     lv_time DESCENDING.&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,&lt;/P&gt;&lt;P&gt;Madhukar Shetty&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 05:08:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512674#M1559734</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-07T05:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Operation on Date and Time fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512675#M1559735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the solution. Jai ho SDN &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt; and the users.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 05:24:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512675#M1559735</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-07T05:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Operation on Date and Time fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512676#M1559736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hai friend,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF temp,&lt;/P&gt;&lt;P&gt;lv_date TYPE d,&lt;/P&gt;&lt;P&gt;lv_time TYPE t,&lt;/P&gt;&lt;P&gt;END OF temp.&lt;/P&gt;&lt;P&gt;DATA: itab TYPE TABLE OF temp,&lt;/P&gt;&lt;P&gt;wa TYPE temp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101218'. " yyyymmdd&lt;/P&gt;&lt;P&gt;wa-lv_time = '050505'. " hhmmss&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101219'.&lt;/P&gt;&lt;P&gt;wa-lv_time = '050504'.&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wa-lv_date = '20101218'.&lt;/P&gt;&lt;P&gt;wa-lv_time = '050506'.&lt;/P&gt;&lt;P&gt;APPEND wa TO itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab by lv_time lv_date  DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT itab INTO wa.&lt;/P&gt;&lt;P&gt;write:/ wa-lv_date, wa-lv_time.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do like this u can get the out put i checked also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;anji.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 05:26:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512676#M1559736</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-07T05:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Operation on Date and Time fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512677#M1559737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Soma,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The system is behaving correctly. How ? Let me explain....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you write SORT ITAB component1 ASCENDING / DESCENDING , then the component1 of itab will be sorted in ascending or descending manner. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And here if you dont mention ASCENDING / DESCENDING, then by default it is sorted in the Ascending mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in your case you have coded like this -:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab STABLE BY lv_date lv_time DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This means first itab will be sorted in Ascending mode for lv_date (from lower date to higher date) and then within the same date range, the table will be sorted in the descending mode for lv_time (From higher time to lower time).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if you code like this -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SORT itab STABLE BY lv_date DESCENDING lv_time DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then both lv_date and lv_time will be sorted in descending mode. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Deb&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Dec 2010 05:30:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-operation-on-date-and-time-fields/m-p/7512677#M1559737</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-12-07T05:30:55Z</dc:date>
    </item>
  </channel>
</rss>

