Show TOC

Using Metadata Definition Code PatternsLocate this document in the navigation structure

Use

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

Generic Steps
Procedure

To implement the types of metadata definition code patterns, proceed as follows:

  1. Start ABAP Workbench in transaction SE80.

  2. 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.

  3. Place your cursor at the position in the source code where you want the RFC to be called.

  4. Choose the Pattern push button. The Ins. statement dialog box displays.

  5. 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.

  6. Choose Continue.

    The ODC Code Pattern Selection Screen Dialog box displays.

  7. Make appropriate selection and continue to do the following.

    • Define Entity Type

    • Define Complex Type

    • Define Association

    • Define Composition

Define Entity Type
Procedure

To configure the Define Entity Type code pattern, proceed as follows:

  1. Follow the steps provided in the Generic Steps section.

  2. Select Define Entity Type in the ODC Code Pattern Selection Screen.

  3. Choose Continue.

    The Local Entity Type Pattern screen displays.

  4. 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.

  5. The name of the ABAP structure is displayed in the Object Name field.

  6. 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.

  7. 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.

  8. You can change the names displayed in the EDM Property Name and Complex Type Name columns, but ensure the names are unique.

  9. 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.

  10. Choose Continue to generate the source code.

Result

The source code is inserted automatically into your DEFINE method.

Define Complex Type
Procedure

To configure the Define Complex Type code pattern, proceed as explained above for configuring the Define Entity Type code pattern.

Note

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.

Defining Association

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.

Procedure

To define Association proceed as follows:

  1. Follow the steps in the Generic Steps section.

  2. Choose the Define Association radio button in the ODC Code Pattern Selection Screen and click Continue.

    The Define Association window displays.

  3. 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:

    Note

    To create Referential Constraint, both the Principle and Dependent property fields are mandatory.

More Information

See Defining Association for reference.

Define Composition

Composition is a way by which multiple relevant models/services can be associated with each other to reuse their functionality.

Procedure

To define Composition proceed as follows:

  1. Follow the steps in the Generic Steps section.

  2. Choose the Define Composition radio button in the ODC Code Pattern Selection Screen and click Continue.

    The Define Composition window displays.

  3. 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

    Note

    To create Composition, all the fields are mandatory.



    Figure 1: Sample Entries

    The code is now generated in the ABAP editor:



    Figure 2: Generated Code for Composition
    Note

    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.

More Information
More Information

For more information about metadata definition code patterns, see Metadata Definition Code Patterns.