Brief Summary
This video explains deep entity sets in OData services, which are essentially structures within structures, like nested internal tables. It addresses the need to consolidate related business data into a single URI for UI applications, rather than using multiple URIs for different entity sets. The video outlines the steps to create a deep entity set, including creating associations and navigation properties, defining entity types and sets, and using the MPC extension class to define a new internal table structure. It also covers how to fill the data using the "get expanded entity set" method in the DPC class and how to trigger this method using the $expand parameter in the URI.
- Deep entity sets consolidate related data into a single URI.
- MPC extension class is used to define new internal table structures.
- The "get expanded entity set" method fills the data.
- The $expand parameter triggers the "get expanded entity set" method.
Introduction
The video introduces the concept of deep entity sets in OData services, explaining that they are similar to deep structures or nested internal tables. The presenter notes that those familiar with web development may already be acquainted with this concept. The discussion aims to explain how to design OData services to meet business requirements, particularly the need to retrieve interrelated data using a single URI.
Business Requirement of OData
The video addresses the business requirement of OData services to consolidate related data into a single URI. Traditionally, each entity set (e.g., sales header, item, shipment) requires a separate URI, leading to multiple calls from the UI application. The video highlights that in real-world scenarios, these entities are interrelated, and it is more efficient for the UI application to request all related information with one URI. This approach is especially beneficial when dealing with a large number of entity sets, as it reduces the complexity and number of requests.
Steps to Create Deep Entity Set
The video outlines the steps to create a deep entity set in OData:
- Create Associations and Navigation Properties: Establish relationships between entity types (e.g., header and item, header and shipment) using associations and define navigation properties.
- Create Entity Types and Sets: Define entity types for header, item, and shipment, along with their corresponding entity sets.
- Create a Deep Entity Set: Design a new internal table structure that includes header information and nested internal tables for item and shipment details. This structure is created in the MPC extension class.
- Fill the Data: Use the "get expanded entity set" method in the DPC class to fill the deep entity set with data from the database tables.
- Trigger the Method: Use the
$expandparameter in the URI to trigger the "get expanded entity set" method. - Convert Data: Convert the data from the new entity set to the
er_entitysetinternal table, which is readable by the UI application.
MPC Extension Class
The video explains the use of the MPC (Model Provider Class) extension class in creating a deep entity set. Unlike the DPC (Data Provider Class), which handles data retrieval and manipulation, the MPC class is used to define the structure of the data model. In this context, the MPC extension class is used to create a new internal table structure that includes header information and nested internal tables for item and shipment details. This allows the OData service to return a consolidated set of data in a single response.
Filling the Data: Get Expanded Entity Set
The video describes how to fill the deep entity set with data using the "get expanded entity set" method in the DPC class. This method is redefined to include the logic for retrieving data from the database tables (header, item, shipment) and populating the new internal table structure. The method uses a case statement to identify the entity set name and execute the appropriate data retrieval logic. The data is then transferred from the individual internal tables to the deep entity set, and finally, to the er_entityset internal table for the UI application to consume.
Triggering Get Expanded Entity Set
The video explains how to trigger the "get expanded entity set" method using the $expand parameter in the URI. The $expand parameter is appended to the entity set name in the URI, followed by the navigation property name. For example: /SalesHeaderSet?$expand=HeaderToItemNav,HeaderToShipNav. This parameter tells the OData service to include the related entities in the response. If the $expand parameter is not used, the service will call the default "get entity set" method, which will not return the consolidated data.
Custom Tables and Part Two Preview
The video mentions the use of custom tables for the demonstration and provides a preview of the next video in the series. The presenter explains that custom tables are used because of issues encountered when creating sales orders or purchase orders using standard SAP functionalities. The next video, "Deep Entity Set Part Two," will focus on creating entries in these custom tables using deep entity sets, allowing UI applications to update the backend system with consolidated data.
Creating Entity Sets and Types
The presenter demonstrates the creation of three entity sets: sales header, sales item, and shipment, within the SAP system. This involves navigating through transaction SEGW to define the entity types and their corresponding properties. The properties, such as sales ID, order type, item number, material, shipment number, and plant, are created to match the fields in the custom tables. The presenter emphasizes the importance of creating these entity sets and types as a foundation for building the OData service.
Association Creation
The presenter walks through the process of creating associations between the entity types. Two associations are created: one between the header and item, and another between the header and shipment. The presenter specifies the cardinality (1 to many) and defines the navigation properties for each association. The navigation properties, such as "HdrToItemNav" and "HdrToShip," are crucial for calling the "get expanded entity set" method later on.
Generating Project and MPC Class
The presenter generates the OData service project, which automatically creates the DPC and MPC classes. The MPC class is then explored to show the automatically generated structure and table types for the entity sets. The presenter explains that the MPC class will be enhanced to create a new deep entity set structure that includes the header information along with the item and shipment details as table types.
Deep Entity Structure Creation
The presenter modifies the MPC class to create a new deep entity structure. This involves adding a new structure definition that includes the header information and internal tables for item and shipment details. The presenter emphasizes the importance of using the same names for the internal tables as the navigation properties defined in the associations. This ensures that the data is correctly populated during the execution of the OData service.
DPC Class and Redefining Methods
The presenter transitions to the DPC extension class and redefines the "get expanded entity set" method. Before redefining this method, the presenter suggests redefining the basic entity set methods (header, item, shipment) as a precautionary measure to avoid potential errors during testing. The "get expanded entity set" method is then redefined to include the logic for retrieving data from the database tables and populating the deep entity set.
Code Implementation in Get Expanded Entity Set
The presenter implements the code within the "get expanded entity set" method to retrieve and populate the deep entity set. This involves declaring internal tables and work areas to hold the data from the database tables. A case statement is used to identify the entity set name and execute the appropriate data retrieval logic. The data is then transferred from the individual internal tables to the deep entity set, and finally, to the er_entityset internal table for the UI application to consume.
Service Activation and Testing
The presenter activates the OData service and tests it using the SAP Gateway Client. The presenter retrieves the metadata to understand the structure of the service and then executes the service with the $expand parameter to trigger the "get expanded entity set" method. The presenter demonstrates how to include multiple navigation properties in the $expand parameter to retrieve related entities in a single response.
JSON Format and Conclusion
The presenter demonstrates how to retrieve the data in JSON format by adding the $format=json parameter to the URI. The presenter concludes the video by summarizing the steps to create a deep entity set and providing a preview of the next video, which will focus on creating entries in the custom tables using deep entity sets.

