Brief Summary
This video explains the concepts of association and navigation in OData services, focusing on how to design them for business scenarios. It covers creating entity sets, establishing associations between them, and using navigation paths to access related data through a single URI. The video also discusses the methods called based on the URI parameters and key fields provided.
- Association and navigation in OData services.
- Creating entity sets and associations.
- Using navigation paths to access related data.
- Understanding method calls based on URI parameters.
Introduction
The video introduces the concept of association and navigation in OData services. It builds upon previous videos that covered creating OData services with entity sets and relevant Data Provider Context (DPC) methods. The goal is to demonstrate how to design OData services to reflect business data relationships, such as header and item dependencies, using association and navigation instead of separate entity sets.
Existing Design vs. New Design
The current design involves two independent entity sets for header and item data, requiring separate URIs to access each. The proposed design aims to create an association between these entity sets, allowing access to both header and item data through a single URI. This approach uses the concept of deep entity sets and involves mapping fields between the entity sets, such as the purchase order number.
Technical Terms: Association and Navigation Path
Association enables the mapping between two entity sets. Navigation path is the way of communication between the header and item entity sets, used at the UI level. URI (Universal Resource Identifier) is the terminology used in SAP Gateway.
Entity and Entity Set Methods
When creating an OData service, default methods like Create Entity, Update Entity, Delete Entity, Get Entity, and Get Entity Set are generated in the DPC extension class. The video focuses on Get Entity and Get Entity Set methods. Get Entity returns a single record (like a work area), while Get Entity Set returns multiple records (like an internal table). The system decides which method to call based on the URI parameters.
How System Decides Which Method to Call
The system determines whether to call the Get Entity or Get Entity Set method based on the URI parameters. If the URI includes key field values, the system calls Get Entity, assuming it will return only one record. If the URI does not include key field values, the system calls Get Entity Set, expecting multiple records.
Navigation Path in URI
With association enabled, a single URI can be used to access both header and item data. The navigation path is used to specify which related entity set to access. For example, adding the navigation path to the header entity set URI will call the item entity set method. This allows one URI to serve different purposes based on the parameters provided.
System Demo: Creating OData Service
The video demonstrates creating a new OData service using transaction SEGW. It involves importing DDIC structures for purchase order header and item details to create entity types and entity sets. The entity sets created are PO Header and PO Item.
Creating Association
The video explains how to create an association between the header and item entity sets. The principal entity is set to header with a cardinality of one, and the dependent entity is set to item with a cardinality of zero to many. A navigation property is created to define the relationship between the entities, using the purchase order number as the basis for the association.
Activating and Generating the Service
After creating the entity sets and association, the service is activated and generated. This process creates the DPC and MPC classes. The metadata is then examined to ensure the navigation property is included, showing the association between the header and item entity sets.
Redefining DPC Methods
The video demonstrates redefining the DPC methods (Get Entity and Get Entity Set) for both header and item entity sets. This involves going to the runtime and extending the DPC class to redefine these methods. Breakpoints are set to observe the behavior of the service.
Testing the Service and Breakpoints
The video shows how the system calls different methods based on the URI parameters. When the URI includes the key field (PO number), the Get Entity method is called. When the URI does not include the key field, the Get Entity Set method is called. This behavior is demonstrated with both header and item entity sets.
Coding the Get Entity Method
The video demonstrates coding the Get Entity method for the header entity set. The code retrieves the key field values from the URI and uses a function module to fetch the header details. The retrieved data is then populated into the entity.
Coding the Get Entity Set Method
The video explains the coding of the Get Entity Set method for the item entity set. The code retrieves item details based on the key fields passed in the URI. The retrieved data is populated into an internal table, which is then returned as the entity set.
Testing with Navigation Path
The video demonstrates how to use a single URI with the navigation path to access related data. By appending the navigation property name to the header entity set URI, the system calls the Get Entity Set method for the item entity set, retrieving the item details associated with the header.

