Search code examples
data-structuresodatasapui5abapsap-gateway

ABAP oDATA Service: How to provide nested data in one call?


I want to write a custom Fiori, using an oData Service to call the data out of my SAP system.

Using the SEGW transaction, I already set up a service to return a flat structure based on the VBAK table. Using that knowledge, I could develop an EntitySet for each object type and call them if needed. However, I would to reduce my database calls to just one statement. All relevant data should be provided at once.

Now, I ask myself: How to provide nested data in one call? Lets say, for each entry in VBAK, I would like to have a nested array of related VBAP entries.

My questions are:

  • How to define the described data model in DDIC?
  • How to setup the described data model in SEGW?
  • How to reimplement the method in my service implemetation class?

If I had coded the structure in ABAP, it might look like that:

TYPES: BEGIN OF vbakvbap,
  vbap TYPE vbap OCCURS 0.
  INCLUDE TYPE vbak.
TYPES: END OF vbakvbap.

DATA: lt_vbakvbap TYPE TABLE OF vbakvbap.

I have only a brief knowledge of ABAP and even less of SEGW, so every hint is welcome.


Solution

  • The SAP NetWeaver Gateway acts as the interface between the Odata request and the underlying data (obviously). Conceptually reducing DB requests make sense, but you would need to optimize the "Data Provider Class"(DPC) that gets created with your Gateway project. While you can improve ABAP (and associated DB performance) - the request in the DPC will be constrained by the overall Odata design paradigms.

    In a SAP NW Gateway project it is not possible to define a complex type as an entity set itself - see help file You should rather look to see if some SAP DDIC views exist that could meet your need (see WB2_V_VBAK_VBAP2 as an example) and model your entity sets logically around those i.e. flatten out your data requirements.

    How to set up data model Note that your data model in SEGW is a logical model, it does not have to physically exist on the DB, the DPC class is the ABAP which does the heavy lifting to populate the entity sets.

    How to re-implement the method Technically you redefine the methods of the DPC class, this can be accessed directly from the SEGW project, by expanding the runtime artifacts folder and extending the *_DPC_EXT class (right click and say go to Workbench). You would need to have some reasonable ABAP knowledge as well as implement any of the Odata filtering that may be requested.

    Other Comments To minimize DB access you may also want to consider implementing some caching in your DPC class, but it would depend on frequency of your calls.