How to prevent SAP oData framework to run into an infinite loop when using get_expanded_entityset

Viewed 278

In my project we recently implemented a method to retrieve a complex table for an odata service. In short, the service consists of 7 entities, let's call them M (master or uppermost parent), C1 and C2 (children of M, first level of two) and D1 - D5, which are children of C2 (second level).

The nested itab is already working as intended, consisting of the complex structure of all the entities and their relations.

However, only calling the Service with an URL that causes the framework to just retrieve the Main data and first level nested data works correctly. Trying to retrieve second level data as well results in an infinite loop where the framework is trying to loop over nested entities.

The oData URI looks like this:

/sap/opu/odata/sap/zsrv_data_srv/MSet?$expand=MToC1List,MToC2List/C2ToD1List,MToC2List/C2ToD2List,...,MToC2List/C2ToD5List

We also did implement the expanded_tech_clause itab for each navigation property of the entity model, which to my knowledge is supposed to mark entities as "already done", preventing the method from being called again for that entity.

what could be the issue here?

1 Answers

I have managed to solve this shortly after asking the question actually and the solution was quite simple.

The table et_expanded_tech_clauses needs to be filled with path strings. For the above example this needs to look like:

M/C1 M/C2 M/C2/D1 M/C2/D2 ... M/C2/D5

I have created constants for those strings. The framework now only calls the expanded_entityset method once and the odata call only takes about 15% of the previous runtime in our case.

Related