You can use metadata definition code patterns on the OData Channel to save time and effort when you define data models using a code-based approach by implementing the DEFINE method in the model provider class. To implement the code patterns in the design time in ABAP Workbench in transaction SE80, you must install the component IW_BEP on your system.
You can choose from two metadata definition code patterns:
Define Entity Type
Define Complex Type
Define Association
Define Composition
To implement the types of metadata definition code patterns, proceed as follows:
Start ABAP Workbench in transaction SE80.
Display the program, for example, ZHS_TEST in the tree view and choose Edit to switch to editing mode. 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 the RFC to be called.
Choose the Pattern push button. The Ins. statement dialog box displays.
Select the Other Pattern radio button and enter the technical name of the OData Channel pattern in the corresponding input field /IWBEP/FM_MGW_PATN or use the Input help available for this field to select the technical name.
Choose Continue.
The ODC Code Pattern Selection Screen Dialog box displays.
Make appropriate selection and continue to do the following.
Define Entity Type
Define Complex Type
Define Association
Define Composition
To configure the Define Entity Type code pattern, proceed as follows:
Follow the steps provided in the Generic Steps section.
Select Define Entity Type in the ODC Code Pattern Selection Screen.
Choose Continue.
The Local Entity Type Pattern screen displays.
Enter in the ABAP Structure field an ABAP data structure from the ABAP Dictionary or from a global class or global interface, for example, SFLIGHT. Input help is available for this field. Choose Continue.
The name of the ABAP structure is displayed in the Object Name field.
Select the appropriate usage type for each field in the Usage column by selecting a usage type from the drop-down list. Possible usages are:
Key: you must define this usage for at least one field.
Property
Ignore: if you define this usage for a structure, all subordinate structures are similarly set to Ignore automatically.
If your ABAP structure includes substructures, the code pattern proposes complex types for generation. If you do not want the code pattern to generate new statements for existing complex types, select the Exists checkbox.
You can change the names displayed in the EDM Property Name and Complex Type Name columns, but ensure the names are unique.
Choose the Check button to check the validity of the table entries. If there are errors in the table, double-click the relevant error message to navigate to the line in the table you need to correct.
Choose Continue to generate the source code.
The source code is inserted automatically into your DEFINE method.
To configure the Define Complex Type code pattern, proceed as explained above for configuring the Define Entity Type code pattern.
You can use the Define Complex Type code pattern similarly to the Define Entity Type code pattern, but be aware of the following differences:
You cannot define fields with usage type Key.
The generated source code defines a complex type for top-level fields in the ABAP structure.
The Define Complex Type code pattern supports ABAP Dictionary types in addition to global class and interface types adhering to the ABAP syntax.
An Association is a named relationship between two or more Entities. Association defines a peer-to-peer relationship between participating Entity Types and can support different multiplicities at both the ends. An example of an association is the relationship between the Customer and Order entities.
To define Association proceed as follows:
Follow the steps in the Generic Steps section.
Choose the Define Association radio button in the ODC Code Pattern Selection Screen and click Continue.
The Define Association window displays.
Do the following in the Define Association window.
Region |
Fields |
Description |
---|---|---|
Principal |
Entity |
Enter the name of the Principal Entity for which the association has to be created (Mandatory field) |
Property |
Enter the Navigation Property of the Principal Entity (Optional field, but becomes mandatory when the Dependent Property is specified). The Navigation Properties are special properties on Entity Types which are bound to a specific association and can be used to refer to associations of an entity |
|
Cardinality |
Select a cardinality for the Principal Entity from the drop-down list (Mandatory field) |
|
Dependent |
Entity |
Enter the name of the Dependent Entity for which the association has to be created (Mandatory field) |
Property |
Enter the Navigation Property of the Dependent Entity (Optional field, but becomes mandatory when the Principal Property is specified) |
|
Cardinality |
Select a cardinality of the Dependent Entity from the drop-down list (Mandatory field) |
The code is now generated in the ABAP editor:
To create Referential Constraint, both the Principle and Dependent property fields are mandatory.
See Defining Association for reference.
Composition is a way by which multiple relevant models/services can be associated with each other to reuse their functionality.
To define Composition proceed as follows:
Follow the steps in the Generic Steps section.
Choose the Define Composition radio button in the ODC Code Pattern Selection Screen and click Continue.
The Define Composition window displays.
Do the following in the Define Composition window:
Region |
Fields |
Description |
---|---|---|
Principal |
Service Identifier |
Enter the service group name of the Principal Entity |
Model Identifier |
Enter the Model name of the Principal Entity |
|
Entity |
Enter the name of the Principal Entity for which the association has to be created |
|
Cardinality |
Select a cardinality for the Principal Entity from the drop-down list |
|
Dependent |
Service Identifier |
Enter the service group name of the Dependent Entity |
Model Identifier |
Enter the Model name of the Dependent Entity |
|
Entity |
Enter the name of the Dependent Entity for which the association has to be created |
|
Cardinality |
Select a cardinality of the Dependent Entity from the drop-down list |
To create Composition, all the fields are mandatory.
The code is now generated in the ABAP editor:
The F4 help values for the services and the models will be available only if the services are registered in the SAP system. To compose a model from an external system, the F4 help values are not available, rather, you can manually type in the details except for Define Referential Constraint.
Also see Defining Composition
For more information about metadata definition code patterns, see Metadata Definition Code Patterns.