<?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>Question Re: oData multilevel entity with self reference? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaa-p/702622#M190882</link>
    <description>&lt;P&gt;You have to explicitly specify how many levels you want to expand, e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET PRODAREASet?$expand=PRODAREAS,PRODAREAS/PRODAREAS,PRODAREAS/PRODAREAS/PRODAREAS&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to expand three levels deep.&lt;/P&gt;&lt;P&gt;OData V4 adds a shortcut&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET PRODAREASet?$expand=PRODAREAS($levels=3)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and even allows&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET PRODAREASet?$expand=PRODAREAS($levels=max)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to request the maximum number of levels supported by the service (which is allowed to defend itself against DOS attacks by interpreting "max" appropriately &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Oct 2018 16:21:47 GMT</pubDate>
    <dc:creator>RalfHandl</dc:creator>
    <dc:date>2018-10-18T16:21:47Z</dc:date>
    <item>
      <title>oData multilevel entity with self reference?</title>
      <link>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaq-p/702621</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;I have a flat list of products which are in basicly a product hierarchy. So each entry in the table has an id and parent id, while the parent id can point to an id of a different entry in the table. What i now want to achieve is to build a oData which can expand the whole tree while the level of deepenes is unknown and respond with a nested json that represents the hierarchy.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;So i have built the oData with one entity (product list) and have defined association from the entity to it self by mapping id to parent id with an 1:M association. I also have created a Navigation Property which points to the association.&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/236595-association.jpg" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;/P&gt;
  &lt;P&gt;Now i started to overwrite the GET_EXPANDED_ENTITYSET method. What i want to achieve is, that whenever the oData is called with the url /sap/opu/odata/sap/ZORG_TEST_SRV/PRODAREASet?$expand=PRODAREAS&amp;amp;$format=json it responds with a nested json that shows the complete hierarchy, all levels. &lt;/P&gt;
  &lt;P&gt;Now i am wondering how to build the hierachy inside the method, beause the generated structure in mpc class does not have any table for child nodes. &lt;/P&gt;
  &lt;P&gt;i tried to built a local type (product), a table type of my local type and the local type that includes the table of itself but this seem not to work. I have also tried a class instead of structure but then copy_data_to_ref call inside GET_EXPANDED_ENTITYSET gave me an error that ref are not allowed.&lt;/P&gt;
  &lt;P&gt;Is this use case even possible with oData if you do not know how deep your structure can be? Basicly i need an "expand all" with unknown deepness for an entity that self references 1:n&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;Thank you and Best Regards&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;&lt;/P&gt;
  &lt;P&gt;Dimitri&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 16:13:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaq-p/702621</guid>
      <dc:creator>_Dimitri_</dc:creator>
      <dc:date>2018-10-18T16:13:23Z</dc:date>
    </item>
    <item>
      <title>Re: oData multilevel entity with self reference?</title>
      <link>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaa-p/702622#M190882</link>
      <description>&lt;P&gt;You have to explicitly specify how many levels you want to expand, e.g.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET PRODAREASet?$expand=PRODAREAS,PRODAREAS/PRODAREAS,PRODAREAS/PRODAREAS/PRODAREAS&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to expand three levels deep.&lt;/P&gt;&lt;P&gt;OData V4 adds a shortcut&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET PRODAREASet?$expand=PRODAREAS($levels=3)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and even allows&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;GET PRODAREASet?$expand=PRODAREAS($levels=max)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;to request the maximum number of levels supported by the service (which is allowed to defend itself against DOS attacks by interpreting "max" appropriately &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Oct 2018 16:21:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaa-p/702622#M190882</guid>
      <dc:creator>RalfHandl</dc:creator>
      <dc:date>2018-10-18T16:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: oData multilevel entity with self reference?</title>
      <link>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaa-p/702623#M190883</link>
      <description>&lt;P&gt;Thanks a lot for the clarification, sadly i have a v2 oData. &lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 10:28:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/odata-multilevel-entity-with-self-reference/qaa-p/702623#M190883</guid>
      <dc:creator>_Dimitri_</dc:creator>
      <dc:date>2018-10-19T10:28:11Z</dc:date>
    </item>
  </channel>
</rss>

