<?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: table type with reference type -&amp;gt; how to sort? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505635#M233726</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Danial, please see the following.  In the case where you want to sort your reference by an attribute within the object, you can do something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.











*---------------------------------------------------------------------*
*       CLASS lcl_tab DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app definition.

  public section.
    data: attri type i.
    methods: constructor importing im_attri type i.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_tab IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.
  method constructor.
    attri = im_attri.
  endmethod.

endclass.


data: a_app type ref to lcl_app.
data: a_app_list type table of ref to lcl_app.

start-of-selection.



  create object a_app exporting im_attri =  3 .
  append a_app to a_app_list.
  create object a_app exporting im_attri =  2 .
  append a_app to a_app_list.
  create object a_app exporting im_attri =  1 .
  append a_app to a_app_list.



  sort a_app_list by &amp;lt;b&amp;gt;table_line-&amp;gt;attri&amp;lt;/b&amp;gt; ascending .

  check sy-subrc = 0.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the documentation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Access to Attributes with References in Internal Tables&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the line type of internal tables includes reference variables as components comp, the attributes attr of the object to which the reference in a line points can be used as key values for reading, sorting and changing table rows. This is possible in the following statements: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;,,LOOP AT itab ... WHERE comp-&amp;gt;attr ... 
,,READ TABLE itab ... WITH [TABLE] KEY comp-&amp;gt;attr = ... 
&amp;lt;b&amp;gt;,,SORT itab BY comp-&amp;gt;attr ...&amp;lt;/b&amp;gt; 
,,DELETE itab WHERE comp-&amp;gt;attr ... 
,,MODIFY itab ... TRANSPORTING ... WHERE comp-&amp;gt;attr ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;If a table contains unstructured lines with the type of a reference variable, the attributes of the object to which a line points can be addressed using TABLE_LINE-&amp;gt;attr.&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/i&amp;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;RIch Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 23 Aug 2006 15:26:07 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2006-08-23T15:26:07Z</dc:date>
    <item>
      <title>table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505630#M233721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have an internal table lt_refs of the type ZXX_TT_REFS.&lt;/P&gt;&lt;P&gt;The table type ZXX_TT_REFS is a table of references ("ref. type") to the class ZCL_C.&lt;/P&gt;&lt;P&gt;The class C has an attribute attr1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I would like to sort that table. Is there an easy (built-in) way to do this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA lt_refs TYPE ZXX_TT_REFS.
DATA lr_ref  TYPE REF TO ZCL_C.
LOOP AT lt_refs INTO lr_ref.
  "Sort based on lr_ref-&amp;gt;attr1. ?
ENDLOOP.
"or can I 
SORT lt_refs BY attr1.
"directly?
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 13:50:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505630#M233721</guid>
      <dc:creator>daniel_humberg</dc:creator>
      <dc:date>2006-08-23T13:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505631#M233722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can sort by referencing the attribute of the object.  See below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;


report zrich_0001.

*---------------------------------------------------------------------*
*       CLASS lcl_tab DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_tab definition.

  public section.

    types: ttab type table of string.

    data: itab type ttab.
    methods: constructor importing im_tab type ttab.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_tab IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_tab implementation.
  method constructor.
    itab[] = im_tab[].
  endmethod.

endclass.

data: l_itab type table of string.
data:  l_wa type string.
data: a_tab type ref to lcl_tab.

start-of-selection.

  l_wa = 'B'.  append l_wa to l_itab.
  l_wa = 'C'.  append l_wa to l_itab.
  l_wa = 'D'.  append l_wa to l_itab.
  l_wa = 'A'.  append l_wa to l_itab.

  create object a_tab
        exporting
            im_tab = l_itab.


&amp;lt;b&amp;gt;  sort a_tab-&amp;gt;itab ascending.&amp;lt;/b&amp;gt;


  check sy-subrc = 0.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REgards,&lt;/P&gt;&lt;P&gt;RIch Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 14:01:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505631#M233722</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-08-23T14:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505632#M233723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rich,&lt;/P&gt;&lt;P&gt;sure, I can sort an internal table that is the attribute of a class.&lt;/P&gt;&lt;P&gt;By how can I sort an interal table that itself consists of a list of references to objects of a class?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 14:56:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505632#M233723</guid>
      <dc:creator>daniel_humberg</dc:creator>
      <dc:date>2006-08-23T14:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505633#M233724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How exactly would you like to sort it?  By object reference identifier?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REgards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 15:03:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505633#M233724</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-08-23T15:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505634#M233725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And for what purpose?  They are simply dynamically created references.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 15:17:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505634#M233725</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-23T15:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505635#M233726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Danial, please see the following.  In the case where you want to sort your reference by an attribute within the object, you can do something like this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

report zrich_0001.











*---------------------------------------------------------------------*
*       CLASS lcl_tab DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app definition.

  public section.
    data: attri type i.
    methods: constructor importing im_attri type i.

endclass.


*---------------------------------------------------------------------*
*       CLASS lcl_tab IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_app implementation.
  method constructor.
    attri = im_attri.
  endmethod.

endclass.


data: a_app type ref to lcl_app.
data: a_app_list type table of ref to lcl_app.

start-of-selection.



  create object a_app exporting im_attri =  3 .
  append a_app to a_app_list.
  create object a_app exporting im_attri =  2 .
  append a_app to a_app_list.
  create object a_app exporting im_attri =  1 .
  append a_app to a_app_list.



  sort a_app_list by &amp;lt;b&amp;gt;table_line-&amp;gt;attri&amp;lt;/b&amp;gt; ascending .

  check sy-subrc = 0.


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the documentation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;i&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;&lt;/P&gt;&lt;P&gt;Access to Attributes with References in Internal Tables&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the line type of internal tables includes reference variables as components comp, the attributes attr of the object to which the reference in a line points can be used as key values for reading, sorting and changing table rows. This is possible in the following statements: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;,,LOOP AT itab ... WHERE comp-&amp;gt;attr ... 
,,READ TABLE itab ... WITH [TABLE] KEY comp-&amp;gt;attr = ... 
&amp;lt;b&amp;gt;,,SORT itab BY comp-&amp;gt;attr ...&amp;lt;/b&amp;gt; 
,,DELETE itab WHERE comp-&amp;gt;attr ... 
,,MODIFY itab ... TRANSPORTING ... WHERE comp-&amp;gt;attr ...&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;If a table contains unstructured lines with the type of a reference variable, the attributes of the object to which a line points can be addressed using TABLE_LINE-&amp;gt;attr.&amp;lt;/b&amp;gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/i&amp;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;RIch Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Aug 2006 15:26:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505635#M233726</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-08-23T15:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: table type with reference type -&gt; how to sort?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505636#M233727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tanks, Rich.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That's what I wanted.&lt;/P&gt;&lt;P&gt;I has something like this in mind, but I just couldn't find it in the doku.&lt;/P&gt;&lt;P&gt;Really cool!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Aug 2006 07:02:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-type-with-reference-type-gt-how-to-sort/m-p/1505636#M233727</guid>
      <dc:creator>daniel_humberg</dc:creator>
      <dc:date>2006-08-24T07:02:06Z</dc:date>
    </item>
  </channel>
</rss>

