<?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: Problem is Sorting Numeric with Decimals in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367171#M1401309</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is exactly how sort works. Your requirement is wrong, if you still want to achieve that, then you cannot use one internal table for this purpose.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First append 3 values in ITAB1, then rest three values in ITAB2. ITAB1 and ITAB2 will have only one column. Then sort both tables, and append them in 3rd intenal table which will have 2 columns, you know what I mean?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You know I am bored and have some time right now, so I'll write the code for you ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  zsr_test13.
TYPES: BEGIN OF ty_type1,
         value TYPE char10,
       END OF ty_type1.
TYPES: BEGIN OF ty_sort,
        val1 TYPE char10,
        val2 TYPE char10,
       END OF ty_sort.

DATA : it1  TYPE STANDARD TABLE OF ty_type1,
       it2 TYPE STANDARD TABLE OF ty_type1,
       it3 TYPE STANDARD TABLE OF ty_sort,
       wa_it3 TYPE ty_sort.
DATA: temp_value TYPE char10.

APPEND '0.05' TO it1.
APPEND '0.03' TO it1.
APPEND '0.00' TO it1.

APPEND '0.00' TO it2.
APPEND '0.02' TO it2.
APPEND '0.06' TO it2.


SORT it1 DESCENDING BY value.
SORT it2 DESCENDING BY value.

DO 3 TIMES.
  READ TABLE it1 INDEX sy-index INTO temp_value.
  wa_it3-val1 = temp_value.
  READ TABLE it2 INDEX sy-index INTO temp_value.
  wa_it3-val2 = temp_value.
  APPEND wa_it3 TO it3.
ENDDO.

LOOP AT it3 INTO wa_it3.
  WRITE:/ wa_it3-val1,  20 wa_it3-val2.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Nov 2009 20:54:20 GMT</pubDate>
    <dc:creator>Shafiq_Rehman1</dc:creator>
    <dc:date>2009-11-25T20:54:20Z</dc:date>
    <item>
      <title>Problem is Sorting Numeric with Decimals</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367169#M1401307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi leads,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting problem in sorting when I sort on numeric values with decimals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here I am giving my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES : BEGIN OF ty_sort,
         val1 TYPE char10,
         val2 TYPE char10,
        END OF ty_sort.

DATA : it  TYPE STANDARD TABLE OF ty_sort,
       it2 TYPE STANDARD TABLE OF ty_sort,
       wa TYPE ty_sort.

wa-val1 = '0.05'.
wa-val2 =  '0.00'.
APPEND wa TO it.
CLEAR wa.

wa-val1 = '0.03'.
wa-val2 =  '0.02'.
APPEND wa TO it.
CLEAR wa.

wa-val1 = '0.00'.
wa-val2 =  '0.06'.
APPEND wa TO it.
CLEAR wa.

SORT it BY val1 DESCENDING val2 DESCENDING.

LOOP AT it2 INTO wa.
  WRITE : / wa-val1,  20 wa-val2.
  CLEAR wa.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;O/P : ( I am getting this output, which is not expected )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;0.05               0.00&lt;/P&gt;&lt;P&gt;0.03               0.02&lt;/P&gt;&lt;P&gt;0.00               0.06&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Expected O/P :&lt;/P&gt;&lt;P&gt;0.05               0.06&lt;/P&gt;&lt;P&gt;0.03               0.02&lt;/P&gt;&lt;P&gt;0.00               0.00&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Sandeep&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;Moderator message - Please use code tags around your code&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Nov 25, 2009 3:17 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2009 19:42:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367169#M1401307</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-25T19:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem is Sorting Numeric with Decimals</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367170#M1401308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The problem is with data declaration :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES : BEGIN OF ty_sort,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;val1 TYPE char10,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;val2 TYPE char10,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;END OF ty_sort.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Declare val1 and val2 as type p decimals 2 instead of char10 ...&lt;/P&gt;&lt;P&gt;Check your requirement as well ... I don't think this is correct ...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2009 19:45:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367170#M1401308</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-25T19:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problem is Sorting Numeric with Decimals</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367171#M1401309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is exactly how sort works. Your requirement is wrong, if you still want to achieve that, then you cannot use one internal table for this purpose.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First append 3 values in ITAB1, then rest three values in ITAB2. ITAB1 and ITAB2 will have only one column. Then sort both tables, and append them in 3rd intenal table which will have 2 columns, you know what I mean?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You know I am bored and have some time right now, so I'll write the code for you ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  zsr_test13.
TYPES: BEGIN OF ty_type1,
         value TYPE char10,
       END OF ty_type1.
TYPES: BEGIN OF ty_sort,
        val1 TYPE char10,
        val2 TYPE char10,
       END OF ty_sort.

DATA : it1  TYPE STANDARD TABLE OF ty_type1,
       it2 TYPE STANDARD TABLE OF ty_type1,
       it3 TYPE STANDARD TABLE OF ty_sort,
       wa_it3 TYPE ty_sort.
DATA: temp_value TYPE char10.

APPEND '0.05' TO it1.
APPEND '0.03' TO it1.
APPEND '0.00' TO it1.

APPEND '0.00' TO it2.
APPEND '0.02' TO it2.
APPEND '0.06' TO it2.


SORT it1 DESCENDING BY value.
SORT it2 DESCENDING BY value.

DO 3 TIMES.
  READ TABLE it1 INDEX sy-index INTO temp_value.
  wa_it3-val1 = temp_value.
  READ TABLE it2 INDEX sy-index INTO temp_value.
  wa_it3-val2 = temp_value.
  APPEND wa_it3 TO it3.
ENDDO.

LOOP AT it3 INTO wa_it3.
  WRITE:/ wa_it3-val1,  20 wa_it3-val2.
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2009 20:54:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367171#M1401309</guid>
      <dc:creator>Shafiq_Rehman1</dc:creator>
      <dc:date>2009-11-25T20:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Problem is Sorting Numeric with Decimals</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367172#M1401310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sandeep, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Change your data declaration.Take help on data types.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Nov 2009 00:10:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-is-sorting-numeric-with-decimals/m-p/6367172#M1401310</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-26T00:10:44Z</dc:date>
    </item>
  </channel>
</rss>

