cancel
Showing results for 
Search instead for 
Did you mean: 

CDS Custom Entity not working with Multilevel Expand

catalinfeidi
Participant

Hi there,

We have been experimenting CDS Custom Entity in order to keep the legacy code clean but we do have a corner case to load full BO which custom entity is not supporting.

We need to retrieve parent entity -> children entity -> grandchildren entity, all together as follows:

Parent(entity: parent)

-Child1(entity:_children)

--GrandChild1forChild1(entity: _grandchildren)

--GrandChild2forChild2(entity: _grandchildren)

Child2(entity:_children)

--GrandChild1forChild2(entity: _grandchildren)

--GrandChild2forChild2(entity: _grandchildren)

Our OData call:

/parent?$filter=((key1 eq 'something1')and(key2 eq 'something2'))&$expand=_child($expand=_grandchildren)

When we want to get the navigation keys inside of _grandchildren query implementation class as doing get_filter()->get_as_ranges(), it is short-dumping when method is being called, because there are 2 children for the Parent(Child1 and Child2). It doesn't work with multiple parents for that respective entity.


This seems to be a limitation of Custom Entity, not supporting the expand of associations on entities that have more entries.

Accepted Solutions (0)

Answers (2)

Answers (2)

dominik_ee
Advisor
Advisor
Andre_Fischer
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Catalin,

as Dominik wrote the root cause is that the filter statement cannot be translated into a ranges table.

As a result an exception is thrown when calling the get_as_ranges( ) method.

And if this is not catched you get a dump because raising exceptions is not allowed within the RAP framework.

If you surround the call of the method get_as_ranges() with a TRY CATCH block you will probably see an exception of type CX_RAP_QUERY_FILTER_NO_RANGE.

Or if you catch it into cx_root the exception message should be something like that the filter condition could not be translated to a ranges table.

CATCH cx_root INTO DATA(exception).   

DATA(exception_message) = cl_message_helper=>get_latest_t100_exception( exception )->if_message~get_longtext( ).

I have built a sample with three entities as well and got the following filter string on grandchild level (root has one key field "SALESORDERID", child has two key fields "SALESORDERID" and "ITEMPOSITION")

( SALESORDERID = ' 2' AND ITEMPOSITION = ' 2' OR SALESORDERID = ' 2' AND ITEMPOSITION = ' 1' )

So you can try to retrieve the filter as string or in newer releases as filter tree.

DATA(filter_string) =   io_request->get_filter( )->get_as_sql_string(  ).  

DATA(filter_tree) =   io_request->get_filter( )->get_as_tree(  ).

Hope this helps.

Kind regards,

Andre