Composition is a way by which multiple relevant models/services can be associated with each other in order to reuse their functionality.
To create a Sales Order we require a list of customers and products. So for Sales Order service two types of master data is required:
Customer
Product
Here is where Composition is used. The services, Customer and Product already exists and can be reused by means of composition.
Incase of combination with external models, the external model must exist and be live on the SAP Gateway system. During Composition, It is also possible to define associations to the entities of the combined model. 1:1 and 1:n cardinality can be defined pointing from the new model to the combined external model. It is necessary to define Referential Constraints for these associations as they are resolved generically during runtime by the framework on the SAP Gateway system.
Method INCLUDE_MODEL_BY_SERVICE_ID, Includes a model from another OData Channel Service exposed on the SAP Gateway.
To Compose services and models proceed as follows:
Start ABAP Workbench in transaction SE80.
Navigate to your model provider class and open the DEFINE method
in which you want to insert the source code generated by the code pattern.
Choose the Edit button. After you have switched to editing mode, the Pattern push-button in the application tool bar is active.
Place your cursor at the position in the source code where you want to insert the generated code pattern for composition.
Choose the Pattern push button. The Ins. statement dialog box is displayed.
Select the Other Pattern radio button and enter the technical name of the OData Channel pattern in the corresponding input field /IWBEP/FM_MGW_PAT. Input help is available for this field.
Choose
In the ODC Code Pattern Selection Screen dialog box , select the Define Composition radio button under Metadata Definition.
Choose to open the Define Composition window.
Do the following in the Define Composition window:
Fields |
Description |
|
---|---|---|
Association Name |
Enter a name for the Association |
|
Principle Entity |
Navigation Property and Referential Constraint should have a From Role and To Role defined. The From Role refers to the Principal entity. |
|
Service Identifier |
Enter string value that is used to uniquely identify a service of the Principle Entity. |
|
Model Identifier |
Enter string value that is used to uniquely identify a model of the Principle Entity. |
|
Entity |
Enter the name of the Principal Entity for which the association has to be created (Mandatory field) |
|
Cardinality |
Select a cardinality for the Principal Entity from the drop-down list (Mandatory field). Cardinality is the measure of the number of Entity instances occurring in a relationship. Example
An example of an association is the relationship between the Customer and Order entities. Typically, this relationship has the following characteristics: Multiplicity: each Order is associated with exactly one Customer. Every Customer has zero or more Orders. |
|
Dependent Entity |
Navigation Property and Referential Constraint should have a From Role and To Role defined. The To Role refers to the Dependent entity. |
|
Service Identifier |
Enter string value that is used to uniquely identify a service of the Dependent Entity. |
|
Model Identifier |
Enter string value that is used to uniquely identify a model of the Dependent Entity. |
|
Entity |
Enter the name of the Dependent Entity for which the association has to be created (Mandatory field) |
|
Cardinality |
Select a cardinality of the Dependent Entity from the drop-down list (Mandatory field) |
The F4 values for the services and the models will be available only if the service has been registered in the SAP system. To compose a model from an external system, you have to manually type in the details (no F4 value help).
To create Referential Constraint, both the Principle and Dependent Property fields are mandatory.
Click to generate the code.
The code will now be generated in the ABAP editor.
Refer Defining Complex Type, Defining Association and Defining Entity Type for more options in Metadata Definition Code Patterns.