2-SAP NetWeaver Gateway Service Builder
December 8, 2016 | Author: kokocodename47 | Category: N/A
Short Description
2-SAP NetWeaver Gateway Service Builder...
Description
SAP NetWeaver Gateway Service Builder PDF download from SAP Help Portal: http://help.sap.com/saphelp_nw74/helpdata/en/cd/dd22512c312314e10000000a44176d/content.htm Created on April 16, 2014
The documentation may have changed since you downloaded the PDF. You can always find the latest information on SAP Help Portal.
Note This PDF document contains the selected topic and its subtopics (max. 150) in the selected structure. Subtopics from other structures are not included.
© 2014 SAP AG or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Please see www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.
Table of content
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 1 of 65
Table of content 1 SAP NetWeaver Gateway Service Builder 1.1 Development Approaches 1.2 User Interface 1.2.1 Working with the Mass Maintenance View 1.3 Creating a Service Builder Project 1.3.1 Copying a Service Builder Project 1.3.2 Generating Runtime Artifacts for Copied Projects 1.4 Data Modeling Basics 1.4.1 Defining a Data Model 1.4.2 Copying Data Model Artifacts 1.4.3 Entity Types 1.4.3.1 Defining Properties 1.4.3.1.1 Mappings and the ABAP Type Editor 1.4.3.2 Navigation Properties 1.4.4 Complex Types 1.4.5 Associations 1.4.5.1 Referential Constraints 1.4.6 Entity Sets 1.4.7 Association Sets 1.4.8 Function Imports 1.4.8.1 Function Import Parameters 1.4.9 Working with Annotations 1.4.9.1 Uploading Vocabularies into the Vocabulary Repository 1.4.9.2 Importing a Vocabulary File 1.4.9.3 Adding Vocabulary-Based Annotations to Data Model Artifacts 1.5 Data Modeling Options 1.5.1 Importing a Data Model 1.5.2 Importing a DDIC Structure 1.5.3 Importing a Data Source (RFC/BOR Interface) 1.5.4 Importing Search Help as a Data Source 1.5.5 Including an OData Service 1.6 Redefining Services 1.6.1 Extending an OData Service Using Service Builder 1.6.2 Redefining OData Service (GW) 1.6.3 Redefining Services from External Framework (SPI, BW Query, GenIL) 1.7 Service Implementation 1.7.1 Redefining Methods of the Operations 1.7.2 Mapping to a Data Source 1.7.2.1 Creating the Mapping 1.7.2.1.1 Mapping UI 1.7.2.1.1.1 Mapping Table 1.7.2.1.1.2 Data Source View 1.7.2.1.1.3 Deleting the Mapping 1.7.2.1.1.4 Mapping Rules 1.7.2.2 Setting Constant Values 1.7.2.3 Mapping the Query Operation 1.7.2.3.1 Ranges Table and Structures 1.7.2.4 Mapping the Read Operation 1.7.2.5 Mapping the Create Operation 1.7.2.6 Mapping Delete or Update Operations 1.7.3 Implementation Support for Association 1.8 Runtime Artifacts 1.8.1 Generating Runtime Objects 1.8.1.1 Creating the ABAP Classes and Registering the Service 1.8.1.2 BOP Interface Naming Rules 1.8.1.3 Generated ABAP Classes and Service Registration 1.8.1.3.1 Generated Classes for Model Provider Class 1.8.1.3.1.1 Base Class: Model Provider Class 1.8.1.3.1.2 Implementation Class: Model Provider Class 1.8.1.3.2 Generated Classes for the Data Provider Classes
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 2 of 65
1.8.1.3.2.1 Base Class: Data Provider Class 1.8.1.3.2.2 Implementation Class: Data Provider Class 1.9 Service Maintenance
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 3 of 65
1 SAP NetWeaver Gateway Service Builder Use SAP NetWeaver Gateway Service Builder (transaction SEGW) is a design-time environment, which provides developers with an easy-to-use set of tools for creating services. It has been conceived for the code-based OData Channel and supports developers throughout the entire development life cycle of a service.
Prerequisites If you system is based on SAP NetWeaver 7.40 or higher, the core component SAP_GWFND is installed as standard. For more information about deployment options and scenarios, see SAP NetWeaver Gateway Master Guide.
Features In one single transaction, SAP NetWeaver Gateway Service Builder caters for the needs of both experienced and less experienced developers who want to expose data for easy consumption using a variety of platforms, frameworks, and devices. While experienced developers have maximum flexibility to define a new service from scratch and integrate their own source code, less experienced developers can reduce the time and effort involved in creating services by importing existing definition files and implementing content generators. In short, the Service Builder provides an OData-compliant modeling environment for the creation and maintenance of OData services without the need for programming. The Service Builder visualizes all development artifacts developers need to create a service including: SAP NetWeaver Gateway runtime artifacts such as model provider class (MPC), data provider class (DPC), model, and service OData artifacts such as entity set, entity type, and properties
Project-Based Service Development The Service Builder introduces a new service development concept, which is organized around projects. Projects are used to store all the artifacts developers need to create a service and model together in one place. Since projects consolidate all related data, developers can easily work on multiple projects in parallel and reuse data between projects before generating and activating the actual service. Consequently, projects provide developers with the freedom to interrupt the service development and modeling process at any time, without being bound to runtime artifacts and without risk of losing data. Organizing the service development and modeling process in projects has the advantage that all project data can be transported easily between one system and another for maximum efficiency and reuse.
1.1 Development Approaches Use SAP NetWeaver Gateway Service Builder supports different development approaches and life cycles to provide developers with maximum flexibility so they can fulfill changing development prerequisites and meet diverse requirements. When developers need a service to expose specific data, they can decide whether to define a completely new data model for the new service and integrate their own source code, or reuse and redefine existing services. If a project exists that could be applied to a similar use case, you can create a copy of an entire project and then make the minimal change required. The Service Builder provides numerous ways of reusing existing data sources from an SAP Business Suite system, thereby accelerating the development process significantly. In short, the Service Builder caters for all levels of development experience and provides development approaches tailored to saving time and increasing efficiency without compromising on quality. Whichever development approach is taken, the appropriate set of ABAP classes is generated. This ensures that developers retain maximum flexibility when optimizing or extending OData services in Gateway. The Service Builder supports the following development phases for OData services: 1. Data Model Definition (Model Provider Class (MPC)) 2. Service Implementation (Data Provider Class (DPC)) 3. Service Maintenance
Overview
Overview of Development Approaches for the
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 4 of 65
Service Builder (transaction SEGW)
Data Model Definition OData services require a data model definition (model provider class). In the case of client development projects, the development process invariably starts with a previously-defined data model (outside-in approach). Depending on your requirements, you can define a data model in the following ways: Define new data model: provides maximum flexibility and requires manual definition of individual data model elements and their properties. Subsequent development phases: Service Implementation, Service Maintenance. For more information, see Import: DDIC structure (ABAP Data Dictionary): reduces time required to create entity types and complex types in your data model. Subsequent development phases: Service Implementation, Service Maintenance. For more information, see Importing a DDIC Structure. Data source (RFC/BOR interface): enables you to reuse existing RFC/BOR parameters to create entity types with ease. In this way, you can tap into a multitude of existing Remote Function Calls (RFCs) and Business Application Interfaces (BAPIs) from the Business Object Repository. After you have imported an existing interface definition, you can map the operations from the same RFC or BAPI to obtain the service operations you require without having to write additional ABAP source code. Subsequent development phases: Service Implementation, Service Maintenance. For more information, see Importing a Data Source (RFC/BOR Interface). Data model: allows you to reuse an existing data model. You can reuse a data model for more than one service. Subsequent development phases: Service Implementation, Service Maintenance. For more information, see Importing a Data Model. Redefine service: enables you to redefine existing SAP NetWeaver Gateway services or services created from a framework within your SAP system landscape. For example, Service Provider Interface (SPI), SAP Business Information Warehouse (BW Query), Generic Interaction Layer (GenIL). The Redefine service function enables you to reuse the diverse business objects and services that exist in your SAP system landscape. Furthermore, it connects existing service operations so you do not need to create an individual service implementation. Consequently, you can skip the service implementation phase. Subsequent development phase: Service Maintenance. For more information, see Redefining Services. Include service: enables you to include an existing SAP NetWeaver Gateway service so you do not need to recreate its data model. For greater reuse, it allows you to combine one or more existing services in a new service. If you choose to include one or more existing services, you do not need to perform the service implementation phase. Subsequent development phase: Service Maintenance. For more information, see Including an OData Service.
Service Implementation In the service implementation phase, you define the runtime artifacts (operations and methods) for the data provider class. You can define the runtime artifacts in the following ways: Code-based implementation: The Service Builder generates the required ABAP classes based on the data model you define. Subsequently you can navigate directly from the Service Builder to ABAP Workbench where you can access the appropriate methods and write the source code for the various different service operations. SAP provides some code patterns for data provision and metadata definition. Mapping operations to a data source: You define manual relations between the parameters of a data source object and the properties of an entity. You can map data sources of type Remote Function Call (RFC) and Business Object Repository (BOR). This function is designed for use in conjunction with the Import data source function (RFC/BOR interface) and enables you to map the RFC/BOR function to the service operations. Where possible, the Service Builder proposes an operation mapping for imported RFC/BOR interfaces. For more information, see Including an OData Service.
Service Maintenance The final development phase in the life cycle of an OData service is Service Maintenance and this must be carried out regardless of your chosen development approach. Service Maintenance entails registering and activating each service in an SAP NetWeaver Gateway system. For more information, see Service Maintenance.
1.2 User Interface Use SAP NetWeaver Gateway Service Builder simplifies and structures the service development and modeling process required for exposing and consuming data by using projects. Developers first create a project to develop, model, and store all the development artifacts they need to define a service. The focus on projectbased service development is consequently reflected in the Service Builder user interface.
Screen Areas The standard UI comprises the three following screen areas: Tree view to show open projects, their substructures, and the artifacts they contain. To edit data objects and their properties, double-click the relevant data object in the tree view. Mass maintenance view for creating, editing, and deleting data objects within a project. Data object types include, for example, entity types, complex types, associations, and function imports. To display details about a data object, select the relevant row in the mass maintenance view and choose Details . Message view, which displays all types of messages regarding the status of the project. You can hide the message view or delete individual messages. For more information about the mass maintenance view, see Working with the Mass Maintenance View.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 5 of 65
1.2.1 Working with the Mass Maintenance View Use SAP NetWeaver Gateway Service Builder provides an easy-to-use mass maintenance view, which allows you to create, edit, delete, and organize data objects and their properties in your Service Builder project. Regardless of the data object type you want to edit, the editing process is identical.
Overview Overview of functions available in the mass maintenance view: Icon
Description
Close View
Choose Close View to close mass maintenance view.
Full Screen On/Off
Choose Full Screen On/Off to toggle between a full screen view of the mass maintenance view and hide the project tree displayed in the left-hand screen area.
Display/Change
Choose Display/Change to toggle between the display and change modes for the data artifacts in the project..
Append Row
Choose Append Row to append a new row to the bottom of the table.
Insert Row
Select appropriate row in the mass maintenance view and choose Insert Row to insert a new row above the current cursor position.
Delete Row
Select appropriate row in the mass maintenance view and choose Delete Row to delete the row at the current cursor position.
Sort in Ascending/Descending Order
Choose Sort Ascending/Sort Descending Order to sort data objects in ascending or descending order.
Choose Layout
Choose, change, save, and manage templates.
Copy to Clipboard
Choose Copy to Clipboard to copy the selected rows from the table to the clipboard so you can subsequently paste these rows elsewhere.
Cut to Clipboard
Choose Cut to Clipboard to cut the selected rows from the table and copy them to the clipboard so you can subsequently paste these rows elsewhere.
Paste from Clipboard
Choose Paste from Clipboard to paste the rows you previously copied to the clipboard to a new location.
Invert Checkboxes
When selecting and deselecting checkbox values in the mass maintenance view, for example, to define properties, select the cells or whole columns for which you want to invert the current checkbox values and choose Invert . This enables you to change the checkbox values from selected or deselected for one or more cells, that is, invert the current values. Furthermore, choose Select or Deselect from the dropdown list to select or deselect all checkboxes in the selected columns.
Redefine Attributes
When redefining an existing service in your project that is referenced from another model, choose Redefine Attributes to change the existing attributes of the service.
Undo Redefinition
After you have redefined the attributes of an existing service in your project that is referenced from another model, choose Undo Redefinition to reset the attributes you have redefined to the original service attributes.
Undo Identical Redefinition
After you have redefined the attributes of an existing service in your project that is referenced from another model, choose Undo Identical Redefinition to retain the redefined attributes, while resetting the attributes you have not changed to the original service attributes.
Annotations
Displays vocabulary namespace if applicable for project. For example, Org.OData.Core.V1. If you want to work with vocabularies for annotations, you must create a project of type Service with Vocabulary-Based Annotations .
After you have made the relevant changes to the appropriate data objects in the mass maintenance view, choose Save to save the changes to your Service Builder project.
Related Information Copying Data Model Artifacts
1.3 Creating a Service Builder Project Use To develop a service using SAP NetWeaver Gateway Service Builder, you first need to create a project. The Service Builder uses projects to bundle all the artifacts you need to develop a service in one central place and thereby helps you to organize the service development and modeling process. You can use projects to organize the transport of objects from one system environment to another meaning that all artifacts remain together at all times. Choose from two project types in the Service Builder when you create a new prpoject:
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 6 of 65
Choose Service with SAP Annotations if you want to annoate your data model artifacts using standard SAP annotations. SAP annotations include Creatable, Updatable, Label, and UnitProperty , for example. The available attributes can differ according to the data model artifact you want to annotate. You can also define the facets, Nullable, Default, MaxLength, FixedLength, Precision, Scale , for example. The ABAP type information available includes ABAP field name and explicit ABAP type assignment. Choose Service with Vocabulary-Based Annotations if you want to annotate data model artifacts using additional terms that are not part of the core attributes and provide additional descriptive information about the artifact. In this case, additional terms can be consolidated in a vocabulary and uploaded into the Vocabulary Repository. The Vocabulary Repository includes a selection of vocabulary files for ODate vocabulary-based annotations, such as Org.OData.Atom.V1 and Org.OData.Capabilities.V1.
Procedure To create a Service Builder project, proceed as follows: 1. Click Project from the main menu, and choose Create , and then enter a name for the new project you want to create. The project name must be unique and may not contain any spaces or special characters, however, it may contain underscores. Input help is available so you can check which project names are already in use. Although you cannot reuse an existing project name, you can derive a new project name from an existing project name by adding a prefix or suffix, for example. 2. Enter a description for your new project. This is a mandatory entry and you are unable to create a new project without defining a description. The description is displayed in the Service Builder together with the project name. The short description can be used to provide additional context information about the project or service you define. The short description must not exceed 60 characters. 3. Under Attributes select the project type you want to create. The project type you select when creating a project cannot be changed at a later time. Select Service with SAP Annotations if the OData service in your project is to use standard SAP annotations. Select Service with Vocabulary-Based Annotations if the OData service in your project is to use vocabulary-based annotations. You can create and upload your own customer-specific vocabularies into the Vocabulary Repository. The uploading of vocabulary files is an optional preparatory step for implementation. 4. Under Attributes , specify the generation strategy that is to be used. The standard generation strategy is used as default, but other generation strategies are feasible. If no customer-specific generation strategies have been defined in the system, Standard is entered as default to indicate that the standard generation strategy will be used. For more information about generation strategies, see Generating Runtime Objects. 5. Under Object Directory Entry , enter the name of the package in which you want to create the new project and, implicitly, the service and choose Enter .
Note If you do not want the project to be created in a package to be transported from one system to another in the system landscape, enter $TMP as the package name or choose the Local Object pushbutton. This ensures that the object is created locally.
Result The Service Builder creates the new project together with an empty folder structure. You can see the newly-created project structure in the tree view in the lefthand screen area. The project structure comprises the following folders and subfolders: Data Model Entity Types Associations Entity Sets The following subfolders are automatically added to the tree only when you define new entity entries for them: Association Sets Complex Types Function Imports Vocabularies: Imports - Lists the vocabulary or vocabularies imported for your project. Implicit References - Lists the vocabulary or vocabularies referenced by the vocabulary file that was explicitly imported. Service Implementation Runtime Artifacts Service Maintenance To save the newly-created project in the Service Builder, choose Save . Your project is saved and you can subsequently return to the Service Builder at any time, open this project, and continue the service development and modeling process. If you do not save your newly-created project, your data will be lost as soon when you close the Service Builder.
Related Information Copying a Service Builder Project
1.3.1 Copying a Service Builder Project How to copy an existing Service Builder project for a similar use case to save time and effort.
Context To reduce development effort and save time, you can create a new Service Builder project by copying an existing project together with its data model and service implementation. Note that while you can copy the mapping information contained in a project's service implementation, you cannot copy the generated ABAP classes since these have to be generated explicitly for the project created as a copy.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 7 of 65
It can be particularly helpful to copy a project if a project has already been created for a similar use case and you can reuse its artifacts with only minimal changes being required. To copy an existing Service Builder project, proceed as follows:
Procedure 1. Ensure the project you want to copy is open in the tree view. To open a project, choose Open Project and enter the project's name directly or use the input help available. 2. In the tree view, right-click the name of the project you want to copy and choose Copy Project . Alternatively, choose Project Copy from the Service Builder menu. 3. In the Create Project dialog box, overwrite the name of the existing project with the name of the new project you want to create as a copy. Enter the new name in the Project field. If you want to create a new version of an existing project, you can simply append a version number, for example, 0001, to the original project name. In this way, it is apparent, that the new project is based on an earlier version of the project of the same root name. In some cases, it might be helpful to have several versions of the same project indicated by a numeric counter of this kind. 4. Overwrite the description of the existing project you want to copy with a suitable description for your new project. While it is not mandatory to enter a short description, it is helpful to do so. 5. In the Copy from Template Project section of the dialog box, ensure the name of the project you want to copy is displayed in the Project field and verify that this is the correct project. 6. If you want to copy the project together with its data model and service implementation, select the Data Model and/or Service Implementation checkboxes. In this context, copying the service implementation refers to the copying of the mapping information, not the actual runtime artifacts. Note that if you want to copy the service implementation, you must also copy the project's data model. However, you can copy the project's data model without having to copy the service implementation. 7. Under Attributes , the project type (either Service with SAP Annotations or Service with Vocabulary-Based Annotations ) of the project you are creating as a copy is displayed in the Project Type field. The type displayed here depends on the type of project specified when the original project was created. If the original template project was specified as type Service with SAP Annotations then the copied project will inherit this project type. 8. Under Attributes , specify the generation strategy you want to use. The Standard generation strategy is used as default and it makes sense to use the same generation strategy that was specified for the original project. 9. Under Object Directory Entry , enter the name of the package in which you want to create the copy of the project and choose Enter . If you do not want the copy of the project to be created in a package to be transported from one system to another in the system landscape, enter $TMP as the package name or choose the Local Object pushbutton.
Results The Service Builder creates a new project as a copy of the template project you selected. The new (copied) proiect is displayed in the tree view on the left-hand side of the screen. The newly created projects contains the same arfiacts as the tempate project you copied. Consequently, if you selected the Data Model and Service Implementation checkboxes in the Create Project dialog box, these are included in your new project. That is, if you copied the data model from the existing project, the new project contains the same entity types, properties, navigation properties, associations, and entity sets contained in the original data model. To save the new project in the Service Builder, choose Save . Your project is saved and you can subsequently return to the Service Builder at any time, open this project, and continue the service development and modeling process. If you do not save your project, your data will be lost when you close the Service Builder. After you have made all the relevant changes to the new project, choose Generate to create the runtime artifacts for this new project. After the runtime artifacts have been generated, you must register the new service in the relevant system using the Service Maintenance function.
Related Information Generating Runtime Artifacts for Copied Projects Creating a Service Builder Project Copying Data Model Artifacts Service Maintenance
1.3.2 Generating Runtime Artifacts for Copied Projects Explains how to generate runtime artifacts for projects that you created by copying an existing project in the Service Builder.
Context Since the Copy Project function does not enable you to copy a project's runtime artifacts, you need to generate the runtime artifacts as follows:
Procedure 1. Make all changes you require in the new project you created as a copy. 2. Save all changes. 3. Choose Generate to generate the new runtime artifacts for the new project. Provided that the template (original) project does not include manual coding, the Generate function will generate all the runtime artifacts as they exist in the original project and its service. If the original project does include manual coding, however, and provided that the service was created using the Standard generation strategy, follow the next steps outlined below. You only need to perform the next steps if your project includes manual coding. 4. Start ABAP Workbench (transaction SE80). 5. Copy all the custom coding from the runtime artifacts of the template project. 6. Paste all the custom coding to the runtime artifacts of the project you created as a copy. Provided that the project was created according to the SAP Standard generation strategy, follow the next steps outlined below. If you have used a custom-specific generation strategy, you would need to follow the custom-specific instructions for this instead.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 8 of 65
7. Copy the custom coding from the _EXT classes of the template project. 8. Paste the custom coding to the _EXT classes of the project created as a copy. 9. Verify corresponding _EXT classes for data provider class (DPC) and model provider class (MPC). Custom coding is located in methods newly defined in the _EXT classes and/or redefined methods from the super classes. DPC_EXT class: check the redefined CRUD method for each entity set (GET_ENTITYSET, GET_ENTITY, CREATE_ENTITY, UPDATE_ENTITY, DELETE_ENTITY and overwrite the same method in the corresponding template class and copy and paste the method's content. MPC_EXT class: check if the DEFINE method is redefined in the template project.
Next Steps After you have generated the runtime artifacts you require for your service, use the Service Maintenance function to register your service in the relevant systems.
1.4 Data Modeling Basics Use After you have created a project in SAP NetWeaver Gateway Service Builder, you can start the data modeling process. The data model defines, for example, the entity types, complex types, properties, and associations required for the service. After you have defined the artifacts contained in the data model, you can consider the operations you want to perform at runtime, and you map these operations to data objects and properties within your Service Builder project. At runtime, the data model is exposed to SAP NetWeaver Gateway services that trigger the operations you have defined at design time and return the relevant data and fields to the user. For example, you can create a data model that reads customers' names, addresses, and contact details stored in an SAP system and a sales manager can access this data from a mobile device while on the road without having to log onto the relevant SAP system directly.
Data Modeling Alternatives Depending on your level of experience and the time you want to dedicate to the data modeling process, you can: Define a new data model. For more information, see . Reuse existing data models or services to reduce the development effort. For more information, see Data Modeling Options. Create function imports to invoke custom operations. For more information, see Function Imports. Use generators to create classes with minimum effort. For more information, see Generating the Service To facilitate a superior user experience when working with the Service Builder, copy and paste functions are available. For more information, see Copying Data Model Artifacts and Copying a Service Builder Project.
1.4.1 Defining a Data Model In SAP NetWeaver Gateway Service Builder, you can define a new data model within your project to suit your exact service requirements based on the data you want to expose at runtime.
Context You can define a new data model by creating (and editing) individual data model elements and their properties. In the tree view of the Service Builder, you use the data model folder structure to create and edit the individual data model elements. The data model structure comprises the following subfolders for each of the element types: Entity Types Complex Types Associations Entity Sets Association Sets Function Imports You can create and define any of the data model elements listed above directly in the Data Model folder of your project. When you create a new data model element, it is located in the relevant predefined subfolder within the Data Model folder. You can ceratre new data model elements in one of the following ways:
Procedure 1. Double-click the specific data model element in the data model folder and make the relevant entries. 2. Right-click the Data Model folder, select Create and then select the data model element you want to create. 3. Expand the Data Model folder, right-click the data model element you want to create and choose Create .
Related Information Data Modeling Options
1.4.2 Copying Data Model Artifacts Explains the different options for working with copy and paste in the Service Builder to copy data model artifacts.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 9 of 65
Context To simplify and enhance usability within the Service Builder, you can copy and paste data model artifacts within a project or between different open projects in the Service Builder. You can copy artifacts from any projects in display or edit mode, but the project in which you want to paste the copied projects must be in edit mode. You can copy and paste the following data model artifacts: Entity types (including properties and navigation properties) Associations Entity sets Association sets Function imports Complex types Working with Copy and Paste Icons in the Mass Maintenance View The mass maintenance view includes the following functions to facilitate the copying and pasting of artifacts within or between open projects in the Service Builder. The project to which you want to paste copied artifacts must be in edit mode. Copy to Clipboard : Select the nodes you want to copy so that you can paste the artifacts elsewhere within this project or to a different project. An information message is displayed at the bottom of the screen to indicate how many nodes have been selected and copied to the clipboard. Cut to Clipboard : Select the nodes you want to cut from this location so that you can paste the artifacts elsewhere within this project or to a different project. You are prompted to confirm whether you really want to delete the nodes from the current location. An information message is displayed at the bottom of the screen to indicate how many nodes have been selected and cut to the clipboard. Paste from Clipboard : Select this icon to paste from the clipboard the artifacts previously copied from a different location within this project or from a different project to the new location. An information message is displayed at the bottom of the screen to indicate how many nodes have been selected and pasted from the clipboard. To use the copy and paste functions in the mass maintenance view, proceed as follows: 1. Open the project from or within which you want to copy data model artifacts. 2. Double-click the folder in the project that contains the artifacts you want to copy. 3. Select the nodes that contain the artifacts you want to copy and paste to a different location and choose Copy to Clipboard to create a copy of the nodes or Cut to Clipboard to create a copy of the nodes and at the same time remove the nodes from the current location. 4. Double-click the folder in the same project, or in a different project, to which you want to paste the nodes you have copied. 5. In the mass maintenance view for the new folder, choose Paste from Clipboard . 6. The nodes you copied from the previous location are pasted to the new location. Working with Copy and Paste Shortcut Keys in the Tree View In the tree view for your projects, you can use the standard copy Ctrl C and paste Ctrl V shortcut keys to copy and paste artifacts within a project or between open projects. To copy a data model in its entirety from one project to another and ensure that node references such as those between entity sets and entity types are copied and retained too, proceed as follows: 1. Open the project from which you want to copy the data model. 2. Select the Data Model folder and all its subfolders and press Ctrl C. The artifacts that have been copied to the clipboard are expanded in the tree view and highlighted in yellow. An information message is displayed at the bottom of the screen to confirm the number of nodes copied to the clipboard. 3. Open the project to which you want to copy the data model and ensure that this project is in edit mode. 4. Select the Data Model folder and press Ctrl V. This copies all the data model artifacts from one project to another. The artifacts that have been pasted from the clipboard into the project are expanded in the tree view and highlighted in yellow. An information message is displayed at the bottom of the screen to confirm the number of nodes pasted from the clipboard. Working with Copy and Paste Context Menu in the Tree View You can use the copy and paste functions from the context menu in the tree view to create copies in other open projects in edit mode. In this way, you can easily reuse existing entity types together with their properties and navigation properties, for example. To use the copy and paste functions from the context menu, proceed as described in the following example:
Procedure 1. To copy all entity types in a project, for example, right-click the Entity Types subfolder and choose Copy . All entity types contained in this folder are highlighted and selected for copying. An information message is displayed at the bottom of the screen to confirm the number of nodes that have been copied to the clipboard. 2. To create copies of these entity types in a different project, open the relevant project in edit mode. Right-click the Entity Types folder and choose Paste . All entity types copied to this folder are highlighted. An information message is displayed at the bottom of the screen to confirm the number of nodes that have been pasted from the clipboard.
Related Information Copying a Service Builder Project
1.4.3 Entity Types Use Use entity types in your Service Builder project to describe the structure of data in the Entity Data Model (EDM). Entity types represent a specific type of data, for example an item or a concept. Entity types comprise: A unique name A key, which can be defined by one or more properties (Is Key) Properties (optional) Navigational properties (optional to navigate between associations) The entity type properties must adhere to the data types allowed and provided by the OData protocol or be of a complex type. An entity type must have a unique identifier that allows the entities belonging to this entity type to be used within an OData context. You can group entity types together in entity sets.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 10 of 65
Procedure To create an entity type in your Service Builder project, proceed as follows: 1. Right click the Data Model folder, and choose Create, and then select Entity Type . The Create Entity Type dialog opens. 2. Specify the following: Entity Type Name Specify a name for the Entity Type Name . The names for entity type and entity sets are unique. An error displays if a character in the specified name is not allowed. Create Related Entity Set Select the Create Related Entity Set checkbox and the entity set name is added. When you choose OK , a new entity type and its entity set are created. In the mass edit view, the entity set table displays the entries for the new data model elements, the entity set and the entity type. Alternatively, use the following steps: 1. Expand the Data Model folder in the tree view of your project, and double-click Entity Types to open the mass maintenance view. 2. Choose Edit and then Insert Row to add a new row to the table for the new entity type. 3. In the Name column, enter a unique name for the entity type you want to create. You must enter a name in this column. For example, enter NEW_ENTITY_TYPE. 4. In the ABAP Structure Name column, you can enter the appropriate ABAP structure directly, or use the input help to search for an existing structure in the repository. 5. In the Base Type column, you can enter the relevant base type name directly or use the input help to display a list of existing node names and their descriptions. Base types (parents) inherit their properties to derived type (children). Inheritance between base types and derived types enables you to reuse existing entity types. 6. In the Is Abstract column, select the checkbox if you want to define the entity type as an abstract type. 7. In the Label column, enter a label for the new entity type. You can enter a free-text label directly or use the Label Text Reference Editor to enter the reference type, for example, program, data element, class or program. The reference type you select influences which of the other input fields (that is, Object Name , Key, , and Label you can, and need to, edit). 8. You can define the following optional attributes for the entity type: Column
Description
Semantics
Specifies how the entity type is to be used. For example, classifies a number as a telephone number or a fax number.
Thing Type
Select this checkbox if the entity type is a thing as opposed to a subordinate object. For example, a thing type is a tangible object such as a purchase order and a subordinate object is a purchase order item.
Media
Select this checkbox if the entity type belongs to a media collection and has a media source stream. This means every instance of this entity type points to an additional resource with some arbitary (MIME) type, for example, a photo with type image or jpeg.
As Author Property
OData feed customizing setting. Enter a property to be used for populating the atom:author element at runtime. Use the input help to select an existing property from the same entity type.
As ETag Property
OData feed customizing setting. Enter a property to be used as an ETag to support OData optimistic currency control for modifying requests. Use the input help to select an existing property from the same entity type.
As Published Property
OData feed customizing setting. Enter a property to be used for populating the atom:published element at runtime. Use the input help to select an existing property from the same entity type.
As Title Property
OData feed customizing setting. Enter a property to be used for populating the atom:title element at runtime. Use the input help to select an existing property from the same entity type.
As Updated Property
OData feed customizing setting. Enter a property to be used for populating the atom:updated element at runtime. Use the input help to select an existing property from the same entity type.
9. Choose Save to create the new entity type.
Note In the mass maintenance view, you can display the details of an entity type at any time by selecting the relevant row and choosing Details . A popup is displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only. To delete an existing entity type, select the relevant row in the mass maintenance view and choose Delete Row .
Creating Entity Type Properties and Navigation Properties After you have created and saved your entity types in the Entity Types subfolder, you can define the properties for each of these entity types. You can also define navigation properties that are required to create a link from one entity type to another using an association. For more information about how to define properties in the Service Builder see Defining Properties. For more information about how to define navigation properties, see Navigation Properties.
1.4.3.1 Defining Properties PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 11 of 65
Use In SAP NetWeaver Gateway Service Builder, you can define properties for entity type and complex types. Properties define the characteristics of the data that an entity type or complex type instance will contain at runtime. The properties of entity types and complex types are stored in a separate Properties subfolder within the Entity Types and Complex Types folders in your Service Builder project. Properties comprise the following: Attributes Name Type (Edm type (with facets such as Nullable, MaxLength, FixedLength, Precision, Scale ) or complex type Annotations SAP annotations (such as Creatable, Deletable, Label, UnitProperty ) Vocabulary-based annotations ABAP type information ABAP field name ABAP type assignment
Procedure To create a new property, proceed as follows: 1. Expand the Data Model folder in the tree view of your project. 2. Expand the Complex Types or Entity Types subfolder (depending on the data object type for which you want to edit the properties) and double-click the Properties subfolder. 3. Choose Edit in the mass maintenance view and then Insert Row to add a new row to the table for the new property. 4. In the Node Name column, enter a name for the property you want to create. You must enter a name in this column. For example, enter NEW_PROPERTY. Since this is a mandatory input field, if you do not enter a node name, an error message is displayed and you cannot save the changes to your project. 5. Define the attributes of the new property:
Note The columns in the Properties table differ depending on whether the project is of type Service with SAP Annotations , for which Edm Core Type and Complex Type are displayed, or Service with Vocabulary-Based Annotations , for which Type Kind (core type or complex type) and Type Name are displayed. For example, if your project is of type Service with Vocabulary-Based Annotations , the standard SAP attributes (creatable, updatable, sortable, for example) are not displayed since vocabulary-based annotations are to be used instead. Column
Description
Name
Enter a new name for the new property or modify the existing name as required. If you have imported the complex type or entity type, a name is already displayed, for example, currency.
Is Key
Select this checkbox to indicate that this is a key field in the data model.
Edm Core Type
Enter the Entity Data Model type allowed in OData for this property. For example, Edm.String, Edm.DateTime.
Type Kind
Specify whether the property is a Complex Type or Core Type for projects of type Service with Vocabulary-Based Annoations .
Data Type
Enter the data type that corresponds to the complex type or core type property. If it is a core type property, use the input help to select the appropriate Edm. type.
Precision
EDM facet. Enter the number of decimal places permitted for numeric data types. The value defines the maximum number of decimal places permitted to the left and right of the decimal point.
Scale
EDM facet. Enter the maximum number of decimal digits permitted after the decimal point.
Max Length
EDM facet. Enter the maximum length you want to allow at runtime. For example, enter 30 to specify a maximum length of 30 characters for this property.
Fixed Length
EDM facet. Select the checkbox to specify if a fixed length applies.
Unit Property Name
Enter the unit property name. Use the input help to select an existing property from the same complex type or entity type. For example, if the property comprises a number that refers to a currency or amount, you can specify the relevant currency or unit of measure.
Creatable
SAP annotation for projects of type Service with SAP Annotations . Select this checkbox if you want to allow a value assignment to this property in Create (POST) requests at runtime. If you select this checkbox, you must include a Create operation in the data model.
Updatable
SAP annotation for projects of type Service with SAP Annotations . Select this checkbox if you want to allow a value assignment to this property in Change (PUT/MERGE) requests at runtime. If you select this checkbox, you must include an Update operation in the data model.
Sortable
SAP annotation for projects of type Service with SAP Annotations . Select this checkbox if you want to allow this property to be used in $orderby statements for sorting data at runtime.
Nullable
EDM facet. Select this checkbox if you want to allow a null value to be entered for this property at runtime.
Filterable
Select this checkbox if you want to allow this property to be used in $filter statements for filtering data at runtime.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 12 of 65
Label
SAP annotation for projects of type Service with SAP Annotations . Enter a language-dependent label using the Label Text Reference Editor in the next column.
Label Editor
Use the Label Editor to specify the reference type ( Data Element, Class, Program, Free Text ). Depending on the reference type you select, the fields Object Name, Key, and Label that are relevant for the particular reference type are ready for input. Input help is available for these fields.
Complex Type Name
Enter the name of the complex type you have created in your project. You can use the input help to obtain an overview of complex types that exist in the current project.
ABAP Field Name
Internal name of the property. If you specified a structure binding for the parent entity or complex type, this denotes a component of this structure. Enter the ABAP field name. If you have imported the entity type, this field contains the ABAP field name in uppercase. You can use the ABAP Type Editor.
ABAP Type Editor
Use the ABAP Type Editor to specify how the ABAP type to EDM type mapping is to be determined ( Structure Binding at Entity or Complex Type, Explicit Assignment, Determination by Runtime Object Generator ) to be used for the ABAP field.
Semantics
Enter how the property is to be used. For example, classifies a number as a telephone number or a fax number.
Value Collection
Indicates whether or not the imported vocabulary includes a property for which a collection of values (multiple entries) exists. Applies to projects of type Service with Vocabulary-Based Annotations . This field is read-only in the properties for view for the data model.
Note To delete an existing property, select the relevant row in the mass maintenance view and choose Delete Row . SAP annotations provide additional metadata for the data model, but they are not validated at runtime. As such, the metadata merely provides the user of the service with additional information. However, if you are developing a specific application, you could include validation checks in the relevant data provider classes. Since the validation checks require a specific use case, these must be tailored to suit the particular customer application. Since it is possible to set an EDM type as well as an internal ABAP type for properties, these types must be validated to ensure that there is no mismatch between the values. Mismatches of this kind where one type is more restrictive than the other, for example DateTime and Date, may lead to data loss. In case of non-compatibility between an EDM type and an ABAP type, an error message is displayed.
More Information For information about defining navigation properties for entity types, see Navigation Properties.
1.4.3.1.1 Mappings and the ABAP Type Editor Use the ABAP Type Editor to define additional type information about properties and the corresponding ABAP field names. Use the ABAP Type Editor to facilitate the mapping between ABAP type and EDM type. You can select the determination mode, Structure Binding at Entity or Complex Type , Explicit Assignment or Determination by Runtime Object Generator that is to be used. If you choose Structure Binding at Entity or Complex Type , an ABAP structure is assigned to the entity type or complex type as appropriate. The automatic ABAP type assignment is derived from the EDM type. You can assign an ABAP structure at entity type or context type level, but not at the level of the individual properties. The ABAP structure that is assigned to the entity type or complex type is subsequently used by the generator. If an ABAP structure is not assigned at design time, the generator will subsequently generate a new structure based on the type information displayed. If you choose Explicit Assignment , you can maintain the category and subsequently the fields that are applicable for this category become ready for input. Fields that are not applicable remain read only. Use the explicit assignment if you specifically do not want an automatic assignment to take place. Note that structure binding overwrites any explicit assignments that have been maintained. Exact correlations between ABAP types and EDM types are not always possible due to their individual facets and the automatic determination of a corresponding ABAP or EDM type might not be a perfect match. Consequently, you must always review determined type mappings to ensure that you choose the best match possible. The Service Builder includes a validation check that determines possible inconsistencies and appropriate warning messages are displayed so you can prevent the loss of data that might otherwise arise through the mapping of ABAP type to EDM type and/or vice versa. The check distinguishes between potential loss of data, possible conversion errors, and the applicability of ABAP types.
Mapping ABAP Types and EDM Types The following example focuses on ABAP Datetime handling for properties with Edm.Datetime as just one example where inconsistencies can arise when mapping ABAP types and EDM types. For the Edm.Datetime property, in the backend, an ABAP field can be represented as a simple date or timestamp with fractional seconds or a timestamp without fractional seconds. Consequently, a property in the Service Builder with the EDM type Edm.Datetime requires additional information to map this EDM type to the correct ABAP type field in the backend. If this is not done correctly, wrong type assignments are the result. Correct type assignments are required for MPC generation as the DPC implementation is based on generated types in the MPC class. The original solution to achieve the correct type assignment in the Service Builder was: If precision = 0 & scale = 0, then internal type is type D. If precision = 8 & scale = 0, then internal type is type P length 8 decimals 0 (timestamp without fractional seconds) If scale = 7, then internal type is type P length 11 decimals 7 (timestamp with fractional seconds) Instead of using the precision and scale attributes in the above example, you can use the ABAP Type Editor in the Service Builder to set the internal type directly. In the ABAP Type Editor, you can set the category manually as Internal Type and: Type Kind = Date, Length = 8, Decimals = 0 (simple date, internal type D) Type Kind = Packed, Length = 15, Decimals = 0 (timestamp without fractional seconds, internal type displayed in MPC as type P, length 8, decimals 0) Type Kind = Packed, Length = 11, Decimals = 7 (timestamp with fractional seconds, internal type displayed in MPC as type P, length 11, decimals 7)
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 13 of 65
Alternatively, instead of setting the internal type, you can use the ABAP Type Editor to assign a data element to a property. In the ABAP Type Editor, you can manually set the category as Data Element and enter the data element name in the Associated Type Field . When using an RFC/BOR import or assigning a DDIC type, if the structure is assigned to the parent artifact (entity type or complex type), then no assignment is made at property level. When using the Import from DDIC Structure option, the date fields are handled in the following way: If the field's domain is of type 'TZNTSTMPS' then Timestamp without fractional seconds, internal type in MPC is type P length 8 decimals 0. If the field's domain is of type 'TZNTSMP1' then Timestamp with fractional seconds, internal type in MPC is t ype P length 11 decimals 7 Refer to the following EdmType usage and conversion to backend ABAP type: Table 1: EdmType Usage and Conversion EDM Primitive Type
XML Representation
ABAP Representation
ABAP Type
Edm.Binary
binary
Binary
XSTRING, HEX
Edm.Boolean
booleanLiteral
Boolean
CHAR LENGTH 1
Edm.String
string Literal
STRING
STRING, CHAR, NUM
Edm.Guid
guidLiteral
Guid
CHAR LENGTH 32, HEX LENGTH 16
Edm.Byte
byteLiteral
Byte
INT1, INT, NUM, HEX, LENGTH 1
Edm.SByte
sbyteliteral
Integer (1 byte)
INT2, INT, NUM
Edm.Int16
int16Literal
Integer (2 byte)
INT2, INT, NUM
Edm.Int32
int32Literal
Integer (4 byte)
INT, NUM
Edm.Int64
int64Literal
Integer (8 byte)
PACKED LENGTH 8 DECIMALS 0, NUM
Edm.Decimal
decimalLiteral
Decimal
PACKED, DECFLOAT16, DECFLOAT34
Edm.Double
doubleLiteral
Double
FLOAT
Edm.Single
singleLiteral
Single
FLOAT
Edm.Float
singleLiteral
Single
FLOAT
Edm.DateTime
dateTimeLiteral
DateTime as Timestamp
PACKED LENGTH 8, DECIMALS 0, PACKED LENGTH 11, DECIMALS 7
DateTime as Date
DATE
DateTime as Time
TIME PACKED LENGTH 8, DECIMALS 0,
Edm.DateTimeOffset
dateTimeOffsetLiteral
DateTimeOffset as Timestamp
Edm.Time
timeLiteral
Duration in seconds
PACKED, DECFLOAT16, DECFLOAT
Duration as Time
TIME
PACKED LENGTH 11, DECIMALS 7
Note If an ABAP structure is bound to an entity type, then the entity type properties refer to the ABAP structure's element types. The properties should have the same ABAP name as the element name of the ABAP structure. When using Datetime and its related properties as an optional field, set the attribute Nullable to true.
1.4.3.2 Navigation Properties Introduction The Entity Types includes one or more Navigation Properties. Navigation Properties describe the navigation path between the relationship of an entity. It is the property of an Entity that represents a link from the Entity to one or more related Entities. The Navigation Property is tied to an Association Type and allows the navigation from one end of the Entity Type that declares the Navigation Property, to the other related end. Navigation property is required to create a link from one entity to another via an association. Creating Navigation Properties
Procedure To create a Navigation Property for Entity Types proceed as follows:
Note Create Entity Types before creating Navigation Property. The Navigation Property folder displays only when an entity type is added. See Entity Types for creating entity types. 1. 2. 3. 4. 5. 6. 7.
Open the Service Builder. Expand the Data Model folder in the tree view of your project. Expand the Entity Types folder to view the entity types. Expand the listed entity types to view the Navigation Properties folder. Double click the Navigation Properties folder to open it in the mass edit view. Choose Display->Change button to switch to edit mode. Choose the Insert Row button to create a new association. A row will be added.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 14 of 65
A row will be added. 8. Do the following in the mass edit view under Navigation Properties : Fields
To Do
Name
Enter a name for the navigation property
Relationship Name
Enter the Association Name in the Relationship Name field, or use the input help to select the value (Mandatory field)
Label
Enter a label for the new Navigation Property
Label Text Reference Editor
To define the label, use the Label Text Reference Editor. The Label Text Reference Editor enables you to enter the reference type.
Note In the mass edit view, you can display the details of the association at any time by selecting the relevant row and choosing Details. A popup is displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only. 9. Save the changes
More Information See Associations for more information on additional functions.
1.4.4 Complex Types Use Use complex types to define structured properties for entity types or other complex types without exposing complex types themselves as independent OData entities. Since complex types consist of a collection of properties without a unique key, they can only exist as properties of a containing entity or, outside an entity, as a temporary value. Unlike entity types, complex types cannot form either end of an association between data objects, and therefore you cannot define navigation properties for complex types. However, complex types can contain other complex types, meaning that they can have a deep structure. Within a complex type the cardinality is always 1:1. Complex types comprise: A unique name Properties (optional)
Example A complex type structure called Fullname could comprise two properties, firstname and lastname .
Creating a Complex Type Procedure To create a complex type in your Service Builder project, proceed as follows: 1. Right click the Data Model folder, and choose Create, and then select Complex Type . Also, you can create a new Complex Type when you right click the Complex Type folder, and choose Create . The Complex Type dialog opens. 2. Specify the Complex Type. Alternatively, use the following steps: 1. 2. 3. 4.
Expand the Data Model folder in the tree view of your project. Double-click the Complex Types subfolder to open the mass maintenance view. Choose Edit and then Insert Row to add a new row to the table for the new complex type. In the Node Name column, enter a unique name for the complex type you want to create. You must enter a name in this column. For example, enter NEW_COMPLEX_TYPE.
5. In the ABAP Structure Name column, you can enter the appropriate ABAP structure directly, or use the input help to search for an existing structure in the repository. 6. In the Base Type Name column, you can enter the relevant base type name directly or use the input help to display a list of node names and their descriptions. Base types (parents) inherit their properties to derived types (children). Inheritance between base types and derived types enables you to reuse existing complex types. 7. In the Is Abstract column, select the checkbox if the new complex type is of type abstract as opposed to concrete. As default, this checkbox is not selected. If you set the type as abstract, your service implementation has to use a concrete derived type at runtime. 8. In the Label column, you can enter a label for the new complex type. You can enter a free-text label directly or use the Label Text Reference Editor to enter the reference type, for example, program, data element, class, or program. The reference type you select influences which of the other input fields (that is, Object Name , Key , and Label you can, and need to, edit. 9. Choose Save to create the new complex type.
Note In the mass maintenance view, you can display the details of a complex type at any time by selecting the relevant row and choosing Details. A popup is displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 15 of 65
To delete an existing complex type, select the relevant row in the mass maintenance view and choose Delete Row .
Creating Complex Type Properties After you have created and saved your complex types in the Complex Types subfolder, you can define the properties for each of these complex types. For more information about how to edit properties in the Service Builder, see Defining Properties.
1.4.5 Associations Concept 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. The Service Builder provides the facility to create and edit Associations. This document guides you to create an association in the Service Builder. Creating an Association You can create an association in one of two ways: Using the Association Wizard Use the Association wizard to quickly define the following for a data model: Associations Association Sets Referential Constraints Navigation Properties Using the Mass Edit View Create and edit the different individual artifacts needed for an association using the mass edit view for the data model. You can quickly define a minimum set of information for an association using the association wizard, and enhance it using the mass edit view.
Note Make sure that you are working in the edit mode. Using the Association Wizard To create an association using the wizard: 1. Right click the data model folder in your project, and choose Create , and then choose Association . Alternatively, right click Associations in the data model folder and choose Create . The Association wizard displays. 2. Specify the following in the Create Association page of the wizard: Association name Specifies a name for the new association. An error message displays if you do not specify a name, or if the name contains a character that is not allowed. Below this field, there are the following areas: Principal Entity The Principal Entity represents the leading end of the association. Entity Type Name Specifies the name of the entity type for the new association. The entity at this end of the association can exist independently of the entity on the dependent end of the association. Press F4 to select the entity type. Cardinality Specifies the relations between the specified principal entity type and the dependent entity type. Press F4 or click to select from the list. The multiplicity of the association can be as follows: 0: 0..1 Only one instance occurs, zero is also allowed. 1 One-to-one relations. Exactly one instance occurs. M: 1..n One-to-many relations. One or more instances can occur. N: 0..n Zero-to-many relations. Zero or more instances can occur.
Note Many-to-many relations is not supported in the wizard. Create related navigation property Optional. Select this option to set a link for the entity type. Under Principal Entity, when selected the navigation property name is proposed based on the specified cardinality. Under Dependent Entity, when selected the navigation property name is proposed based on the specified cardinality. Navigation Property Available only when the option to create a related navigation property is selected. It sets a navigation property name for the specified entity type. The name is proposed based on the cardinality of the entity. Dependent Entity The Dependent Entity represents the secondary part of the association. Entity Type Name Specifies the name of the entity type defined as the related entity in the new association. Press F4 to select the entity type.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 16 of 65
3.
4.
5. 6.
The entity at this part of the association exists only if an entity type has been defined for the Principal Entity Cardinality Specifies the relations between the specified dependent entity type and the principal entity type. Press F4 or click to select from the list. The multiplicity of the association can be as defined in the principal part of the association: Create related navigation property Optional. Select this option to set a link for the entity type. Under Dependent Entity, when selected the navigation property name is proposed based on the specified cardinality. Navigation Property Available only when the option to create a related navigation property is selected. It sets a navigation property name for the specified entity type. The name is proposed based on the cardinality of the entity. Click Next to define referential constraints. The principal part of the referential constraint contains one or more property elements that name the key properties of the principal entity type. To make changes in the previous wizard page, click Back . Specify the following for the referential constraints; you can relate each key of the principal entity type to a property of the dependent entity type: Principal key Press F4 to select a key property in the principal entity type. Dependent property: Press F4 to select a property in the specified dependent entity type. Click Next to define a name for the association sets, or the collection of associations in each entity type. Press F4 to select the entity set for the specified entity type. Click Finish .
The wizard creates an entity object that contains the collection of association set, the Entity Set, and the Navigation Properties for the defined Association. Using the Mass Edit View To create an association using the mass edit view. proceed as follows: 1. Expand the Data Model folder in the tree view of your project . 2. Choose Edit for edit mode. 3. Double-click the Association folder to open it in the mass edit view. 4. Choose Edit and then Insert Row to create a new association. A row is now added. 5. Do the following in the mass edit view under Associations : Fields
Description
Name
Enter a name for the new association in this field.
Note An error message displays if you do not enter a name for the association.
External Association
Click to create an external association. The term external association refers to creating an association with the entities of the model that has been included in the Service Builder. See Including an OData Service for more information.
Principal Entity
Enter the name of the Principal Entity, the entity which is being considered for the From Role in the new association.
Principle Entity Cardinality
Select a cardinality for the Principal Entity from the drop-down list.
Dependent Entity
Enter the name of the Dependent Entity, the entity which is being considered for the To Role in the new association.
Dependent Entity Cardinality
Select a cardinality of the Dependent Entity from the drop-down list.
Label
Enter a label for the new association. This label is displayed as the label when the service is consumed.
Label Text Reference Editor
To define the label, use the Label Text Reference Editor. The Label Text Reference Editor enables you to enter the reference type.
Note In the mass edit view, you can display the details of the association at any time by selecting the relevant row and choosing Details displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.
. A popup is
6. You can also use additional functions available in the mass edit view as described in the table below: Icons
Description Click to insert a row as required to add an association Click to delete a row Click to sort the list in ascending order Click to sort the list in the descending order Click to change the existing layout Click to hide and unhide the tree view
7. Click to save the association. The new Association will appear under the Associations folder in the tree view.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 17 of 65
Note Generated services based on BOR and RFC data sources in the Service Builder support navigation between entities within the same service, and between entities in different services. To properly handle associations for data sources, make sure that the following is met: 1. A referential constraint has been created to define a foreign key relation. 2. A navigation property is created for the principal entity. Navigation from a dependent entity to a principal entity is not supported by the generating mechanism for BOR and RFC data sources.
More Information See Including an OData Service. See Navigation Properties See Referential Constraints See Association Sets
1.4.5.1 Referential Constraints Introduction A referential Constraint can be used to specify the foreign key relationship for 1:1 or 1:n associations.
Creating Referential Constraints Procedure To create Referential Constraints proceed as follows: 1. 2. 3. 4. 5.
Open the Service Builder. Expand the Data Model folder in the tree view of your project. Expand the Entity Types folder to view the entity types. Expand the entity types to view the Navigation Properties folder . Double click the Navigation Properties folder to open it in the mass edit view.
6. Choose Display->Change
button to switch to edit mode.
7. Choose the Append Row to create a new association. A row is now added. 8. Do the following in the mass edit view: Fields
Description
Principle Entity
Enter the name of the Principal Entity for which the association has to be created.
Principle Key
Enter a Key Property of the principle Entity Type. Use the input help to select an existing property.
Dependent Entity
Enter the name of the Dependent Entity for which the association has to be created.
Dependent Property
Enter the Property of the dependent Entity Type which correlates to the entered Key property of the principle Type. Use the input help to select an existing property.
Note You have to add one mapping for each Key Property of the Principle Entity Type.
Note To create Referential Constraint, both the Principle and Dependent Property fields are mandatory.
Note In the mass edit view, you can display the details of the association at any time by selecting the relevant row and choosing Details displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.
. A popup is
9. Save the changes.
More Information See Associations for more information on additional functions.
1.4.6 Entity Sets Use PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 18 of 65
Use entity sets in your Service Builder project to group together instances of an entity type together with instances of any type that are derived from this particular entity type. While an entity type describes a data structure, an entity set contains the instances of the given structure. For more information about entity types, see Entity Types.
Creating an Entity Set To create an entity set in your Service Builder project, proceed as follows: 1. Right click the Data Model folder, and choose Create, and then select Entity Set . Also, you can create a new Entity Set when you right click the Entity Set folder, and choose Create . The Create Entity Set dialog opens. 2. Specify the Entity Set name and the related Entity Type.
Procedure Alternatively, use the following steps: 1. 2. 3. 4.
Expand the Data Model folder in the tree view of your project. Double-click the Entity Sets folder to open the mass maintenance view. Choose Edit in the mass maintenance view and then choose Insert Row to add a new row to the table for the new entity set. In the Node Name column, enter a name for the entity set you want to create. You must enter a name in this column. For example, enter NEW_ENTITY_SET.
5. In the Entity Type Name column, enter the name of an existing entity type or your project or search for an entity type in your project using the input help. 6. In the Label column, enter a label for the new entity set. You can enter a free-text label directly or use the Label Text Reference Editor to enter the reference type, for example, program, data element, class or program. The reference type you select influences which of the other input fields (that is, Object Name , Key , and Label you can, and need to, edit. 7. You can define the following optional attributes for the entity set: Column
Description
Semantics
Specifies how the entity set is to be used in your service implementation.
Creatable
Select this checkbox to indicate that creation is supported by your service implementation.
Updatable
Select this checkbox to indicate that updating is supported by your service implementation.
Deletable
Select this checkbox to indicate that deletion is supported by your service implementation.
Pageable
Select this checkbox to indicate that paging is supported by your service implementation.
Addressable
Select this checkbox to indicate that the addressable function is supported by your service implementation.
Searchable
Select this checkbox to indicate that searches are supported by your service implementation.
Subscribable
Select this checkbox to indicate that subscriptions are supported by your service implementation.
Requires Filter
Select this checkbox to indicate that a filter is required by your service implementation. If you select this checkbox, the entity set cannot be accessed directly and cannot be queried without a $filter expression.
8. Choose Save to create the new entity set.
Note In the mass maintenance view, you can display the details of an entity set at any time by selecting the relevant row and choosing Details . A popup is displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only. To delete an existing entity set, select the relevant row in the mass maintenance view and choose Delete Row .
1.4.7 Association Sets Introduction An Association Set groups Association instances (similar to how an Entity Set groups Entity Type instances). Hence, it specifies a relationship between two Entity Sets based on the respective Entity Types of the underlying Association.
Example Assuming you have a 1:n association Author_To_Books based on Entity Types Author and Book there may be an Association Set WrittenBy for the Entity Sets Authors and Books , as well as another Association Set FictionWrittenBy for the Entity Sets FictionAuthors and FictionBooks . This means if you follow a navigation link from an entry of an Authors feed at runtime, it will yield a Books feed, whereas following a link from an entry of the FictionAuthors feed will yield a FictionBooks feed - both are structurally equal (due to being based on the same Entity Types) but have different semantics and may contain different entries.
Procedure PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 19 of 65
Procedure To create an Association Set in the Service Builder proceed as follows: 1. Right click the Data Model folder, and choose Create, and then select Association Set . Also, you can create a new Association Set when you right click the Association Set folder, and choose Create . The Create Association Set dialog opens. 2. Specify a name for the Association Set. The Association Set name must be unique, and cannot contain characters that are not allowed such as, numbers and other symbols. All the elements needed to create relations between entities, such as Association, Association Set, Referential Constraints, and Navigation Properties are also created for you. Press F4 in Association Name to choose from the list of associations in the model. The Association Set and Navigation Properties must be unique. The cardinality for the Entity Type and Entity Set are automatically verified. When you choose OK , a new Association Set is created in the project tree. In the mass edit view, the Association Set table displays the new entries for the Association Set. Alternatively, use the following steps: 1. Open the Service Builder. 2. Expand the Data Model folder in the tree view of your project. 3. Double-click the Association Set folder to open it in the mass edit view. 4. Choose Edit and then choose to create a new association. A row is now added. 5. Do the following in the mass edit view under Association Sets : Fields
Description
Name
Enter a association set name in the Association Set Name field.
Association
Enter the association name in the Association Name field.
Principal Entity Set Name
Enter the name of the Principal Entity Set for which the association set has to be created.
Dependent Entity Set Name
Enter the name of the Dependent Entity Set for which the association set has to be created.
Label
Enter a label for the new association.
Label Text Reference Editor
To define the label, use the Label Text Reference Editor. The Label Text Reference Editor enables you to enter the reference type.
Note In the mass edit view, you can display the details of the association at any time by selecting the relevant row and choosing Details displayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.
. A popup is
6. Save the changes.
More Information See Associations for more information about additional options.
1.4.8 Function Imports Use The Open Data Protocol (OData) includes standard CRUD (Create, Retrieve, Update, and Delete) operations that map to the HTTP methods POST, GET, PUT/MERGE, and DELETE. In addition, OData supports further service operations (function imports) that can be invoked by the HTTP methods GET or POST for anything that cannot be mapped to the standard CRUD operations. You can implement such additional service operations in the Service Builder by creating function imports within your data model. For example, you could create function imports for the following custom operations: Confirm Work Item Check Flight Availability While it is simple to create new function imports to invoke custom operations, if the operation you want to use can be invoked using a standard CRUD operation, you should not create a function import. That is, you should only create function imports for custom operations that cannot be invoked using a standard operation.
Procedure To create a function import for a custom operation, proceed as follows: 1. Right click the Data Model folder, and choose Create, and then select Function Import . Also, you can create a new Function Import when you right click the function import folder, and choose Create . The Create Function Import dialog opens. 2. Specify the Function Import name. Alternatively, use the following steps: 1. Open the Service Builder project in which you want to create a function import. 2. Expand the Data Model folder and double-click the Function Imports subfolder. The mass maintenance view for function imports is displayed.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 20 of 65
3. Choose Edit and Add Line to create an entry for the new function import. 4. Enter a name for the function import you want to create, for example, CheckFlightAvailabilty . You must enter a name in this field to proceed with the creation process. 5. Select the kind of return type (if any) you want the function import to return data at runtime. Possible entries are: Complex type Entity type No return (no data returned) 6. In the Return Type column, enter the name of the complex type or entity type you want the function import to return. You can use the input help to select an existing complex type or entity type from your project. If the input help is empty, you must first create the relevant complex type or entity type in your project. If you selected No Return as the Return Type Kind , this field is not ready for input and has a grey background. 7. In the Return Cardinality column, select the number of complex type or entity type instances you want to be returned. 8. If you want more than one entity type instance to be returned, you must enter the entity set that is to be used for this purpose in the Return Entity Set column. In any other case, you are not required to specify an entity set and as such the field is not ready for input and has a grey background. 9. Select the HTTP method to be used to invoke the function import. If you do not select an HTTP method, the caller may invoke the function import using the GET or POST method. 10. Select the entity type to which the function import applies semantically as an action. While this setting has no effect at runtime, it can help the consumer of the service to ascertain the purpose of the function import or determine which function imports belong to a particular entity type. 11. Choose Save to create the new function import and invoke the custom operation at runtime.
1.4.8.1 Function Import Parameters Use You define function import parameters in SAP NetWeaver Gateway Service Builder to fine tune new function imports you have created that will invoke the required custom operations. The process for defining function import parameters is almost identical to the way in which you define properties for complex types and entity types.
Overview You can define the following parameters: Column
Description
Parameter Name
Enter name, for example, flightdate or connectionID
EDM Core Type
Enter core type, For example, Edm.String or Edm.DateTime
Data Element
Enter elementary type for the function import parameter. If you specify a DDIC data element, its type attributes will be reflected in the resulting OData service metadata. This is provided that you do not overwrite the type attributes by specifying a maximum length for the function import parameter explicitly.
Precision
Enter the number of decimal places permitted for numeric data types. The value defines the maximum number of decimal places permitted to the left and right of the decimal point.
Scale
Enter the maximum number of decimal digits permitted after the decimal point.
Max Length
Enter the maximum length you want to allow at runtime. For example, enter 30 to specify a maximum length of 30 characters for this parameter.
Semantics
Enter how the parameter is to be used. For example, classifies a number as a telephone number or a fax number.
Unit Reference Parameter
Enter the unit reference to be used. For example, if the parameter comprises a number that refers to a currency or amount, you can specify the currency or unit of measure that is to be used.
Label
Enter a label text to be displayed at runtime.
1.4.9 Working with Annotations Explains the concept behind adding annotations to data model artifacts to specifiy how an artifact is to be used. You can add annotations to data model artifacts to provide additional data or descriptive information about an artifact to specify how the data is to be displayed by an OData service. Use standard SAP annotations at design time to add semantics that describe certain behavior applicable to an artifact such as creatable, updatable, or sortable, for example, or to provide consumption hints such as which fields form an address or which fields logically belong together, for example. Annoatations represent a consensus between the data model developer and the consumer of the data model as to how the data model is ideally to be used. While annotations provide precise instructions as to how a data model should be consumed they also act as an extension point to provide additional information that is useful for the consumption of the data model. Two types of annotations exist: Annotations that describe the parts of the data model that originate from a backend system (precision) Annotations that describe additional parts of the Entity Data Model (EDM) for the consumer (extension) By annotating metadata and instance data at design time you have the flexibility to add more precise information about an artifact that would not otherwise be possible using the core SAP attributes alone. Some artifacts within a given data model will, for reasons of logic, not permit all the possible interactions that are supported by a given interface and you can use annotations to convey such restrictions in the data model definition. At entity type or entity set level, for example, you can use annotations to define whether the artifact is searchable or updatable and which properties may be used in filter expressions.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 21 of 65
Annotation Composition Put simply, annotations comprise the following key entries: Target (for example, entity type, entity set, complex type, property or association to which the annotation applies) Term (entry that can define the artifact type (for example, Scale or Unit) or usage (for example, Countable, Navigable, Expandable) Qualifier (free qualifier that defines context) An annotation is a combination of these three entries, which together result in the specific usage and/or presentation of a particular artifact instance. For this reason, only one annotation may exist for a particular artifact in a data model. Essentially, annotations provide you with much greater freedom to define more precise and explicit information about an artifact than the definition of core attributes alone can allow. Annotations are consolidated in vocabularies and care should be taken to ensure that the newly defined annotations can be clearly understood by a wide audience.
Annotations in Service Builder Projects When you create a new project in the Service Builder, you are required to define the project type. Choose Service with SAP Annotations to use standard SAP extensions (such as Creatable, Updatable, Label, UnitProperty) Choose Service with Vocabulary-Based Annotations to use annotations (customer-specific extensions) defined in separate vocabulary files. A central Vocabulary Repository exists (choose Extras Vocabulary Repository in the Service Builder menu) that includes some standard vocabulary files in the /IWBEP/ namespace for vocabulary-based annotations, but you can also upload customer-specific vocabulary files for greater flexibility. Use the standard vocabulary files as a template for defining your own vocabulary files if required. You can import one or more of the vocabulary files from the Vocabulary Repository to your data model contained in the Service Builder project.
Note The project type you define when you create a new project cannot be changed at a later time.
Related Information Creating a Service Builder Project Uploading Vocabularies into the Vocabulary Repository Adding Vocabulary-Based Annotations to Data Model Artifacts
1.4.9.1 Uploading Vocabularies into the Vocabulary Repository Instructions for uploading a vocabulary file into the Vocabulary Repository.
Context If you want to use customer-specific annotations in addition to core attributes (SAP annotations) when defining data model artifacts in Service Builder projects, you can upload the annotations you require collectively in the form of a vocabulary file into the Vocabulary Repository. The Vocabulary Repository already includes a selection of standard vocabulary files and these are available in the /IWBEP/ namespace. You can import the annotations contained in a vocabulary file into Service Builder projects of type Service with Vocabulary-Based Annotations . After you have imported the relevant vocabulary files into your project, you can use vocabulary-based annotations to define additional information about the artifacts in your data model. To upload a vocabulary file into the Vocabulary Repository in the Service Builder, proceed as follows:
Procedure 1. Start the Service Builder in transaction SEGW. 2. Choose Extras Vocabulary Repository . The central Vocabulary Repository opens and shows a table for displaying the vocabulary ID, version, namespace, and description. Any previously uploaded vocabulary files are displayed here, otherwise the table is empty. 3. Change to edit mode and choose Append Row to add a new row to the table. 4. Enter a unique vocabulary ID for the vocabulary file you want to upload. Version 1 is assigned automatically to the first version of the vocabulary file you upload. 5. Click the Upload icon in the Upload Vocabulary Content column to navigate to the vocabulary file you want to upload. The namespace of the vocabulary file is entered automatically. 6. Enter a description for the newly added vocabulary file. 7. Save the changes and choose Enter .
Results Subsequently, the uploaded vocabulary file can be imported into Service Builder projects of type Service with Vocabulary-Based Annotations so the terms defined in this file can be used to annotate data models.
Related Information Importing a Vocabulary File Adding Vocabulary-Based Annotations to Data Model Artifacts
1.4.9.2 Importing a Vocabulary File Instructions for importing a vocabulary file into the Service Builder.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 22 of 65
Context After a vocabulary file has been uploaded into the central Vocabulary Repository, you can import it into the Service Builder to annotate data model artifacts. Subsequently, to import a vocabulary file into the Service Builder and use this for working with annotations, proceed as follows:
Procedure 1. Start the Service Builder in transaction SEGW. 2. In edit mode, right click the Data Model folder in the tree view and choose Import Vocabulary . This menu option is only available for projects created of type Service with Vocabulary-Based Annotations . 3. In the Vocabulary Repository, select the vocabulary file you want to use and choose Continue . A new folder entitled Vocabularies is created for this data model in tree view and the vocabulary file is imported. 4. Double-click the Terms node in the Vocabularies folder to see the details of the imported vocabulary files in the mass maintenance view.
Results After the vocabulary definitions have been added to the data model, you can use these terms to annotate the data model artifacts as they can be applied.
Note Parsing will treat both V3 and higher terms as valid items and update appropriately. For example, both Value Term (V3) and Term (higher terms than V3) are valid and will be updated to Term node. Both Using and Reference -> Include elements are valid to reference a vocabulary definition. When adding vocabularies into the data model, if the referenced vocabulary is available in the Vocabulary Repository, then it will also be imported into the data model in the Implicit References folder.
Related Information Creating a Service Builder Project Uploading Vocabularies into the Vocabulary Repository Adding Vocabulary-Based Annotations to Data Model Artifacts
1.4.9.3 Adding Vocabulary-Based Annotations to Data Model Artifacts Explains how to add vocabulary-based annotations to data model artifacts in the Service Builder.
Context Add vocabulary-based annotations to data model artifacts such as complex types, entity types, and associations, for example, to specify information about a particular artifact that would not be possible using core attributes alone. To add vocabulary-based annotations, you can use the vocabulary files available in the Vocabulary Repository as standard in the /IWBEP namespace or you can define and upload customer-specific vocabulary files. For example, you might want to use ths standard vocabulary Ord.OData.Aggregation.V1 to add the annotations LeveledHierarchy or RecursiveHierarchy to entity types for which otherwise only core attributes could be defined such as Base Type Name and Is Abstract . You can import one or more vocabulary files for use in a data model provided that the data model is created in a Service Builder project of type Service with Vocabulary-Based Annotations . Ensure that at least one vocabulary file has been uploaded into the Vocabulary Repository. Furthermore, you must have created a Service Builder project of type Service with Vocabulary-Based Annotations into which you have imported one or more vocabulary files from the Vocabulary Repository. To import a vocabulary file, ensure the project is in edit mode, right click the Data Model folder and choose Import Vocabulary . After you have imported a vocabulary file into your data model, a Vocabularies subfolder is displayed for the data model in the tree view. The Vocabularies subfolder includes: Imports subfolder that lists the name of the vocabulary files explicitly imported from the Vocabulary Repository to the data model. For each imported vocabulary file, you can expand the data model artifacts for which it applies, for example, complex types and their properties and the defined terms. Implicit References subfolder that lists the names of the vocabulary files used implicitly since the imported vocabularies reference it. For each implicitly referenced vocabulary file, you can expand the data model artifacts for which it applies, for example, complex types and their properties and the defined terms. Double-click the Vocabularies subfolder to display the available vocabularies in an overview table in the mass maintenance view. This overview displays the vocabulary ID, version, namespace, and a description (if available). Futher, nestled inside each subfolder for a particular entity type or complex type, for example, in the data model, an Annotations subfolder exists that lists the imported vocabularies and specifies the number of applicable terms each vocabulary defines for the given node. These are the vocabulary-based annotations you can add to these artifacts. If, however, a vocabulary cannot be applied to a given artifact, the vocabulary is displayed in a grey (as opposed to black) font and the following descriptive text is displayed, Vocabulary does not define applicable terms for target node type Entity Type. To see this additional information about imported vocabularies, the hierarchy view must be displayed in full-screen mode. Close any overviews in the mass maintenance area if you cannot see this information. To add annotations to artifacts for which vocabularies define applicable terms, proceed as follows:
Procedure 1. Double-click the subfolder that contains the artifacts you want to annotate, for example, Entity Sets . Existing entity sets are listed in the mass maintenance view. 2. Choose the Annotation pushbutton to see the vocabulary that is valid for these entity sets. If more than one vocabulary defines applicable terms, you can select the vocabulary you want to use to annotate the entity set and, if required, toggle between the different vocabularies. If none of the imported
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 23 of 65
3.
4.
5. 6.
vocabularies includes applicable terms for entity sets, for example, this pushbutton is not enabled. After you have selected the vocabulary you want to use for the annotations, all entity sets are displayed in a table in the mass maintenance view with the name of the applicable vocabulary displayed as a header. To create annotations for an entity set, select either the entire row to create all available annotations or select the applicable cells for each annotation you want to create and choose the Create Annotation pushbutton. You can select more than one row and more than one cell to enable the mass maintenance of multiple entity sets and annotations, for example. The annotations you have created for a particular artifact are also displayed in the Annotations subfolder, organized according to vocabulary, for each node in the data model's hierarchy view. To display detailed information (annotation data, term type, and expression value) about an annotation, double-click the annotation. The annotation data is then displayed in an additional table. If you want to display detailed information about all the annotations created for a particular entity set, double-click the entity set itself. If you want to delete any annotations, select the relevat rows or cells and choose the Delete Annotation pushbutton. Save your entries. If you want to navigate from the annotation mass maintenance view and see an overview of the core attributes (SAP annotations) that can be defined for the entity set, choose the Core Attributes pushbutton.
Related Information Importing a Vocabulary File
1.5 Data Modeling Options Use SAP NetWeaver Gateway Service Builder provides a variety of data modeling options to simplify the data modeling process for you significantly by enabling you to reuse existing data models or redefine existing services. Depending on your development experience and the time you have available, you can choose which option is best suited to your needs.
Options for Reusing Data Models If you want to reuse an existing data model as opposed to defining a new data model, you have the following options: Importing a Data Model by uploading a file (.edmx or .xml) containing pre-defined data you want to reuse in your Service Builder project. Importing a DDIC Structure to reuse an existing ABAP structure as a complex type or entity type. Importing a Data Source (RFC/BOR Interface) to implement RFC or BOR generators. Alternatively, see: Redefining Services Including an OData Service (Gateway)
1.5.1 Importing a Data Model Introduction Use The File Import function is developed to allow importing of the data model files defined by external model editors like Visual Studio (edmx files) and the metadata files types (xml) into the Service Builder to create a data model. This feature can be used in the following scenarios: To import a metadata/edmx file for a new project. In instances where you create a project and import a file. To import a metadata/edmx file for an existing project, which already has a data model created (re-import). In this case, the existing data model will be overwritten.
Prerequisites Ensure that the virus scan profile /SCET/GUI_UPLOAD is Active and selected as Default Profile in the SAP system.
Figure 1: Setting Virus Scan Profile
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 24 of 65
More Information For more information on Virus Scan Profile, see http://help.sap.com/saphelp_nw70/helpdata/en/ae/ad1640033ae569e10000000a155106/frameset.htm.
Importing a Data Model - New and Empty Project Procedure To Import a model file proceed as follows: 1. Logon to the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder appears. 3. Create a new project by following the instructions in the Creating a Service Builder Project section. The Service Builder creates the new project together with an empty folder structure. You can see the newly-created project structure in the tree view in the left-hand screen area.
Note For existing projects, these folders are already available and you have to just proceed with importing the data model file. 4. Switch to edit mode. 5. Right click on the Data Model
Import
Data Model from File
to import a metadata/edmx type file.
Figure 2: Data Model-> Import-> Data Model from File
Note For an existing project, an overwrite confirmation window appears. Choose Yes to proceed. 6. The file browser to Select a model file for import appears. 7. Select a xml or an edmx file and click Open .
Note When a file other than the xml or edmx type is selected, an error message displays. 8. On successful import of the xml or edmx file an message displays confirming the import. 9. The OData artifacts available in the imported model file will be populated under the respective folders under the project.
Figure 3: OData Artifacts Loaded
10. Double-click the artifacts to view the details in the mass edit area. 11. Save the Project.
Note If you do not save your newly-created project, your data will be lost when the Service Builder is closed.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 25 of 65
Importing a Model File - Existing Project Procedure To import a model file for existing project proceed as follows: 1. Logon to the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Click to open an existing project. The Open Project window appears.
Figure 4: Open Project Window
4. Either click the view cluster button or press F4 to view the available projects. 5. Select the project and click to execute the project. The project displays in the Service Builder. 6. Click the change button on the tool bar. OR Right click on Data Model and choose Change . The project is now open for editing. 7. Right click on Data Model and in the resulting submenu, select Import Data Model from File to import a metadata/edmx type file. An overwrite confirmation message displays. 8. Click Yes to proceed. The Select a model file for import window appears. 9. Select a xml or an edmx file and click Open . On successful import of the xml or edmx file an message displays confirming the import. The OData artifacts available in the imported model file will be populated under the respective folders under the project. 10. Double-click the artifacts to view the details in the mass edit view. 11. Save the Project.
Activities You can also perform the following activities in the Service Builder after importing the data model: Make the required changes to the artifacts in the Service Builder. For more information, see Defining a Data Model. Include a different OData service (GW) and create an Association. For information, see Including an OData Service (Gateway). Import entities from a data source to enhance the model. For more information, see Importing a Data Source (RFC/BOR Interface). Generate the runtime objects. For more information, see Generating Runtime Objects. Register and maintain the service in the configured Gateway hub systems. For more information, see Service Maintenance
1.5.2 Importing a DDIC Structure Use To reduce the time required to create complex types and entity types in your data model, the Service Builder provides you with an Import DDIC Structure function with which you can import an existing ABAP (DDIC) structure and reuse this data to create new complex types and entity types with ease. You can import the following DDIC structures into the Service Builder: Views Database tables Structures
Procedure Importing the DDIC Structure comprises three steps: Import the DDIC Structure Select the parameters from the DDIC Structure Modify the selected parameters To import a DDIC structure into a data model, proceed as follows: 1. Log onto the SAP NetWeaver Gateway system.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 26 of 65
2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Create a new project. For more information, see Creating a Service Builder Project 4. Switch to edit mode. 5. Right-click the Data Model subfolder within the open project located in the tree view in the left-hand screen area and choose Import DDIC Structure . The Wizard Step 1 of 3: Import from DDIC Structure—Create an Entity Type or Complex Type screen of the wizard opens to guide you through the creation of entity types and complex types. 6. Do the following in the Import from DDIC Structure window: 1. Enter a name for the new entity type/complex Type in the Name field 2. Select either Entity Type to import the selected structure into your data model as an entity type or Complex Type to import the selected structure into your data model as a complex type. 3. In the ABAP Structure field, enter the ABAP structure name or use input help to get assistance.
Note Input help (F4 Help) is not available for class/interface-based type structures End of the note. 4. Click Next to proceed.
Note If any entries are incorrect, an error message is displayed. End of the note. If the validation check is successful, the Wizard Step 2 of 3: Import from DDIC Structure-Select Parameter(s) screen of the wizard opens. Based on the chosen ABAP structure name in the Wizard Step1 of 3, you can see a detailed display of the components of the structure as a tree. 7. Expand the Data Source Parameters and select the required structures, tables, and properties. You can also use the (Select All) and (Deselect All) buttons to perform a mass select and deselect. 8. Select the check-box under Assign Structure to create additional artifacts. Complex types will be created if the parameter is a structure type and entity types will be created If the parameter is a table type. In addition, DDIC assignment will be retained for the newly created artifacts. If this check-box is not selected then all the properties will be created under one root as a flattened structure. 9. Choose Next. The Wizard Step 3 of 3: Import from DDIC Structure-Modify Entity Type screen of the wizard opens. Based on the selection from Wizard Step 2 of 3, the Service Builder lists an overview of all fields in the structure you have selected to import as an entity type/complex type. 10. The Modify Entity Type screen provides the following editable and non-editable information: Table 1: Modify Entity Type Screen Details Name
Description
ISEntity
If the property belongs to the entity type, this check box is selected. If it is not selected, the property belongs to the complex type.
Non-Editable
Complex/Entity Type Name
This is the name of the property. It can either be a complex type or entity type
Editable
ABAP Name
This is the technical name. This will not be displayed in the metadata.
Non-Editable
Is Key
Indicates whether the imported property is to be imported Editable as a key of the entity type. Each entity type must define at least one key property.
Name
Name of the property
Editable
Label
Name of the property
Editable
Note The check-box Create Default Entity Set will be selected by default if an entity type is chosen for creation. You can choose not to create entity sets by unselect this box. If there are no entity types then this will be disabled. All entity sets will be created with the suffix name Set. For example, If Entity type name is E1 then the default entity set name will be E1Set. End of the note. 11. Choose Finish. Result The model contents will be transformed from the wizard to the data model as a new entity type together with its properties.
1.5.3 Importing a Data Source (RFC/BOR Interface) Introduction Use To reduce the time required to create entity types in your data model, SAP NetWeaver Gateway Service Builder provides you with the Import RFC/BOR Interface function with which you can import an existing data source and reuse this data to create new entity types with ease. A wizard is provided to guide you through the process. This document explains how to import a data source and create entity types. . Creating Entity Types from Data Source (RFC/BOR) Creating an entity type from a data source comprises three steps:
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 27 of 65
1. Importing the data source. 2. Selecting the parameters from the selected data source. 3. Editing the selected parameters. To create entity types from a data source, proceed as follows: 1. Logon to the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder appears. 3. Create a new project. For more information, see Creating a Service Builder Project. 4. Switch to edit mode. 5. Right click the Data Model folder, and select Import RFC/BOR Interface. . The Wizard 1 of 3: Create Entity Type from Data Source-Import Entity Type From Data Source screen of the wizard to guide you through the creation of entity types opens. 6. Do the following in the wizard: 1. Enter a name for the new entity type in the Entity Type Name field 2. Select either the Remote data source or the Local data source radio button in the Target System region. Remote : Select this option if the data source to fetch the properties resides in the remote system. On selecting this option the RFC Destination field is activated. Local : Select this option if the data source to fetch the properties resides in the local system. The RFC Destination field is not activated for Local option.
Note In cases when a model is created using the Import RFC/BOR function and later has to be transported to another system where the DDIC objects may not be available, it is recommended to create the model using the RFC destination as NONE. If the RFC destination is NONE, then no DDIC objects will be assigned to the entity type and the individual data element assignment to the properties (in the ABAP type editor) will not happen and local data types will be generated in the MPC. 3. For Remote Data Source, enter the parameters of the connection in the RFC Destination field. For example, TCP/IP or SAP connections. Alternatively, you can also use the input help available for this field. 4. Select the type of the data source from the Type field drop-down list. Select either Business Objects Repository or Remote Function Call to retrieve the properties of the entity type . 5. Depending on the selection in the Type field, enter the name of the data source in the Name field. Alternatively, you can also use the input help available for this field. 6. Choose Next to proceed.
Note If any entries are incorrect, an error message is displayed. If the validation check is successful, the Wizard Step 2 of 3: Create Entity Type from Data Source-Select Parameter(s) screen of the wizard appears. The Select Parameter(s) screen displays the structures/table types and their properties as shown in the images. 7. Expand the Data Source Parameter and select the required structures, tables types, and properties. Structures are imported into the Service Builder as complex types Tables types are imported into the Service Builder as new entity types Properties are defined for the entity type and complex type imported To remember during the selection of the properties: If the Target System is Local, and when you select a property without selecting its structure/table type, the property will be assigned with the corresponding data element. Whereas, if the Target System is Remote, then the data element assignment will not happen. If the Target System is Local, and when you select a property along with its structure/table type, then the DDIC structure is assigned to the Complex Type/Entity Type. Whereas, if the Target System is Remote, then the DDIC structure assignment will not happen.
Recommendation The new entity type if created with a structure assigned to it has the following advantages: Conversion exit routines are used automatically Labels are used from the DDIC In the DPC class, the RFC or BOR interface parameters with structure or table types can be directly assigned instead of using movecorresponding.
Note The parameters marked as mandatory are mandatory in the data source.
Note Unselected parameters can be selected later by using the Import below.
Properties
function as mentioned in the Importing Properties section
8. Select the check-box under Assign Structure to create additional artifacts. Complex types will be created if the parameter is a structure type and entity types will be created if the parameter is a table type. In addition, DDIC assignment will be retained for the newly created artifacts. If this check-box is not selected then all the properties will be created under one root as a flattened structure.
Note The parameters marked as mandatory are mandatory in the data source. End of the note. 9. Choose Next.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 28 of 65
9. Choose Next. The Wizard Step 3 of 3: Create Entity Type from Data Source-Modify Entity Type screen of the wizard opens. This screen provides the following editable and non-editable information: Name
Description
Edit Status
Is Entity
If the property belongs to the entity type, this check box is selected. If it is not selected, the property belongs to the complex type.
Non-Editable
Complex/Entity Type Name
This is the name of the property. It can either be a
Editable
complex type or entity type ABAP Name
This is the technical name. This will not be displayed in the metadata.
Non-Editable
Type
Type of property.
Non-Editable
Node Name
This is external name displayed in the metadata.
Editable
Is Key
Indicates whether the imported property is to be imported Editable as a key of the entity type. Each entity type must define at least one key property.
Label
This is the label for the properties which will be displayed in the metadata.
Editable
Note The check-box Create Default Entity Set will be selected by default if an entity type is chosen for creation. You can choose not to create entity sets by unselect this box. If there are no entity types then this will be disabled. All entity sets will be created with the suffix name Set. For example, If Entity type name is E1 then the default entity set name will be E1Set. End of the note. 10. Choose Finish. The selected data source parameters are imported into the Service Builder.
Figure 1: Selected data source parameters imported into the Service Builder
The new entity type you have created can also be assigned to a structure. The advantages of assigning a structure to the entity types are: Conversion exit routines are used automatically Labels are used from the DDIC In the DPC class, the RFC or BOR interface parameters with structure or table types can be directly assigned instead of using move-corresponding.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 29 of 65
You can also verify if the properties selected without their structures/table types are assigned with a data element.
Figure 2: Data Element automatically assigned
Note The Service Builder runs an OData compliance check. The appropriate information messages resulting from the check are displayed. Double click the message to repair the error. See Entity Types for editing the entity types in the mass edit view. 11. After fixing all the errors you can generate runtime objects. See Generating Runtime Objects for detailed instructions to generate a service. 12. After generating the runtime objects, you can proceed to register and then maintain the service in the configured Gateway hub systems. See Service Maintenance to maintain services.
Note If the model developed in a system where the import from RFC uses the target system as Local is transported to another system, and If an error occurs in the transported system due to the non availability of the DDIC objects in the target system, the DDIC assignments of the artifacts can be removed. Importing Properties There might be instances when some properties were not selected during a import of RFC/BOR Interface. In such cases, the Import properties function can be used to import more properties from the same data source.
Note Importing more properties is supported only for projects created in SAP NetWeaver Gateway 2.0 Support Package 6. This section will guide you to import more properties for the entity/complex types from the same data source that were created during an import of RFC/BOR. To import properties proceed as follows: 1. Right click on the entity type or on the complex type you have imported and select
Import
Properties
.
Figure 3: Entity Type-> Import-> Properties
The Wizard Step 1 of 2: Import Properties-Select Parameter(s) page appears. The properties that were already selected will be non-selectable, and the other properties can be selected. 2. Select the required properties and choose Next. The Wizard Step 2 of 2: Import Properties-Modify Entity Type page appears. The properties that were added are represented with the editable Name, Is Key and Label columns. 3. Click Finish to complete the import. The properties are now added to the selected entity or complex type.
1.5.4 Importing Search Help as a Data Source In the Service Builder, you can reuse existing Search Helps in a system, as data sources to create new entity types.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 30 of 65
Context Only the search helps in the local SAP system can be used as a data source. When you choose to use search helps as data sources, Service Builder allows you to do the following: Import the search help parameters Create OData model entities based on the imported search help parameters Map only the Query and Read operations for the model entities to their corresponding search help parameters. Generate and register the OData service. Importing Search Help Parameters You import search helps as data sources using the import wizard to create a new entity type, and a corresponding entity set into your project. When you import a search help as a data source, the tool performs the following: Checks that the search help you have specified exists, and that it is an elementary search help, and also returns the search help description. Builds the search help parameter that you specify, creates a result table, and range tables based on the logic described above. A max hits data element is provided automatically in Service Builder. To import search help parameters:
Procedure 1. In your project, right click the folder Data Model Import Search Help . 2. In the wizard page for creating an Entity Type, enter a name for the entity type, and Search Help is displayed in Data source type. An entity set is also created. 3. Enter the search help name you want as a data source. You can press F4 to find the search helps in your local system. 4. From the Results, choose the search help parameters you want to use in the data source and click Next. A search help data source contains the following: Result list: An output table that represents the runtime results in a list. It is a representation of the search help parameters. The table is a representation of the result list that users retrieve once they execute thesearch help. If the LPos value for a search help parameter is defined as greater than zero, or it has been selected (flagged) for EXPORT, that parameter is presented in the results list. The implemented logic relates to the search help definition in the data dictionary. Only entries in the result table are enabled. Range tables: Each range table represents a search help parameter in the dialog box for filtering values. Parameters with SPos values defined as greater than zero, or have been flagged for EXPORT, are presented. In the local system, if the SPos is zero, the parameter is not presented, as it does not have a corresponding representation of a range table. Max Hits: Restricts the number of entries in the list. 5. Set the property you want to use as key, and click Next to continue.
Next Steps Mapping Search Help Parameters You can map entity set properties to search helps. The procedures for mapping is the same for all data sources. Only the Query and Read operations can be mapped for entity sets derived from the search help data source. In addition, when mapping a search help to the Read operation, the related range table header of each key property must be mapped to the key. At runtime, the range table is set with the following values: SIGN = ‘I’, option = ‘EQ’, LOW = key value. When you map entity set properties to search help, the tool performs the following: Ensures that mapping can be performed only for Query and Read operations. Checks that the parameters imported into a project contain mapping information. In addition, it checks that the range table mapping semantic has not changed, for example, SIGN can only be mapped to the SIGN semantics, or to a constant value. Constraints The following are the constraints: Only elementary search helps are supported. Collective search helps are not supported. Search helps that call UI in their exit function are not supported, as this cannot be validated by the Service Builder. At runtime, a query operation that is based on a search help data source can retrieve a maximum of 9,999 entries.
Related Information Importing a Data Model Creating the Mapping
1.5.5 Including an OData Service Introduction Use When creating an association, there may be instances when you want to link to an existing model as opposed to recreating it. In such cases, you can use the Including OData Service function to include models in the Service Builder and then create associations using the included models.
Example
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 31 of 65
To create a sales order we require a list of customers and products. For the Sales Order service, two types of master data are required: Customer Product You can use the Include Model function since the Customer and Product services already exist and can be reused. Prerequisites The service of the external data model must exist on the SAP NetWeaver Gateway hub system and be up and running. Including the Model To include a model from a service, proceed as follows: 1. Logon to the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder appears. 3. Open an existing project to include a model from a service. 4. Switch to edit mode. 5. Right click on the Data Model folder and select Include OData (GW) Service from the context menu. The Include Model from Service window opens. 6. Do the following In the Include Model from Service window: 1. Case 1: Select the Service in Current System radio button if you want to include a service from the system in which you are working currently. 1. On selecting Service in the Current System option, the RFC Destination field is automatically disabled. 2. Enter the Technical Service Name of the service you want to include. Alternatively, you can also use the input help available for this field. On selecting the service from the input help window, the version of the service is automatically populated. If you enter the technical service name manually, you must specify the version. 2. Case 2: Select the Service in External System radio button if you want to include a service from any external system.
Note To include a model from an external system, the external system should be configured to SAP NetWeaver Gateway SP5 1. On selecting the Service in the External System option, the RFC Destination field is automatically enabled. 2. Enter the RFC Destination of the system in which the service you want to include resides. Alternatively, you can also use the input help available for this field. 3. Enter the Technical Service Name of the service you want to include. Alternatively, you can also use the input help available for this field. On selecting the service from the input help window, the version of the service is automatically populated. If you enter the technical service name manually, you must specify the version. 7. Choose Continue. The selected service is added and available under the Model References folder in the tree view.
Note To add further models, repeat the steps listed above. 8. Double-click the included model, which can be found under the project Folder maintenance view. The details of the referenced model are displayed in the mass maintenance view.
Data Model
Model References
to view it in the mass
Note The Model Reference Type displays Include, which indicates that the model was referenced by inclusion in Service Builder. 9. Save the project. Creating an External Association This section explains how to create an association between the entities of the model you have included. To create an external association proceed as follows: 1. 2. 3. 4.
Open the Service Builder. Expand the Data Model folder in the tree view of your project. Double-click the Association folder to open it in the mass maintenance view. Switch to edit mode.
5. Choose Edit and then Insert Row to create a new association. 6. Do the following to create an external association: 1. Enter a name for the new association in the Association Name field.
Note An error message displays if you do not enter a name for the association. 2. Click the External Association Editor button in the mass maintenance view. The term external association refers to creating an association between the entities of the model that has been included in the Service Builder.
Note You cannot make a selection until you have included a OData service. The Create External Association window displays. 3. Do the following in the Create External Association window: 1. Ensure External is selected in the Association Type field. The fields to enter the principal and dependent entity details are enabled.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 32 of 65
Note Depending on your requirements for the new association, you can enter either the details of the Principle Entity or Dependent Entity or both. However, you must make one entry. 2. If you want to add an entity from the included model as the dependent entity, proceed as follows in the Enter the details if Dependent Entity is from the Included Model area: Model Reference - Enter the model reference node name of the included model in the field. Alternatively use the input help to view and select the model reference node name. The input help displays the model reference node name of all the included models. On selecting the dependent entity, the Dependent Entity field in the mass maintenance view is populated with the entities of the selected model. RFC Destination for Metadata - Provide the RFC destination of the system where the metadata of the included model resides. This is required only for the models whose metadata will be available in an external system, for example if you include a Gateway service created from a Service Provider Interface (SPI) or a SAP BW Analytics service. 3. If you want to add an entity from the included model as the principal entity, proceed as follows in the Enter the details if Principal Entity is from the Included Model area: Model Reference - Enter the model reference node name of the included model in the field. Alternatively, use the input help to view and select the model reference node name. The input help displays the model reference node name of all the included models. On selecting the principal entity, the Principal Entity field in the mass maintenance view is populated with the entities of the selected model. RFC Destination for Metadata - Provide the RFC destination of the system in which the metadata of the included model resides. This is required only for the models whose metadata will be available in an external system, for example if you include a Gateway service created from an SPI or an Analytics service. 4. Choose Continue. The external association is completed and a checkmark appears on the External Association Editor button in the mass maintenance view.
Note You can now create referential constraints, association sets and navigation properties for this association. See Navigation Properties, Referential Constraints, Association Sets The mass maintenance view displays the following fields: Fields
Description
Association Name
Enter a name for the new association in this field.
Note An error message displays if you do not enter a name for the association.
External Association
Click to create an external association. The term external association refers to creating an association with the entities of the model that has been included in the Service Builder.
Principal Entity
Enter the name of the principal entity, the entity which is being considered for the From Role in the new association. For an external association, if an included model is selected as a principal entity (refer to the Creating External Association step above), then the input help will also display the entities of the included model.
Principle Entity Cardinality
Select a cardinality for the principal entity from the drop-down list
Dependent Entity
Enter the name of the dependent entity, the entity which is being considered for the To Role in the new association. For an external association, if an included model is selected as a dependent entity (refer to the Creating External Association step above), then the input help will also display the entities of the included model.
Dependent Entity Cardinality
Select a cardinality of the dependent entity from the drop-down list
Label
Enter a label for the new association. This label is displayed as the label when the service is consumed.
Label Text Reference Editor
To define the label, use the Label Text Reference Editor. The Label Text Reference Editor enables you to enter the reference type.
7. You can now generate the service. Modifying the External Association To modify an external association, proceed as follows: 1. Choose External Association button for the association with an external association. 2. Make the required changes. 3. Choose Continue. Deleting an External Association To delete an external association, proceed as follows: 1. Choose the External Association button for the association with an external association. 2. Select the blank entry in the Association Type field. 3. Choose Continue. The check mark on the External Association button is removed.
More Information For more information, see Generating Runtime Objects.
1.6 Redefining Services PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 33 of 65
Use The Service Builder allows you to redefine both OData services created using SAP NetWeaver Gateway and the external services (SPI, BW Query, GenIL) that have been created using different frameworks.
More Information See Redefining OData Service (GW) to redefine OData services. See Redefining Services from External Framework (SPI, BW Query, GenI for redefining services of different frameworks.
1.6.1 Extending an OData Service Using Service Builder Extend the OData services by customizing the generated source code using "Redefine" functionality in the SAP NetWeaver Gateway Service Builder (Service Builder-transaction SEGW) Generated Model Provider Classes- An Overview When redefining a service, a new OData service generates a new Model Provider Class (MPC), and a new Data Provider Class (DPC). The MPC includes the MPC of the source service, and the DPC inherits the DPC of the source service. The image below depicts the dependency between the classes:
In the illustration above, two sets of classes (MPC A, and DPC A) are generated for the source service A, and another set of classes (MPC B, and DPC B) are generated for the target service B. While the model represented by MPC A is included in the MPC B for the redefined service, the DPC generated for the target service is inherited from the DPC of the source service, ( DPC_EXT B inherits from DPC B, which also inherits from DPC_EXT A ). The model in the redefined service can be further enhanced in the extension class of the extended service ( MPC_EXT B ). The runtime behavior of the newly added properties, entities, function imports and associations can be handled in the data provider extension class of the extended service ( DPC_EXT B ). Use Cases for Redefining Services This section will explain the extensibility functionality based on specific use cases and an example. In the base service ( ZSALES_ORDER_EXAMPLE_SRV) , there are three entity types SalesOrder, SalesOrderItems and SalesOrderProvider and an association SalesOrderSalesOrderItems. This service will be redefined and the new properties and entity types will be added in the redefined service. Use case 1: Adding a new property to an existing entity Use case 2: Adding a new entity Use case 3: Adding a new Function import Use case 4: Adding an association and a navigation property In the description of the use cases, we refer to the following example service, ZSALES_ORDER_EXAMPLE, which contains two entity sets: SalesOrderSet SalesOrderItemSet SalesOrderProviderSet For our example, you will extend the source service by creating a new project, ZEXTEND_SALES_ORDER_EXAMPLE following these steps: 1. Create a new project ZEXTEND_SALES_ORDER_EXAMPLE which is referred to as the target service. See Creating a Service Builder Project for reference. 2. Right click on the Data Model folder and select Redefine OData Service (GW) option from the context menu. The Wizard Step 1 of 2: Redefine Service appears. 3. In the Select Service region, enter the technical name of the service you wish to redefine in the Technical Service Name field. Alternatively, you can also use the input help available for this field.
Note If the metatdata of the selected service resides in another system, then select Metadata to be fetched from an external system. in the Target System for Metadata. On selection of the Metadata to be fetched from an external system the RFC Destination field becomes editable to select the RFC destination of the external system. Input help is also available for this field.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 34 of 65
4. Click Next to continue. The Wizard Step 2 of 2: Redefine Service opens. 5. Select the required artifacts and click finish. See Redefining OData Service (GW) to understand the artifacts selection logic. Refer Redefining Services cook book for pictorial explaination.
Use Case 1: Adding a New Property to an Existing Entity The required process for adding a new property to your target service, ZEXTEND_SALES_ORDER_EXAMPLE, depends on how the service is implemented. In the sections that follow, you will find explanations for the following: Service implemented with MOVE command and entity bound to DDIC structure Entity bound to a DDIC structure Do the following to identify if the entity is bound by the DDIC structure: 1. Open the Entity Type to check if it has the ABAP Structure Type Name assigned to it. OR Open the Define_ Entity Name Method in either the _MPC_EXT or _MPC from the Runtime Artifacts folder and check if the following code snippet is available. lo_entity_type->bind_structure( iv_structure_name = 'SFLIGHT' iv_bind_conversions = 'X' ). "#EC NOTEXT Entity not bound to a DDIC structure Service implemented with MOVE command and entity bound to DDIC structure The section describes the process for extending an entity in a model that is connected to a Data Dictionary (DDIC) structure. When the connected DDIC structure matches the data source structure (or its attributes by name), and the service has been implemented using the MOVE command, (either single MOVE, or MOVE-CORRESPONDING) to assign a value to ER_ENTITY, it will be sufficient to extend the DDIC structure, and to extend the model as described in steps 1 to 3 of the section The Entity in the Data Model is connected to a Data Dictionary Structure without changing the code. Below is an example code for the entity set, SALES_ORDER_ITEM Get Entity, where the MOVE command is used,(MOVE ls_et_order_item TO er_entity, to fill the er_entity; once the structure is extended, it is automatically moved in the code. METHOD salesorderitemss_get_entity. *------------------------------------------------------------*Data declaration *------------------------------------------------------------DATA lv_sales_order_id TYPE zif_zsales_order_get=>char25. DATA lv_sales_order_item TYPE zif_zsales_order_get=>char25.DATA et_order_item TYPE zif_zsales_order_get=>zsales_o rder_item_table. DATA ls_et_order_item TYPE LINE OF zif_zsales_order_get=>zsales_order_item_table DATA ls_converted_keys LIKE er_entity. DATA lv_source_entity_set_name TYPE string. *------------------------------------------------------------*Map the runtime request to the RFC - Only mapped attributes *------------------------------------------------------------*Get all input information from the technical request context object io_tech_request_context->get_converted_keys( IMPORTING es_key_values = ls_converted_keys ). *Maps key fields to function module parameters lv_source_entity_set_name = io_tech_request_context->get_source_entity_set_name( ). lv_sales_order_item = ls_converted_keys-salesorderitempos. lv_sales_order_id = ls_converted_keys-salesorderid. *------------------------------------------------------------*Call RFC function module *------------------------------------------------------------TRY. CALL FUNCTION 'ZSALES_ORDER_GET' EXPORTING iv_sales_order_item = iv_sales_order_item iv_sales_order_id = iv_sales_order_id IMPORTING et_order_item = et_order_item EXCEPTIONS system_failure = 1000 message lv_exc_msg OTHERS = 1002. *-------------------------------------------------------------------------* * - Post Backend Call *-------------------------------------------------------------------------* * Map properties from the backend to the Gateway output response structure * In GetEntity operation, we support only read for the first entry in the response table READ TABLE et_order_item INTO ls_et_order_item INDEX 1. MOVE ls_et_order_item TO er_entity. ENDMETHOD. Ensure that, the new property (ABAP field name) name is the same as the name of the data source attribute.
Note If the service has not been implemented using the MOVE or MOVE-CORRESPONDING commands, the DPC (extension class) of the extended service has to be redefined to provide the runtime data for the newly added properties.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 35 of 65
Entity bound to a DDIC structure You enhance the structure by adding a new attribute to the DDIC structure. For the new attribute, you must create a new property in the specific entity of the model. Prerequisites: The DDIC can be enhanced. Do the following to extend an entity in a model that is connected to a DDIC structure: 1. Follow these steps to add a new field to the DDIC structure 1. Enter the transaction SE11, and choose Data Type , and then enter the name of the structure you want to enhance 2. Click Display . In our example, the structure is, ZSALES_ORDER_ITEM 3. In the Dictionary: Maintain Structure screen, click GoTo in the menu bar, and select Append Structure (F5) to create the append structure with the additional fields. If you have already appended to the structure you can extend it. For example, we created an append structure called, ZVALUE , and added fields NETVALUE and CURRENCY , to it. 4. When you add the fields to the structure, rename the fields using your own suffix or prefix to prevent naming conflicts. 5. Add a new property for the new field to the entity of the model in the service builder. In the target service, add the new property to entity of the model and save it. In our example, we added the fields, NetValue and Currency, to the entity type, SALESORDER. 6. Save and generate the project for the target service. The new classes of the target service are generated. 7. To change the implementation in DPC, update the code for the methods of the specific extended entity in the DPC (extension) class for the target service, ZEXTEND_SALES_ORDER_EXAMPLE. To update the methods, you can use one of the following options: Redefine the methods for the Create, Read, Update, Delete, Query (CRUDQ) operations of the specific Entity. Copy the code from the original method and update it by providing the additional fields. Call the super class and add the additional fields in your code. If the service has been implemented using SAP tools, such as, Explicit Enhancement Point or BADI, you can use it instead of redefining the class method.
Note Conversion Exits work without any code change for the newly added properties. Entity not Bound to a DDIC Structure The following is the process for extending an entity in a model that is not connected to a DDIC structure: 1. Add a new property to the entity type and generate the service, ZEXTEND_SALES_ORDER_EXAMPLE. In our example, we added a new property, Supplier, to the entity type, SALESORDER. 2. Redefine the dispatching methods (methods that route to the type CRUDQ methods) of the operations: 3. Open the DPC extension class of the target service, ZEXTEND_SALES_ORDER_EXAMPLE, and redefine the dispatching methods for Create, Read, Update, and Query (CRUQ) operations for the extended entity: /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITY /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_ENTITY /IWBEP/IF_MGW_APPL_SRV_RUNTIME~UPDATE_ENTITY /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET 4. For the dispatching method of each operation, enhance the code for the extended entity set and call the super method for all other entities. Optional: To be consistent with SAP development, follow the next step and build the typed methods, and in the dispatching method route to the typed methods 1. Copy the typed methods for the CRUDQ operations that have been assigned to the entity set you want to extend. 2. Example of method names for the operations: Provide a new name, by adding a suffix or prefix, such as, _EXT. In the example, we copied the methods in the source service, ZSALES_ORDER_EXAMPLE, to the new methods in the target service, and added the suffix, _EXT. 3. Update the method interfaces with the model provider class (MPC extension) types in your new project. 4. Once you have the new methods, you can update their interfaces.
Note The new methods are not inherited; therefore you can update their interfaces. For each method, copy the type structure in the MPC extension class of the source service, ZSALES_ORDER_EXAMPLE, and replace the type structure in the MPC extension class in the target service, ZEXTEND_SALES_ORDER_EXAMPLE. Make changes to the methods of the operations as follows: 1. Change type of ER_ENTITY in CREATE operation: In the source service, ZSALES_ORDER_EXAMPLE, the MPC extension class displays, ZCL_ZSALES_ORDER_EXAMP_MPC=>TS_SALESORDER. In the target service, ZEXTEND_SALES_ORDER_EXAMPLE, edit the MPC extension class to,ZCL_ZEXTEND_SALES_ORDE_MPC=>TS_SALESORDER. 2. DELETE operation: No changes are required for this operation. 3. Change type of ER_ENTITY in READ (GET_ENTITY) operation. In the source service, ZSALES_ORDER_EXAMPLE, the MPC extension class displays as, ZCL_ZSALES_ORDER_EXAMP_MPC=>TS_SALESORDER. In the target service, ZEXTEND_SALES_ORDER_EXAMPLE, edit the MPC extension class to,ZCL_ZEXTEND_SALES_ORDE_MPC=>TS_SALESORDER. 4. Change type of ER_ENTITYSET in QUERY (GET_ENTITYSET) operation. In the source service, ZSALES_ORDER_EXAMPLE, the MPC extension class displays as, ZCL_ZSALES_ORDER_EXAMP_MPC=>TT\_SALESORDER. In the target service, ZEXTEND_SALES_ORDER_EXAMPLE, edit the MPC extension class to,ZCL_ZEXTEND_SALES_ORDE_MPC=>TT_SALESORDER. 5. Change type of ER_ENTITY in UPDATE operation. In the source service, ZSALES_ORDER_EXAMPLE, the MPC extension class displays as, ZCL_ZSALES_ORDER_EXAMP_MPC=>TT_SALESORDER. In the target service, ZEXTEND_SALES_ORDER_EXAMPLE, edit the MPC extension class to,ZCL_ZEXTEND_SALES_ORDE_MPC=>TT_SALESORDER. 6. Update the code in the methods, and provide the additional fields. You have two main options to update the code. The option you choose depends on the logic you want to implement: 1. Call the original method of the entity operation; and then provide the code for the additional field.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 36 of 65
2. Copy the code for the method of the specific Entity Set, and the specific operation, from the original method; and update the code for the additional fields. If you choose to implement the first option, you will be using SAP code with your own code for the additional fields. The disadvantage is that, it you may call the backend twice; once for the SAP provided fields, and then again for the additional fields. Redefine the Dispatching Methods The next process is to redefine each dispatching method in the DPC (extension) class. There are typed methods with MPC type, and dispatching methods. At runtime the dispatching methods, one method per each CRUDQ operation, are called with a generic interface that dispatches the call to specific typed methods. The specific call is based on the Entity Set name. In each dispatch method, verify that the specific entity is the extended entity, and then route the entity to the new methods, if not, route it to a super dispatching method. Below is an example code for Get Entity: METHOD /iwbep/if_mgw_appl_srv_runtime~get_entity. DATA salesorderset_get_entityset TYPE zcl_zextend_sales_orde_mpc=>ts_salesorder. DATA lv_entityset_name TYPE string. DATA lr_entity TYPE REF TO data. lv_entityset_name = io_tech_request_context->get_entity_set_name( ). CASE lv_entityset_name. *------------------------------------------------------------------------- * * EntitySet - SalesOrderSet *------------------------------------------------------------------------* WHEN 'SalesOrderSet'. * Call the entity set generated method salesorderset_get_ent_ext( EXPORTING iv_entity_name = iv_entity_name iv_entity_set_name = iv_entity_set_name iv_source_name = iv_source_name it_key_tab = it_key_tab it_navigation_path = it_navigation_path io_tech_request_context = io_tech_request_context IMPORTING er_entity = salesorderset_get_entityset ). IF salesorderset_get_entityset IS NOT INITIAL. * Send specific entity data to the caller interface copy_data_to_ref( EXPORTING is_data = salesorderset_get_entityset CHANGING cr_data = er_entity ). ELSE. * In case of initial values - unbind the entity reference er_entity = lr_entity. ENDIF. *-------------------------------------------------------------------------* * Other enteties => call SAP model *------------------------------------------------------------------------WHEN OTHERS. TRY. CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entity EXPORTING iv_entity_name = iv_entity_name iv_entity_set_name = iv_entity_set_name iv_source_name = iv_source_name it_key_tab = it_key_tab it_navigation_path = it_navigation_path io_tech_request_context = io_tech_request_context IMPORTING er_entity = er_entity. CATCH /iwbep/cx_mgw_busi_exception. * todo CATCH /iwbep/cx_mgw_tech_exception. * todo ENDTRY. ENDCASE. ENDMETHOD.
Use Case 2: Adding a New Entity The following are the processes for adding a new entity to extend the OData service: 1. In your target service, ZEXTEND_SALES_ORDER_EXAMPLE, create and add the new entity (Products), and then generate the project. 2. Manually create new methods for the CRUDQ operations you require for the newly created entity. You can copy existing methods generated for another entity and use it to update your new entity, and add the relevant code.
3. Make sure to change the Associated type of the Method Parameters of the newly created methods.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 37 of 65
4. Redefine the dispatching method. The dispatching methods are inherited from the DPC source service, and these methods do not recognize the new entity; therefore you must redefine these methods in your target service. METHOD /iwbep/if_mgw_appl_srv_runtime~get_entityset. DATA productsset TYPE zcl_zextend_sales_orde_mpc=>tt_products. DATA lv_entityset_name TYPE string. DATA lr_entity TYPE REF TO data. lv_entityset_name = io_tech_request_context->get_entity_set_name( ). CASE lv_entityset_name. *------------------------------------------------------------------------- * * entityset - productsset *------------------------------------------------------------------------WHEN 'ProductsSet'. * call the entity set generated method productsset_get_entityset( EXPORTING iv_entity_name = iv_entity_name iv_entity_set_name = iv_entity_set_name iv_source_name = iv_source_name it_filter_select_options = it_filter_select_options it_order = it_order is_paging = is_paging it_key_tab = it_key_tab it_navigation_path = it_navigation_path iv_filter_string = iv_filter_string iv_search_string = iv_search_string io_tech_request_context = io_tech_request_context IMPORTING et_entityset = productsset ). IF productsset IS NOT INITIAL. copy_data_to_ref( EXPORTING is_data = productsset CHANGING cr_data = er_entityset ). ELSE. * in case of initial values ENDIF. WHEN OTHERS. TRY. CALL METHOD super->/iwbep/if_mgw_appl_srv_runtime~get_entityset EXPORTING iv_entity_name = iv_entity_name iv_entity_set_name = iv_entity_set_name iv_source_name = iv_source_name it_filter_select_options = it_filter_select_options it_order = it_order is_paging = is_paging it_key_tab = it_key_tab it_navigation_path = it_navigation_path iv_filter_string = iv_filter_string iv_search_string = iv_search_string io_tech_request_context = io_tech_request_context IMPORTING er_entityset = er_entityset. CATCH /iwbep/cx_mgw_busi_exception. * todo CATCH /iwbep/cx_mgw_tech_exception. * todo ENDTRY. ENDCASE.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 38 of 65
ENDMETHOD.
Use Case 3: Adding a New Function Import The following are the enhancement processes for extending an OData service by adding a new function import to the data model: 1. Add a new function import into the model. 2. Manually redefine the function import method,EXEC_SERVICE_OPERATION>, and write your own code for the newly added function import and call the super class EXEC_SERVICE_OPERATION> method for the function imports inherited from the base service
Use Case 4: Adding an Association and a Navigation Property The following are the enhancement processes for extending an OData service by adding an association and a navigation property: 1. In the target service, add the new association, navigation property, and referential constraint to the data model. 2. Update the code in the query and read operations of the target entity.
Boundary Conditions The following are the enhancement processes for extending an OData service by adding a new function import to the data model: 1. 2. 3. 4. 5. 6.
In the redefined service, RFC mapping editor cannot be used for DPC generation. If your entity is bound to a structure in the base service, it should not be bound to the new structure in the redefined service. Redefining a composed service is not supported. DIC binding is not supported when the Backend system is different from the IW_BEP & IW_FND system. If an entity is bound to a DDIC structure, the abap type of the property cannot be modified from the ABAP type editor in SEGW. Redefining a service from another BEP system is not supported.
Related Information Function Imports Redefining OData Service (GW) Creating a Service Builder Project Defining Properties Associations
1.6.2 Redefining OData Service (GW) Overview Use The Service Builder allows you to redefine the OData services for SAP NetWeaver Gateway. The Redefine Gateway Service function allows the user to do the following: Redefine a service - Select this option if you want to redefine a service for the first time in the Service Builder. Extend the existing model - Select this option if you wish to add more artifacts to your model from an existing model. If your model already has artifacts from a reference model, you can add more artifacts from this model only. Overwrite existing model - Select this option to overwrite the existing model in the Service Builder with a new model from a different service. After choosing one of the redefinition options, the user is provided with options to select the relevant service he or she wants to redefine (only those services that are registered in the current SAP Business Suite backend system can be selected). After the service has been selected, the model is displayed in a tree view allowing the user to select the required artifacts (entity types, associations, function imports) for the new model. The Modification Generator enables the user to make certain restricted changes in the services created using an external framework like SAP Business Information Warehouse (BW), Service Provider Interface (SPI), and Generic Interaction Layer (GenIL). For example, these services might not have a proper label or might not need all the artifacts. In these cases, the Modification Generator enables the user to make cosmetic changes without influencing the underlying data provider class, and reuses the existing model. To redefine a service for the first time, proceed as follows - Empty project: When you select the Redefine option for an empty project, you will be provided with a redefine wizard that allows you to specify a model of your preference. 1. Log onto the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Open an existing project you want to redefine. 4. Choose Edit to switch to editing mode. 5. Right-click on the Data Model folder and in the resulting submenu, select Redefine OData Service (GW) The Wizard Step 1 of 2: Redefine Service wizard appears. 6. In the Select Service region, enter the technical name of the service you wish to redefine in the Technical Service Name field. Alternatively, you can also use the input help available for this field. 7. On selecting the service from the input help window, the version of the service is automatically populated.
Note If you enter the technical service name manually, you must specify the version. 8. If the metadata of the selected service resides in another system, select Metadata to be fetched from an external system. in the Target System for Metadata. 9. On the selection of the Metadata to be fetched from an external system the RFC Destination field becomes editable to select the RFC destination of
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 39 of 65
the external system using the input help. 10. Click Next to continue.
Note If the RFC destination is incorrect, an error message is displayed. 11. On successful validation of the RFC destination, the Wizard Step 2 of 2: Redefine Service opens. 12. Select the required artifacts. Refer to the artifacts selection logic described in the " To Overwrite a model " section. 13. Follow steps 14 to 19 in the To Overwrite a model section to complete the procedure.
Note Since the Wizard Step 2 of 2: Redefine Service is same for all the redefinition scenarios, these steps (14 to 19) are only mentioned in the "To Overwrite a model, proceed as follows" section. To redefine a service for the first time, proceed as follows - Project with a model: When you select redefine option for a project with an existing model created by methods other than redefine, for example, by importing a data model, importing a data source or hand craft a model in the Service Builder, you will be provided with the option to overwrite the existing model. On choosing to overwrite, the existing model and the generated classes will be overwritten. 1. Log onto the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Open an existing project you want to redefine. 4. Choose Edit to switch to editing mode. 5. Right-click on the Data Model folder and in the resulting submenu, select
Redefine
OData Service (GW)
.
Note A message box is displayed in which you are prompted to confirm whether you want to overwrite an existing model 6. Choose Yes to overwrite the existing model and No to cancel. 7. On choosing Yes, the Wizard Step 1 of 2: Redefine Service wizard is displayed. 8. Enter the technical name of the service you wish to redefine in the Technical Service Name. Alternatively, you can also use the input help available for this field. 9. On selecting the service from the input help window, the version of the service is automatically populated.
Note If you enter the technical service name manually, you must specify the version. 10. If the metadata of the selected service resides in another system, select Metadata to be fetched from an external system. in the Target System for Metadata. 11. On the selection of the Metadata to be fetched from an external system the RFC Destination field becomes editable to select the RFC destination of the external system using the input help. 12. Click Next to continue.
Note If the RFC destination is incorrect, an error message is displayed. 13. On successful validation of the RFC destination, the Wizard Step 2 of 2: Redefine Service opens. 14. Select the required artifacts. Refer to the artifacts selection logic described in the To Overwrite a model section. 15. Follow steps 14 to 19 in the To Overwrite a model section below to complete the procedure. To Extend the existing model, proceed as follows: After you have added the artifacts for your service in the Service Builder, there might be instances when you would want to add more artifacts without overwriting the model. In such cases, you can use the Extend Current Model option and select the artifacts from the model that was redefined. In such cases, the Technical Service Name field in the Select Service region is read-only and displays the specific service from which you can add more artifacts. 1. Log onto the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Open an existing project to be redefined. 4. Choose Edit to switch to editing mode. 5. Right-click on the Data Model folder and in the resulting submenu, select Redefine Service Gateway Service The Wizard Step 1 of 2: Redefine Service wizard opens. 6. Select the Extend current model radio button. The Technical Service Name field in the Select Service region displays the source model's technical service name and the version. This field is readonly. 7. If the metadata of the selected service resides in another system, select Metadata to be fetched from an external system. in the Target System for Metadata. 8. On the selection of the Metadata to be fetched from an external system the RFC Destination field becomes editable to select the RFC destination of the external system using the input help. 9. Choose Next to continue.
Note If the RFC destination is incorrect, an error message is displayed.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 40 of 65
10. On successful validation of the RFC destination, the Wizard Step 2 of 2: Redefine Service opens.
Note The artifacts that were already selected will be read-only. 11. Select the required artifacts. Refer to the artifacts selection logic described in the To Overwrite a model section. 12. Add more artifacts as required and choose Finish. The added artifacts are displayed in the tree view under the appropriate folder. 13. Follow steps 14 to 19 in the To Overwrite a model section below to proceed. To Overwrite a model, proceed as follows: If you want to overwrite an existing model you can use the overwrite the existing model option. On choosing to overwrite, the existing model and the generated classes will be overwritten. 1. Log onto the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Open an existing project that you want to redefine. 4. Choose Edit to switch to editing mode. 5. Right-click on the Data Model folder and in the resulting submenu, select Redefine Service Gateway Service The Wizard Step 1 of 2: Redefine Service wizard opens. 6. Select the Overwrite model radio button to select and add more artifacts from a different model. This action overwrites the existing model. 7. Enter the technical name of the service you want to redefine in the Technical Service Name. Alternatively, you can also use the input help available for this field. 8. On selecting the service from the input help window, the version of the service is automatically populated.
Note If you enter the technical service name manually, you must specify the version. 9. If the metadata of the selected service resides in another system, select Metadata to be fetched from an external system in the Target System for Metadata. 10. On the selection of the Metadata to be fetched from an external system the RFC Destination field becomes editable to select the RFC destination of the external system using the input help. 11. Click Next to continue.
Note If the RFC destination is incorrect, an error message is displayed. 12. On successful validation of the RFC destination, the Wizard Step 2 of 2: Redefine Service opens. 13. Select the required artifacts. There is a selection logic in the backend, which automatically includes all the entity types that are end types/return type of chosen association/function import. The reverse is not selected. For example, consider the following model:
Example COMPLEX TYPES complex_type_1 complex_type_2 ENTITY TYPES entity_type_1 entity_type_2 entity_type_3 ASSOCIATIONS association_1 (between Entity_type_1 & Entity_type_2) association_2 (between Entity_type_1 & Entity_type_3) FUNCTION IMPORTS function_import_1 Case1: User selects Entity_Type_1, Entity_Type_2 and Association_1. All these entities are selected and used in the new model. If Entity_Type_1 & Entity_Type_2 uses Complex_Type_1 & Complex_Type_2, they are automatically selected. Case2: User selects Entity_Type_1, Association_2. Since Entity_Type_3 is part of the Association_2, Entity_Type_3 is selected automatically along with Entity_Type_1 and Association_2. 14. Choose Finish after you have made the relevant selections. 15. The Service Builder performs the consistency check of the imported model and a message is displayed. The selected artifacts are then transferred to the respective folders in the tree view of the Service Builder. Also, an entry with the name and the version of the service selected for redefinition is created under the Model Reference folder in the Service Builder. 16. Double-click the referenced model and the mass maintenance view displays Model Reference Type as Extend to indicate that this model can be extended.
Note If the model has been referenced as an Include, the model reference type displayed is Include instead of Extend. 17. You can perform the following redefinitions for the model imported: Delete the artifacts. Change the Node Names and Labels. 1. Switch to edit mode.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 41 of 65
2. Choose the Redefine Attribute button. The Node Name and the Label fields can be edited. 3. Choose the Undo Redefinition button to revert the redefined value to the original value. 4. Choose the Undo Identical Redefinition button to view the fields which have been reverted to their original values in the course of editing.
Caution During redefinition of a service, changes to the external name and labels are allowed, but deleting a label is not supported. In case if you delete a label, the following will be the impact. Metadata will not reflect the deletion and will still show the label. There will be issues in the assignment of text keys to labels in the generated MPC, which will lead to incorrect label settings for other artifacts. 18. After you have completed the redefinition process, you can generate runtime objects.
Note Generation of MPC: Case1: Re-using existing service - During the generation process a new model needs to be created that includes an model provider class (MPC). This MPC uses the extend_model( ) API and refers to the original model. After the new model has been created, it should be related to the old service. Since the original service has been modified, the service registration for this service on the hub has to be deleted and the service has to be registered again to reflect the changes. See Activate and Maintain Services for more information. Case2: Create a new service - A new service and a new model will be created and registered during the generation process. See Generating Runtime Objects for more information. 19. After the service has been generated, the MPC classes are stored in the Runtime Artifacts folder.
More Information See Redefining Services from External Framework (SPI, BW Query, GenI See Generating Runtime Objects See Service Maintenance
1.6.3 Redefining Services from External Framework (SPI, BW Query, GenIL) Introduction Use The Service Builder allows you to create a service and model from different external frameworks (integration topics) and redefine the service and model without having to navigate to a different transaction. This function comprises three steps: Specify the parameters for the selected external framework Generate the service Redefine the service Redefining Services The Service Builder allows you to redefine services from the following external frameworks: Service Provider Interface (SPI) SAP Business Information Warehouse (BW) Generic Interaction Layer (GenIL) A separate plug-in for each framework provides a wizard to create services starting from framework-specific data. Since these plug-ins belong to different software components they might not be available in every system.
Note Based on the component installed in your system, the relevant context menu is displayed. If software component IW_SPI is installed in your system, Create from SPI is displayed in the context menu. If software component IW_GIL is installed in your system, Create from GenIL is displayed in the context menu. If software component IW_BEP is installed in your system, BW Query Service is displayed in the context menu. To redefine services from an external framework, proceed as follows: 1. Logon to the SAP Business Suite backend system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Create an empty project. For more information, see Creating a Service Builder Project. 4. Switch to edit mode. 5. Right-click the project folder and select Redefine SPI Service, BW Query Service or GenIL Service Depending on the external framework you select, the appropriate framework-specific screen is displayed. More information is provided below. Service Generator for SPI Service The following screen opens for the Redefine SPI Service .
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 42 of 65
Figure 1: Wizard Step 1 of 3: Redefine Service-> Service Generator for SPI Service
1. Do the following in the Wizard Step 1 of 3: Redefine Service screen: 1. Enter the RFC Destination of the SPI system. Alternatively, you can use the input help available for this field. 2. Enter the Application Building Block ID for which you want to generate the SAP NetWeaver Gateway service. For example, EAMS_OBJK. Alternatively, you can use the input help available for this field. 3. Select the Generate Metadata Specific to Application to generate metadata specifically for this application. If this indicator is set, DEFINE Method of Generated Model Provider Class is redefined and the model is defined in this generated method. Otherwise, the generic metadata provisioning options are used to obtain the metadata. 4. Choose Next. Service Generator for BW Query Service The following screen opens for the Create Service from the BW Query service framework:
Figure 2: Wizard Step 1 of 3: Redefine Service-> Service Generator for BW Query Service
1. Enter the Access Type, RFC Destination, Catalog Name, and Query Name for the BW Query service. Alternatively, use the input help available for these fields. 2. Choose Next. Service Generator for GenIL Service The following screen opens for the Create Service from GenIL scenario:
Figure 3: Wizard Step 1 of 3: Redefine Service-> Service Generator for GenIL Service
1. Enter the GenIL Component for the service you wish to create. Alternatively, use the input help available for this field. 2. Choose Next. 6. On clicking Next in all the above scenarios, the Wizard Step 2 of 3: Redefine Service opens.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 43 of 65
Figure 4: Wizard Step 2 of 3: Redefine Service-> Transport Attributes page
The screen displays the following fields. You must make an entry in each of the fields to proceed to the next step of the wizard: Fields
Description
Package
Enter the target package name. This is the package in which the generated model provider class and data provider class will be stored.
Transport Request
Enter a valid transport request number.
Model Provider Class
Enter a name for the model provider class to be created. For example, ZCL_MPC_SPI_SAMPLE.
Data Provider Class
Enter a name for the data provider class to be created. For example, ZCL_DPC_SPI_SAMPLE.
Model Name, Version and Description
Enter a unique model name. For example, ZMO_SPI_SAMPLE. Enter '1' for version in the corresponding text box. Enter a description. This is a mandatory field and you will not be able to proceed without entering a description.
Service Name, Version and Description
Enter a unique service name. For example, ZSV_SPI_SAMPLE. Enter '1' for version in the corresponding text box. Enter a description. This is a mandatory field and you will not be able to proceed without entering a description.
7. Choose Next. The Wizard Step 3 of 3: Redefine Service opens. This screen shows all the artifacts generated in a selectable tree. 8. Select the required artifacts.
Note Choose
to view any existing messages for the service.
9. Choose Finish. The Service Builder runs the consistency check for the imported model and a message is displayed. The selected artifacts are transferred to the respective folders in the tree view of the Service Builder. Also, the name and the version of the service selected for redefinition are displayed in the Model References folder.
More Information See Redefining OData Service (GW) See Generating Runtime Objects See Service Maintenance
1.7 Service Implementation Use The Service Implementation contains the references to the operations and the methods for the service. It is a sub tree containing the runtime aspects of the service as reflected in the Data Provider Class. The sub tree consists of the following: The actual name of an entity set object that already exists in the Entity Set folder under the data model folder of the project. You cannot edit, add, delete, or change any actual entity set contained in this Entity Set folder, as it is reflected from the data model folder. Right click the folder to do the following:
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 44 of 65
Display Switches between the ready-only and edit mode for the Service Builder. Change Switches between the ready-only and edit mode for the Service Builder. Details The Service Entity Set table displays in the view on the right hand side. The table displays the names of the entity set as defined in the data model folder and the Service Implementation folder. In addition, the selected entity set expands to display the default set of operations. Each entity set object contains a default set of CRUD and query operations. The following are the operations: Create GetEntity (Read) GetEntitySet (Query) Update Delete You can select and right click an operation related to an entity set to do the following: Display: Switches between the ready-only and edit mode for the Service Builder Change: Switches between the ready-only and edit mode for the Service Builder. Map to Data Source: Opens the Map to Data Source dialog in which you map the selected operation to a data source. Go to Implementation: Opens the Class Builder to display the selected method. Details: Specifies the detailed properties of the selected operation, such as, the operation name, data source group, type and name, implementation class and methods. Double click the Service Implementation folder to expand or collapse it. Right click the folder to do the following: Display: Switches between the ready-only and edit mode for the Service Builder. Change: Switches between the ready-only and edit mode for the Service Builder. Check Consistency: Checks the folder for errors. Details: Specifies the detailed properties of the selected operation, such as, the operation name, data source group, type and name, implementation class and methods.
More Information Creating the ABAP Classes and Registering the Service Mapping to a Data Source
1.7.1 Redefining Methods of the Operations Procedure The Service Builder enables you to redefine the methods generated for the extension class of the DPC. For each entity set under the Service Implementation folder, you can find the methods for the operations. There is one method for each of the following operations; create, read, update, delete (CRUD), and query. You can select the method related to the operation of an entity set to view its implementation or to redefine it. You can redefine a method using one of the following: Add your code to the existing code, remove asterisks from the existing code, save and activate the class. Remove existing code, add your own code, then save and activate your class. To redefine the method for an operation: 1. Expand the Service Implementation folder to display its entity sets. 2. Expand an entity set to display the methods for the operations. Change to edit mode to able to edit the code you want. Right click a method and choose Go to Implementation . If the selected method has already been redefined, it is presented in the display mode in the transaction SE24. If the method has not been redefined a message displays and a list of methods is presented in the display mode in the transaction SE24. 3. Save the project.
Caution Changes you make in the data model, such as, renaming, removing of entity sets and attributes of entity types, which have been referenced in your code, can result in syntax errors in your implementation. If no implementation exists for the selected method in the extension class for the Data Provider Class, the Service Builder opens the standard Class Builder screen (transaction SE24). If the selected method has already been defined, the Service Builder opens the specific method in the extension class of the Data Provider Class.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 45 of 65
Example Redefining a Method Declaration part
Map request input fields to the data source input fields. This provides information for filters, keys, constants and many more.
Call to the SAP system (backend) Find only the mapped properties. There are two sections IF and ELSE. The IF section relates to local RFC destination, the ELSE relates to Remote.
Map data in the SAP system (backend) to the model properties.
You map the response from the data source to the model's properties in order to return the information to the requesting client. This includes writing to the application log, and handling $skip. For the create operation, there is a read-after-create call. For create, update, delete operations, there is call for saving. Routing mechanism There is one method per operation.
In the declarative part, find the entity type on which the entity set is based. If you change the name of the entity type, it is also reflected in this section.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 46 of 65
For every entity set in the project, there is an entry in this section, that passes the relevant information received in the client request to the specific implementing method. Ref to Data After executing the entity set specific method, call the method, copy_data_to_ref in order to map the strongly typed results ( user_get_entityset) to the runtime data object ( er_entityset).
More Information Creating the ABAP Classes and Registering the Service
1.7.2 Mapping to a Data Source Activities Mapping is a manual relation that you establish between the parameters of a data source object (in an SAP backend system) and the properties of an entity set in the Service Builder. Service Builder enables you to map the data source for each of the CRUD (Create, Update ,Read , Delete) and the query operations. In the Service Builder, you can map the following types of data sources: Remote Function Calls (RFC) Business Object Repository (BOR) The process of mapping data sources is the same regardless of the data source type. For more information, see Creating the Mapping, below.
Recommendation We recommend that, you familiarize yourself with the documentation for the specific SAP Remote Function Call ( RFC), or BAPI you want to map to an entity set.
More Information Importing a Data Source (RFC/BOR Interface) Creating the Mapping
1.7.2.1 Creating the Mapping Use You can map entity sets with embedded complex types, delete the mapping for an operation, or update the mapping information. For BOR, the data source name is in the format: ..
Process Each entity set that is listed in the Service Implementation folder has the default operations to which you can map the data source. To map an operation, proceed as follows: 1. Expand the Service Implementation folder, and select the entity set you want to map to a data source. A list of operations of the entity set displays. For example, GetEntitySet (Query). 2. Right click the operation you want to map, and click Map to Data Source . The Map to Data Source dialog displays. 3. Under Target System , specify the location of your data source by choosing one of the following: Local: Choose Local , if the data source to which you want to map is in the same system as the Service Builder. Remote: Choose Remote if the data source ( RFC or BAPI) to which you want to map, is in a remote backend system (a system different from that of the Service Builder).
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 47 of 65
This option is applicable only where Service Builder is deployed in the SAP NetWeaver Gateway hub system itself.
Note The Remote option is applicable only if SAP NetWeaver Gateway deployment is SAP NetWeaver Gateway with IW_BEP Installation. In all other deployment options, use only the Local option . 4. Under Data Source Attribute, select one of the following data source types: Remote Function Call (RFC): Select the RFC data source to specify the remote function modules from which you want to map selected parameters to the properties of an entity set. Business Object Repository (BOR): Select the BOR data source to specify the BAPI methods from which you want to map selected parameters to the properties of an entity set. 5. In Data Source Name, press F4 to get a list of the BOR methods, or remote function modules in the target system. Alternatively, enter the name of the BOR method or remote function module. You can enter part of the name with the wild card character *, and press F4 to search for the remote function modules or BOR methods with names that contain the search term. 6. Choose the remote function module or BOR method for your data source, and click the check mark to confirm your mapping. The mapping displays as a node called, Mapping, under the selected operation of the entity set in the Service Implementation folder. In addition, the Mapping Screen displays on the right hand side of the project tree. You can map the parameters of the data source to the properties of the entity set in the Mapping screen
More Information Mapping UI Mapping the Query Operation Mapping the Read Operation Mapping the Create Operation Mapping Delete or Update Operation
1.7.2.1.1 Mapping UI Features You can create and edit your mappings in the Mapping UI.
The Mapping screen contains the following views: Mapping table
Note You can quickly obtain an automatically generated mapping relationship using the Propose mapping button in the tool bar of the mapping table. Data source view
Note You can drag and drop a parameter from the data source view into the Mapping table (in the same row) as the Entity set property to which you want to map the data source.
Related Information Map to Data Source Mapping Table Data Source View
1.7.2.1.1.1 Mapping Table Use The Mapping table displays when you open the Mapping screen to do the following: Create new mappings for the parameters of a data source and the properties of an entity set. For more information, see Creating the Mapping Edit the mapped operations. The Mapping table displays the following set of buttons in its tool bar: : Opens the Details dialog to display descriptive information of the selected line of row. The displayed information is presented in the columns, Group Description and Cell Content. The contents of the Details dialog are similar to the column headings and their values as displayed in the Mapping table. Click the check mark to close the Details dialog.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 48 of 65
Click to add a new row to the end of the Mapping table. Click to add a new row above the selected cell in the Mapping table. Click to remove the selected row and its content from the Mapping table. Sort the content of the Mapping table in an ascending or in a descending order. : Click to add or remove the heading columns in the Mapping table. The main area of the Mapping table consists of the title, table for entity set . Mapping screen help Opens the help information for the mapping screen. Propose Mapping Available in edit mode. Choose this button to automatically generate and display the available mapping relations between the properties of the entity set and the parameters of the data source. Full Screen on/off Choose this button to maximize or restore the size of the mapping screen. Below the title, are the following column headings: Entity Set Property: Displays the path to a specific property in the entity set. If the specified property is a simple field, the field name displays. If it is part of a complex type (structure), it displays the structure name or field. A search help is assigned to each property. The search help provides a popup with the entity structure. When you open the Mapping screen for the first time, the Mapping Table displays the default entity set properties. You can map the same property to more than one data source attribute. The same icons for the entity properties are available in the entity property search help, to enable you to clearly identify the key properties. Press F4 in a property to get the Property view, which displays all the fields for the entity set, and to select a property. Mapping Direction Specifies the direction of the mapping, and describes the data flow direction. An input data flow direction indicates that the service request is mapped into the RFC input parameters, and an output data flow direction indicates that the RFC output is mapped into the service result. The direction is determined based on the data source declaration type as follows: When the button points to the right, the mapping is of type input. When the button points to the left, the mapping is of type output. If the data source parameter is an import field, it means the direction is coming from the model to the data source, and the direction is set to input. You cannot change it. If the data source parameter is an export field, the flow is coming from the data source to the model, the direction is set to Output and you cannot change it. If the data source parameter is a changing or table parameter, you must decide the direction of flow.
Note If the data source parameter is for both directions, you send the data from the model and also get it back. In this case, you must specify one line of the parameter for input and another line for output. Data Source Parameter Specifies the path to a specific data source attribute. You can specify data source entries as follows: Press F4 to select the data source parameter from the popup. Drag and drop the data source parameter from the Data Source view into the Mapping table; on the same row as the entity set property to which you want to map.
More Information Mapping UI Data Source View
1.7.2.1.1.2 Data Source View Use The Data Source view enables you to drag and drop data source attributes into the same row as the entity set properties to which you want to map the data source. The data source attributes presented include structures, tables, and information such as, mandatory, default value, internal type and length. You can hide and show the column headings using the Change Layout icon. The following attributes are shown differently: Return table: Specifies a return message table, or a return structure, such as BAPIRET2. The table is automatically identified based on the message structure. It shows the icon [ ], at the end of the name of the attribute. You can use the Set/Unset button to set and to unset the structure as a log.
Note Do not map return tables or structures.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 49 of 65
Max Hits: Specifies the maximum items to return at runtime. It is automatically identified based on the name, and the Service Builder can use it correctly at runtime. No mapping is required. Range table: Specifies the structure of an internal table for administering complex areas, that is, the type of an internal ranges table in the ABAP program. Service Builder automatically identifies a ranges table based on its structure, however, you can manually identify it. You can set the ranges table using the button, SET/unset Range Table , (the button displays only when mapping the query operation). For more information, see Range Tables and Structures.
1.7.2.1.1.3 Deleting the Mapping Use You can delete the mappings for an operation of the entity set in the Service Implementation folder.
Process To delete the mappings for an operation, proceed as follows: 1. Expand the Service Implementation folder and select the entity set with the mappings you want to delete. A list of operations of the entity set displays. For example, GetEntitySet (Query). 2. Expand the operation to display the mapping under it. 3. Right click Mapping , and choose Delete Mapping .
More Information Mapping to a Data Source
1.7.2.1.1.4 Mapping Rules Implementation Considerations In the mapping between a data source and an entity set, Service Builder automatically performs certain checks to verify that the mapping you create is logical and acceptable. Familiarize yourself with the following mapping rules to minimize errors when creating a mapping. In addition, you can automatically obtain a proposal for the available mapping relations between the properties of the entity set and the parameters of the data source, using the Propose Mapping button. When you create a mapping in the Mapping screen, Service Builder checks that: The specified data source parameter (in the Data Source Parameter path) is a parameter or a range table of the data source. If the value is not a parameter, or a range table of the data source, you get an error. In a case a constant value has been provided, it checks if the specified data source parameter to be mapped to the constant value is of type, import or changing. Once a data source parameter is assigned to a constant value, the mapping direction is set to an input type. The specified property is a property of the Entity Type. If the specified constant value starts and end with an apostrophe. If the specified constant value is for a data source attribute of type output, or export. Generated Mapping Proposal Available in the mapping table, is the Propose Mapping button, which provides automatic mapping proposal between the properties of the entity set and the parameters of the data source. If there is no information about the mapping, no mapping is proposed. The mapping proposal is based on heuristics that consider the following: The origin of the properties (in case they are imported from a BOR or an RFC interface). If the property of an entity set is derived from an imported data source, that property is proposed to be mapped to a data source attribute with the same path as the original data source attribute. Mapping of other operations of the same entity set The proposed mapping information is derived as follows: Query operation: When attempting to map the Query operation, the proposed mapping for the Query operation is taken from the mapping information of the mapped Read operation. Read operation: When attempting to map the Read operation, the proposed mapping for the Read operation is taken from the mapping information of the mapped Update, Create, or Query operations. Update operation: When attempting to map the Update operation, the proposed mapping for the Update operation is taken from the mapping information of the mapped Create, and Read operations. Create operation: When attempting to map the Create operation, the proposed mapping for the Create operation is taken from the mapping information of the mapped Update, and Read operations. Delete operation: When attempting to map the Delete operation, the proposed mapping for the Delete operation is taken from the mapping information of the mapped
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 50 of 65
Update, and Read operations. The mapping mechanism attempts to generate a proposal by searching for corresponding mapping in the following sequence: 1. Based on the exact name of the path for the data model property. 2. Based on the exact path, and data type for the data model property. 3. Based on the mapping information from existing mapped operations.
Recommendation As the mapping proposal is based on heuristics, we recommend that you verify the proposal to make sure it is correct and suits your needs. General Mapping Rules The following are some of the general mapping rules: When mapping in the Mapping screen, Service Builder enables you to edit the direction of the specified data source parameter only if it is of type, changing. For more information, see Mapping UI. When mapping a data source attribute of type, import, the mapping direction icon indicates the attribute to be of type, input. When mapping a data source attribute of type export, the mapping direction icon indicates the attribute to be of type, output. For more information, see Data Source ViewData Source View. When mapping the Update or the Delete operations, only data source parameters of type, input can be mapped. For more information, see Mapping the Delete or Update Operation. When mapping the Query operation, the mapping direction icon indicates the attribute to be of type, input. For more information, see Mapping the Query Operation. If the data source parameter is a range table, or structure, it displays with a green icon. For more information, see Ranges Table. A constant value can only be mapped to a parameter of type input or changing. For more information, see Setting Constants. Many to one mapping is not allowed in all methods and all directions, except for range tables. A data source attribute that is not a range table cannot appear in more than one mapping with an input mapping direction.
Example For example, you are not allowed to map two properties to one data source parameter; or map two data source parameters to the same property. Mapping of properties in the mapping table is mandatory, unless you use constants. You get an error if the mapping entry contains a constant value and an entity set property at the same time. If the data source parameter is of type, changing, you can choose the mapping direction. In all other cases, it is automatically set according to the input or output characteristics of the parameter.
More Information Creating the Mapping
1.7.2.2 Setting Constant Values Procedure When creating or changing the mapping, you can manually set constant values for input parameters. When you set a constant value for a Property, you enable the Service Builder to retrieve additional data for the key Property, at runtime. You must enclose all values in apostrophes, for example, 'Value'.
Recommendation When you familiarize yourself with the documentation for the function or BAPI, you will get information about the parameter for which you can define a constant value.
Example For example, in case of RFC, choose the data source BAPI_USER_GETLIST, its key parameter is USERNAME. After mapping the parameters you want, select the parameter WITH_USERNAME, and set a constant value for it. Click the cell in the column, Constant Value , on the same row as the property you want to map, in the Mapping table; and set the constant value, 'Name'. Do not use apostrophes for numeric values or the following ABAP statements, as these statements will be converted accordingly at runtime: ABAP_TRUE ABAP_FALSE SPACE Initial SY-... (for example, SY-LANGU) You can add constants for flat structures and for only one table row. You can assign constant values to components of structures or for tables as well, but in the latter case, one table row instance will always be populated with constant values and passed to the data source. Deleting a Constant Value To delete a constant value, from the Mapping table, select the value (in the column, Constant Value ) to be deleted and press Delete.
More Information PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 51 of 65
More Information Creating the Mapping
1.7.2.3 Mapping the Query Operation Procedure When mapping the Query operation of an entity set to a data source, you can map the standard input parameters or range parameters, and filter the output, for example, to enable searching for flights between certain date ranges. You can use the Propose Mapping button to automatically generate and display the available mapping relations between the properties of the entity set and the parameters of the data source. If there is no information about the mapping, no mapping is proposed. To map the Query operation and set ranges tables (the range can be a table or a simple structure), proceed as follows: 1. Map the operation, GetEntitySet (Query) , to your data source in the Map to Data Source dialog. For more information, see Creating the Mapping. 2. In the Mapping table, click the cell under the heading, Data Source Parameter, in the same row as the property you want to map. 3. From the Data Source view, drag and drop the data source parameter you want to map into the selected cell in the same row as the property you want to map. Alternatively, press F4 in the cell under , Data Source Parameter , in the same row as the property you want to map. 4. Specify the mapping direction; the icon for the specified mapping direction displays. For well defined data source parameters of type input, or output, Service Builder automatically sets the mapping direction. 5. Save the project to continue editing the mapping, or generate the project. For more information, see Generating the Service. Max Hits: Limiting the Number of Items Returned in a Query You can limit the number of items returned in a Query, at runtime. Some query BAPIs and RFC function modules allow you to restrict the number of returned items by means of a Max Hits importing parameter. You can set a parameter as Max Hits in data source view. The Service Builder automatically defines input fields from the data source as Max Hits if the field name has one of the following options: MAXROWS MAX_ROWS MAX_HITS MAX_LINES MAX_CNT You can set a data source parameter as Max Hit in the Data source view, by selecting the Set/Unset Max Hits , if it has not been set automatically. You can either set a constant value to Max Hits and by default limit the returned items, or you can rely on the runtime handling of Max Hits. Also, you can specify Max Hits even if the remote function module does not have explicit Max Hits parameter. You do so to enable paging at runtime. In this case, the paging is done after getting the RFC results. The RFC returns all the results from the application, and the Service Builder deletes all the unnecessary results. To map a Max Hits to a constant value, proceed as follows: 1. Add a row to the Entity Set column of the Mapping table. And enter a constant value, for example, '10'. 2. Select the max_row parameter in the Data source view, and then click Set/Unset Max Hits . 3. Drag and drop the selected Max Hits parameter into the same row as the specified constant value in the Mapping table. In both cases, if the returned items are controlled from the client environment (with the $top option in OData), the runtime component tries to pass the value to the BAPI or RFC only if there is an importing parameter. You can use $top and $skip options to page through table results, at runtime. $top and $skip can be facilitated by mapping against MAXROWS or similar parameters as listed above. If you set a constant value and the $top option is also defined, the number in the $top option takes precedence. There is no default value. Mapping Rules for a Query The following are some of the mapping rules for the query operation: If the data source parameter you are mapping is a table, or structure, the mapping attribute is automatically defined according to the data source parameter type. In case, the data source parameter is of type, changing, Service Builder does not automatically set the direction; you must manually set the mapping direction. If the data source attribute you are mapping is a table, the mapping attribute is changed to the type, output. If the data source attribute you are mapping is a range table, the mapping attribute is changed to the type, input. You can map only one table of type, output. When mapping a property that is set as key, it must be of type, output. Key property must be mapped to one of the attributes in a table parameter in the remote function module or data source. Also, it can be mapped to the input parameter of a remote function module. In this case, it allows you to filter the results by the key property as well.
Example A remote function module returns sales order numbers but you can filter the result by sales order number in range of 1,000-2,000.
More Information PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 52 of 65
Creating the Mapping Mapping UI Mapping the Read Operation Mapping the Create Operation Mapping Delete or Update Operation Importing a Data Source (RFC/BOR Interface)Importing a Data Source (RFC/BOR Interface)
1.7.2.3.1 Ranges Table and Structures Procedure When mapping a query operation, you can map range parameters in the data source to entity set properties, in order to support filters. A ranges table describes an ABAP structure that must to be constructed from the following four components: SIGN (sign; I=include, E=exclude) OPTION (comparison operator; for example, EQ=equal) LOW (lower limit) HIGH (upper limit) Also a structure with prefixes, such as: matnr_sign, matnr_option, matnr_low, matnr_high is recognized as a range structure.
Note Not all the OData runtime filter options are supported. For information about the supported filter options, see SAP Note number 1671893
.
In addition, you can set your filter at design time in the Service Builder as constant value. For example Sign= 'I' ; Option= 'CP' ; Low= 'L*' All the table's or structure's parameters are greyed out, and their settings are only available in the Map Range Table dialog. In some cases, the table's parameters are available, but the structure is not recognized because one of the above listed fields is missing, for example, Sign is missing, but the others are available; Option, Low and High. After setting the range table, Service Builder checks all the range fields, and fields marked as constants are set as the constant value, Constant. Setting Ranges Table Parameters Ranges tables contain additional parameters, typically ones that specify for which parameter the range is valid. If a range table is not automatically recognized, or if you want to set a particular table structure as a range table, proceed as follows: 1. From the Data source view, select the range table node by choosing the arrow at the left of the table structure name. 2. Click Set/Unset Range Table . Alternatively, drag the table header of a range (the range table is dragged), and drop it into the same row as the property you want to map in the Mapping table, the Map Range Table dialog displays. If Service Builder identifies the table as range, it provides semantics proposal. The range displays as a set of brackets on a green button in the Mapping table, and when you select the button, it opens the Map Range Table dialog. You can map a single property to the range. The mapping direction for ranges is always of type, input. The semantic specifies how the field is handled and defines its role in the range expression. Mandatory semantics are HIGH, LOW, SIGN, and OPTION according to the ranges table semantics. For ranges tables, you can also set the semantic Parameter to specify the ranges table attribute that will be filled with the name of the BAPI or RFC parameter for which the range is valid. In some cases, populating the range table attribute with semantics is not correct, therefore you can specify constant values. The semantic is subject to the following checks in the Service Builder: Two or more parameters cannot have the same semantic, for example, two different parameters cannot both have the SIGN semantic. By default, no semantic is specified. When no semantic value is specified, you must specify a constant value.
Note Place constant values in apostrophes, for example, 'Label'. You cannot set both the Semantics and Constant Value fields, at the same time. if the range is already mapped, and you can unset the related range table in the data source view. If a table is mapped as an output table, and you set it as range, an error displays. If you try to set a regular structure other than a range structure, or simple field as a range, an error displays. Structures of type range can be set as range. If you try to set as range an output table, an error is displayed. Checks for semantics occur when you click Check If Low and High are defined in the range, a type match is performed between the mapped property and the data source parameter defined as Low or High. If constants are used in the range, a check is performed for type and length. For each range mapping, you must set at least one field as semantic. An output table cannot be set as range.
More Information PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 53 of 65
Mapping to Data Source Mapping the Query Operation
1.7.2.4 Mapping the Read Operation Procedure When mapping the Read operation in an entity set, you can map input, output, and changing parameters of the properties. Also, you can include constant values in the mapping. In addition, you can use the Propose Mapping button to automatically generate and display the available mapping relations between the properties of the entity set and the parameters of the data source. If there is no information about the mapping, no mapping is proposed. To map the Read operation, see Creating the Mapping. Mapping Rules for Read Operation The following are some of the mapping rules for read operations: When mapping a property that is not set as key, it must be of type, output. You must map at least one data source parameter as type, output. All properties that are set as key must be mapped as input, or output. If you provide constant values, they must be of type, input.
More Information Importing a Data Source (RFC/BOR Interface) Creating the Mapping
1.7.2.5 Mapping the Create Operation Procedure You must map the parameters from the data source to the Create operation of the entity set. You can use the Propose Mapping button to automatically generate and display the available mapping relations between the properties of the entity set and the parameters of the data source. If there is no information about the mapping, no mapping is proposed. To map the create operation, see Creating the Mapping. Mapping Rules for Create Operations The following are some of the mapping rules for create operations: All properties set as key must be mapped. You must map at least one data source parameter as type, input.
More Information Importing a Data Source (RFC/BOR Interface) Creating the Mapping
1.7.2.6 Mapping Delete or Update Operations Procedure When mapping the Update or the Delete operation to a BOR object method, or an RFC, as your data source, the data source view enables only the data source parameters of type, input, for mapping. All other parameters of type, changing, or output, are displayed but you cannot select them. You can use the Propose Mapping button to automatically generate and display the available mapping relations between the properties of the entity set and the parameters of the data source. If there is no information about the mapping, no mapping is proposed. To map the Delete or the Update operation, see Creating the Mapping. Mapping Rules for Update and Delete Operation The following are some of the mapping rules for update and delete operations: All mapping is of type, input, and you cannot edit their mapping direction. Mapping of all properties set as key must be of type, input.
More Information Importing a Data Source (RFC/BOR Interface)
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 54 of 65
Creating the Mapping
1.7.3 Implementation Support for Association In Service Builder, an entity can be related to another entity through association. The association is a relationship that has two ends, with each end defining an entity type in the relationship.
Prerequisites Make sure that you have the following: An association with referential constraints. Operation mapping for GetEntity (Read), or, GetEntitySet (Query) , is defined for the Dependent entity to which you want to navigate. In case the cardinality of the Dependent entity defined in the association is 0..1, or 1 , you must map the GetEntity operation. In case the cardinality is n , or, 0..n , you must map the GetEntitySet operation.
Context Service Builder can generate code in the DPC base class that implements navigation at runtime, from any end of the relationship.
Referential Constraint
Context The Principal entity must have a cardinality of 1 , or 0..1 , and you must specify all key properties of the Principal entity when defining the referential constraint.
Navigation Properties
Context Navigation properties enable users to traverse the association between two entity types. Where an entity has a navigation property, you can navigate between that entity to the related entity in the relationship.
Example The following example shows two scenarios of navigation from Customer to SalesOrder, and then back to Customer. Standard navigation scenario from Customer to its related SalesOrder list. 1. Create the association from Customer, to Entity SalesOrder. 2. Define the cardinality to be from 1..1, or 0..1 to 1..n, or 0..n. Where the cardinality for the principal entity must be 1..1, or, 0..1. 3. Define a navigation property for the Principal entity, Customer. 4. In the Referential Constraints page of the wizard, the key property for the principal entity, Customer, is automatically specified as the principal key. 5. In Dependent Property, select the property from which you want to obtain results, and follow the wizard to define the relationship. Opposite navigation scenario from SalesOrder details to its Customer details. 1. Create the association from Customer, to SalesOrder. Define the cardinality to be from 1..1, or 0..1, to 1..1, or 0..1. Where the cardinality for the principal entity must be 1..1, or, 0..1. 2. Define a navigation property for the Dependent entity, SalesOrder. 3. In the Referential Constraints page of the wizard, the key property for the principal entity, Customer, is automatically specified as the principal key. 4. In Dependent Property, select the property from which you want to obtain results, and follow the wizard to define the relationship. When you try to navigate from SalesOrder details to Customer details, the Read operation of SalesOrder is executed, and from the read response, the customer number is extracted. This is then used as a key in a call to get Customer details
1.8 Runtime Artifacts Use For more information about the runtime artifacts generated in the Service Builder for SAP NetWeaver Gateway, see: Generating the Service Generated ABAP Classes and Service Registration
1.8.1 Generating Runtime Objects Concept You must generate the service when you have defined the metadata for it. You generate the service in the Service Builder, which automatically generates the code for making your service OData compliant, and for use in SAP
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 55 of 65
NetWeaver Gateway. For more information about OData, go to: http://www.odata.org In addition, the Service Builder automatically configures the project by assigning the data model to the generated service for use at runtime. The following occurs when you generate the service: The implementation classes for the data model and the service are automatically created. The service is automatically registered in SAP NetWeaver Gateway. Service Builder automatically generates the corresponding code where you have mapped parameters of a data source to the properties of an entity set. For more information, see Mapping. To Remember Make sure that you have a properly defined data model, Entity Data Model (EDMX) or metadata (XML) file.
More Information Creating the ABAP Classes and Registering the Service
1.8.1.1 Creating the ABAP Classes and Registering the Service Activities You automatically generate code for the runtime functionality of your data model. The Service Builder generates the classes with the generated code, and handles the service registration process for IW_BEP based services for you. The generated classes are listed in the Runtime Artifacts folder, To create the classes and register the service, proceed as follows: 1. From the SAP NetWeaver Gateway Service Builder, right click the project name and choose Generate Runtime . The Model and Service Definition dialog opens. Alternatively, select the project, and click the Generate icon, or from Project in the menu, choose Generate . The Model and Service Definition dialog box displays. 2. Enter a name for the implementation class in the Class Name field. Proposed naming is, CL__MPC_EXT. 3. Enter the name for the base class in the Base Class Name field. Proposed naming is, CL__MPC
Note The MPC names cannot be changed after they have been generated. If you do not want to generate the DPC, you can remove the selection for Generate Classes . The option is available for you to generate the classes for the DPC whenever you want.
Note You can change the class names. If you do not specify the class names, an error displays when you try to generate the project. 4. Select Generate DPC to generate the classes for the Data Provider Class (DPC). When you remove the selection for Generate DPC, no classes are generated for the DPC, and Service Registration is not available. 5. In Backend Operation Proxy (BOP) Prefix, specify a prefix. The specified prefix is used as part of the BOP interface name. The default prefix is ZIF_. By default, the BOP prefix name is: < namespace of the project> and the . When you generate the project, Service Builder checks if the BOP prefix is aligned with the chosen package (derived from the transport request). If not aligned, the appropriate error message displays. In addition, Service Builder creates the BOP interface name for each function module that has been mapped in the specific project. The BOP interface name is created as follows: < BOP prefix> and the function module name. The generated BOP interface is available in the Runtime Artifacts folder under the project and it is listed as Backend Operation Proxy. 6. Under Service Registration, you can do the following: Technical Model Name Specify the Technical Model Name. This references the Model Provider Class which provides the metadata for the model. Technical Service Name Specify the Technical Service Name. This is a key to assign the models to a Service.
Note Make a note of the Technical Service Name. You use this name to register and to activate the specific service in the SAP NetWeaver Gateway system. See Adding the Service. to register and activate the service in the SAP NetWeaver Gateway system. If you choose to redefine an existing service, select Overwrite Extended Service , to overwrite the contents of the referenced service class. By default, it is not selected. You can edit the Technical Model Name. The Technical Service Name cannot be edited. An error displays if you do not specify the technical names. 7. Click Continue . The Transport Request dialog opens. 8. Choose Local , or assign the objects to the appropriate package. You can assign the generated classes to a transport request. The Service Builder checks if the MPC classes are already assigned to a transport request package, and if they are, the DPC classes are automatically assigned to that same transport request. The Service Builder saves the content of the project, checks the project, and saves it again It then creates the classes, lists them in the Generated Objects folder of the project, and registers the service in the backend system.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 56 of 65
Double-click any of the content in the Runtime Artifacts folder, on the right. In the Runtime Artifacts screen, you can view the properties of the classes.
More Information Overview of the Generated ABAP Classes and Service Registration BOP Interface Naming Rules
1.8.1.2 BOP Interface Naming Rules Implementation Considerations The BOP interface name is created as follows: < BOP prefix> and the function module name If the function module already has a namespace, the function module namespace is truncated. The length of the BOP interface name cannot be more than thirty characters. If the constructed BOP interface name already exists in the system, a number is added as part of the name. The length of the number added is two characters and it can be any value between one to ninety nine (1-99). Therefore, where the BOP interface name is more than twenty eight characters, the name is truncated to twenty eight characters and the number is added.
1.8.1.3 Generated ABAP Classes and Service Registration Use The Service Builder uses patterns to separate between the generated logic and your own code. It generates two types of classes: Base Class The base classes contain the Service Builder generated logic. The logic in the base class is overwritten every time the project is regenerated.
Caution Do not modify the code in this class, as the Service Builder overwrites its contents. Extension Class The extension class names have the suffix, EXT. An extension class is a subclass of the base class that is created once, only when the project is generated for the first time. An extension class contains no logic. Service Builder provides the extension class for you to write own code. Regenerating the project does not overwrite your code in the extension class. You provide own logic (typically for the DPC) by redefining the method you wish to modify. When the classes are created, they are listed in the Runtime Artifacts folder of the project, as follows: Model Provider Class (MPC): Two classes are generated for the MPC. These are: MPC Implementation Class : An automatically generated class for an inherited MPC class of the specific model. You can modify the code to suit your needs. MPC Base Class : An automatically generated class for the MPC superclass of the specific model. You cannot modify the code. The inherited MPC class is derived from this superclass. For more information, see Overview: Generated Classes for Model Provider Class. Data Provider Class (DPC): Two classes are generated for the DPC. These are: DPC extension class: An automatically generated for an inherited DPC class of the specific model. You can modify the code to suit your needs. DPC base class: An automatically generated class for the DPC superclass of the specific model. The inherited DPC extension class is derived from this superclass.. You can edit and modify the names of the classes before they are generated.
Note After the classes have been generated, their names cannot be modified. For more information, see Overview: Generated Classes for the Data Provider Class. The extension classes of the MPC and the DPC are called at runtime, respectively. Registering the Service You must specify the following details to enable the Service Builder to automatically register both the model and the service, and to assign the model to the specific service: Technical Model Name: Specifies the name of the data model. The name must be unique. The data model is described in the Model Provider Class, which provides the metadata for the service. Technical Service Name Specifies the name of the service. The name must be unique. The Technical Service Name that you specify will determine the name of the service that will be exposed by SAP NetWeaver Gateway.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 57 of 65
You can modify the registration information using the activities of the OData Channel implementation guide (IMG) in the back-end system. To modify the registration information: 1. Use transaction SPRO , and open the SAP Reference IMG. 2. Choose SAP NetWeaver Gateway Service Enablement Maintain Services .
Backend OData Channel
Service Development for Backend OData Channel
After creating and registering the model and the service, the Service Builder assigns them to the same transport request used for generating the classes. If the Service Builder fails to create the model and the service, an error message displays.
More Information Creating the ABAP Classes and Registering the Service
1.8.1.3.1 Generated Classes for Model Provider Class Introduction The Service Builder provides the user with the option of generating the Model Provider Class and Data Provider Classes. For Model Provider Class, when the user initiates the generation process, two names should be specified in the dialog box under Model Provider Class :
Figure 1: Model and Service Definition Dialog box
Base Class Name Class Name Fields
Description
Naming Sample
Class Name - Implementation Class
This is the Implementation class that inherits the Base class. This class can be modified manually.
CL__MPC_EXT
This is the Base class that is generated by the system during the generation process.
CL__MPC
Base Class Name
Project Name is the actual name of project in the Service Builder.
Project Name is the actual name of project in the Service Builder.
Note Do not modify this class manually
Note The MPC names cannot be changed after the generation. During re-generation of the model in SEGW, the Model and Service Definition dialog box will be displayed again only if the Generated Classes option is unselected in the Data Provider Class region. After generation, the Service Builder creates two types of Model Provider Classes, the Base Class and an Extension Class.
Base Class The generated Base class always inherits its code from /IWBEP/CL_MGW_PUSH_ABS_MODEL which in turn inherits from /IWBEP/CL_MGW_ABS_MODEL. The base class CL__Project Name_MPC that gets generated will have redefinition for DEFINE() and GET_LAST_MODIFIED() methods. See Base Class: Model Provider Class for more information.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 58 of 65
Implementation Class The Service Builder creates an extension class CL__MPC_EXT for the MPC, which is the implementation class. The extension class is inherited from the MPC base class. This class can be used to perform any manual changes required to the MPC, rather than changing the model in the Gateway Service Builder. See Extension Class: Model Provider Class.
Sample Model - Service Builder This is a sample model definition as seen in the Service Builder for project PROJECT_DEMO. A representation of the generated base and implementation classes after the MPC generation is given in the Generated MPC Classes section below:
Structure PROJECT NAME: PROJECT_DEMO DATA MODEL COMPLEX TYPES complex_type_1 complex_type_2 ENTITY TYPES entity_type_1 PROPERTIES key_1 key_2 property_1 property_2 NAVIGATION PROPERTIES nav_property_1 entity_type_2 PROPERTIES key_3 property_3 property_4 NAVIGATION PROPERTIES ASSOCIATIONS association_1 REFERENTIAL CONSTRAINTS referential_constraint_1 ENTITY SETS entity_set_1 entity_set_2 ASSOCIATION SETS association_set_1 FUNCTION IMPORTS function_import_1
Generated MPC Classes For given sample model definition above, on generation of runtime artifacts (MPC Classes), the base class and the implementation class will look as below:
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 59 of 65
Figure 2: Generated MPC Classes
Additional Information If the generated Model Provider Class has a syntax error try to rectify the error from the Service Builder. The error information can be obtained when the MPC class is opened in SE24. Once the error is rectified delete the generated Model Provider Class before regeneration.
More Information Base Class: Model Provider Class Implementation Class: Model Provider Class MPC Generation Using Inline Annotations Annotation maintenance is not supported in the Service Builder’s mass maintenance view and you have to manually write the code in the _EXT class. However, the Service Builder assists you to generate most of required code, which can be copied to the _EXTclass as required.
Note The Project Type should be Service with Vocabulary-Based Annotations. Execute the steps provided in this section in-addition to the steps executed above.
Procedure
Procedure 1. 2. 3. 4.
Create a Project with Type Service with Vocabulary-based Annotations. Import vocabularies as detailed in the Importing a Vocabulary Filesection. Click Generate Runtime Objects button to generate the MPC class. Method DEFINE_VOCAB_ANNOTATIONS will be created in the Model Provider Class to maintain the Vocabulary based Annotations. For Project Types other than e s the method DEFINE_VOCAB_ANNOTATIONS will not be created. End of the note. 5. Vocabulary references will be created Inside the method DEFINE_VOCAB_ANNOTATIONS . lo_reference = vocab_anno_model->create_vocabulary_reference( iv_vocab_id = 'ZCAPABILITIES' iv_vocab_version = '0001'). lo_reference->create_include( iv_namespace = 'Org.OData.Capabilities.V1' iv_alias = 'UI' ). Annotations may be of different types:
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 60 of 65
1. Simple value can be of type of one of the following String, Boolean, Integer, Path, Property path, Navigation property path. For simple value annotation, the code will look like: lo_ann_target = vocab_anno_model->create_annotations_target( 'EPMDemo.PurchaseOrderItem' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Core.Updateble' ). lo_simp_value = lo_annotation->create_simple_value( ). lo_simp_value->set_boolean( abap_true ). 2. Annotation with collection: Collection may contain more than one record or simple value. lo_ann_target = vocab_anno_model->create_annotations_target( 'EPMDemo.PurchaseOrder/GrossAmount' ). lo_annotation = lo_ann_target->create_annotation( iv_term = 'Core.AcceptableMediaTypes' iv_qualifier = 'iPad' ). lo_collection = lo_annotation->create_collection( ). lo_simp_value = lo_collection->create_simple_value( ). lo_simp_value->set_string( 'image/jpeg' ). lo_simp_value = lo_collection->create_simple_value( ). lo_simp_value->set_string( 'image/gif' ). 3. Annotation with Record: Record will contain one or more properties. A property may contain another collection or a simple value. lo_annotation = lo_ann_target->create_annotation( iv_term = 'UI.HeaderInfo' iv_qualifier = 'iPad' ). lo_record = lo_annotation->create_record( iv_record_type = 'Some_Type' ). lo_property = lo_record->create_property( 'ValueID' ). lo_collection = lo_property->create_collection( ). lo_simp_value = lo_collection->create_simple_value( ). lo_simp_value->set_string( 'Inside a collection in a record' ).End of the code.
1.8.1.3.1.1 Base Class: Model Provider Class Use The Base Class CL__Project Name_MPC that gets generated will have redefinition for DEFINE() and GET_LAST_MODIFIED() methods.
DEFINE () Method The content of the Define () method depends on the OData artifacts which are created for a model in SEGW (such as, entity types, associations, function imports, complex types, and more). For each of the artifacts created, one method will be generated and called inside this Define () method.
Sample Code A sample code for the Define () method for the sample model is provided below for reference: method DEFINE. *&---------------------------------------------------------------------* *& Generated code for the MODEL PROVIDER BASE CLASS &* *& &* *& !!!NEVER MODIFY THIS CLASS. IN CASE YOU WANT TO CHANGE THE MODEL &* *& DO THIS IN THE MODEL PROVIDER SUBCLASS!!! &* *& &* *&---------------------------------------------------------------------* define_entity_type_1( ). define_entity_type_2( ). define_associations( ). Define_complextypes(). Define_actions(). endmethod.
Note 1. For each of the method call there will be a corresponding method implementation in the same class with appropriate details. 2. The Gateway Service Builder allows to define an entity type of length 40 characters whereas the ABAP method name of a class should be restricted to 30 characters. In cases where two entity names have similar first 31 characters and last few characters unique, the class will still be generated with unique method names. 3. In the define method of the class super->define() will be called only if at least one entity type (corresponding entity set) is set as subscribable. 4. All the entity types will have their corresponding TYPES definition & names as constants and available in the class, which can be used in the code.
Define GET_LAST_MODIFIED Method A sample code for Get_Last_Modified method is provided below for reference: method GET_LAST_MODIFIED. *&---------------------------------------------------------------------*
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 61 of 65
*& Generated code for the MODEL PROVIDER BASE CLASS &* *& &* *& !!!NEVER MODIFY THIS CLASS. IN CASE YOU WANT TO CHANGE THE MODEL &* *& DO THIS IN THE MODEL PROVIDER SUBCLASS!!! &* *& &* *&---------------------------------------------------------------------*
CONSTANTS: lc_gen_date_time TYPE timestamp VALUE '20121031052115'. rv_last_modified = super->get_last_modified( ). IF rv_last_modified LT lc_gen_date_time. rv_last_modified = lc_gen_date_time. ENDIF. endmethod.
Note The latest timestamp at which the class was last modified will be returned by this method. Additional Information The information provided in this section is only for reference. Method: LOAD_TEXT_ELEMENTS : This method is set as final in the MPC class and is required for internal label handling. Hence this method need not be modified/redefined by the user in the extended class. Method Name
LOAD_TEXT_ELEMENTS
Visibility
Public
Final
X
Parameter Name
RT_TEXT_ELEMENTS
Method: GET_EXTENDED_MODEL : This method will be present in the MPC class only during a redefine scenario. This method is set as final in the MPC class and it is required for internal handling of overwrite scenario. Hence this method need not be modified/redefined by the user in the extended class. Method Name
GET_EXTENDED_MODEL
Visibility
Public
Final
X
Parameter Name
EV_EXTENDED_SERVICE
EV_EXT_SERVICE_VERSION
Exporting
EV_EXTENDED_MODEL
Exporting
EV_EXT_MODEL_VERSION
Exporting
Exporting
1.8.1.3.1.2 Implementation Class: Model Provider Class Use The Service Builder generates an Implementation class along with the base class for every model. It is proposed to extend this class manually to suit your needs. After generating the Model Provider Class the generated classes are stored in the Runtime Artifacts folder. Follow the instructions provided in this section to extend the extension class. To redefine the methods in an implementation class, proceed as follows: 1. Expand the Project folder in the tree view of the Service Builder. 2. Navigate to Generated Objects CL_ProjectName_MPC_EXT
.
3. Click to switch to edit mode. 4. Right click and select Workbench . The selected implementation class opens in the Class Builder . 5. Click the Define Method and choose the redefine button to redefine it: Here is a sample: super->define( ). Endmethod. 6. Save the changes.
1.8.1.3.2 Generated Classes for the Data Provider Classes Activities The Service Builder automatically generates classes for the DPC once you generate the project. The following are the classes:
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 62 of 65
Base Class: The generated base class inherits its code from the minimal Gateway abstract class, /IWBEP/CL_MGW_PUSH_ABS_DATA. The generating mechanism for the DPC redefines and implements the following operations in the minimal Gateway: Create, Read, Update, Delete, (CRUD) and Query. For each entity set in the model, it generates the specific methods for implementation. Extension Class: The Service Builder creates an extension class for the DPC, which is the implementation class. The extension class is inherited from the DPC base class. You can redefine each method in the extension class for the DPC. There are several methods in each class, while some of the methods are inherited from the abstract class and do not change, others that are inherited from the abstract class can be redefined, and you can add your own methods. Properly created DPC classes do not give syntax errors, and have an Active state. To verify, select the Check .
More Information Creating the ABAP Classes and Registering the Service Redefining Methods of the Operations
1.8.1.3.2.1 Base Class: Data Provider Class Use The generating mechanism redefines and implements the following operations in Gateway; Create, Read, Update, Delete (CRUD) and Query . The class is generated only when the Service Builder successfully generates the code for the classes of the Model Provider Class (MPC). The DPC base class inherits from the generic runtime class, /IWBEP/CL_MGW_PUSH_ABS_DATA. In addition, the mechanism generates several service methods that support the runtime of each operation, such as, RFC_EXCEPTION_HANDLING , and RFC_SAVE_LOG.
Caution Do not change this class, as the Service Builder overwrites the content of the base class when you regenerate the project. When generated, the DPC creates specific methods for the implementation of each operation. Doing so, the Service Builder enables you to work with a small number of classes while redefining only the specific operation for a specific entity set without affecting others. Naming of Methods Method names are automatically created and can contain a maximum of thirty characters. The following is the format for method names: For example, for an entity set called BANKLIST, the base class automatically creates new methods for the CRUD and Query operations. In this case, the names of the methods for the entity set, BANKLIST, will be as follows: BANKLIST_CREATE_ENTITY, BANKLIST_READ_ENTITY, BANKLIST_DELETE_ENTITY, and so on. The description for the method provides information about the method for the corresponding entity set. If a method name exceeds the maximum length, the method is renamed by removing characters from the entity set name and not the operation name. For example, the method name BANKLISTOFCUSTOMERS_CREATE_ENTITY, is too long, it will be renamed as BANKLISTOFCUSTOM_CREATE_ENTITY. If there are two methods with the same name, each one is renamed by adding a number to the entity set name. For example, if the mechanism detects two methods with the same name, BANKLISTOFCUSTOME_CREATE_ENTITY, both methods will be renamed as follows, BANKLISTOFCUSTOM01_CREATE_ENTITY, and BANKLISTOFCUSTOM02_CREATE_ENTITY.
Note When you change the name of an entity set, the Service Builder does not rename the methods of the specific entity set, rather it changes the routing logic to point to the new entity set name. Method Interface The entity set method interfaces are strongly typed and coupled with the real entity type in the model. All the methods generated are empty.
More Information Creating the ABAP Classes and Registering the Service Redefining Methods of the Operations
1.8.1.3.2.2 Implementation Class: Data Provider Class Use The Service Builder creates an extension class for the DPC, which is the implementation class.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 63 of 65
You can implement the methods in this class to suit your needs. The extension class inherits from the DPC base class. You can add your own code to specific methods for an entity set in the extension class.
Example If you have a model for customer data and you want to implement the Get Entity operation, redefine the method, CUSTOMER_GET_ENTITY , and write your own code. At runtime, the other generated methods in addition to your code for the CUSTOMER_GET_ENTITY method will be executed. Implementing the Class You redefine the methods in an extension class to suit your needs.
Recommendation We recommend to redefine each method directly.
Caution Changes that you make in the data model, such as, renaming, and removing of entity sets, and the attributes of entity types, which have been referenced in your code, can result in syntax errors in your implementation.
More Information Creating the ABAP Classes and Registering the Service Redefining Methods of the Operations
1.9 Service Maintenance Introduction Use Use the Service Maintenance function in the Service Builder to register and maintain each service in an SAP NetWeaver Gateway system. This function also enables you to maintain services created and redefined directly in the Service Builder (in an SAP Business Suite backend system) as opposed to navigating to another system such as an SAP NetWeaver Gateway hub system. The Service Maintenance offers the following functions: Register the service in an SAP NetWeaver Gateway system. View all the SAP NetWeaver Gateway systems in which the service is registered. View the error log of the service in the registered SAP NetWeaver Gateway systems. View the service document. View the service activation status of the service in the registered SAP NetWeaver Gateway systems. Prerequisites The SAP NetWeaver Gateway systems in which you want to register the service must be configured under the following path: SPRO SAP NetWeaver Gateway Service Enablement Backend OData Channel Connection Settings to SAP NetWeaver Gateway SAP NetWeaver Gateway Settings .
Procedure To maintain a service in the Service Builder, proceed as follows: 1. Log onto the SAP NetWeaver Gateway system. 2. Open transaction SEGW. The SAP NetWeaver Gateway Service Builder opens. 3. Create a new project. See Creating a Service Builder Project for more information. 4. Generate the service if the service it is not already generated. See Runtime Artifacts for information about generating services. 5. Expand the Service Maintenance folder in the tree view. 6. Double-click on the Service Maintenance folder to view the configured systems in the mass maintenance view. The mass maintenance view displays the following details: Table 1: Details of the Mass Maintenance View
System
These systems are the SAP NetWeaver Gateway hub systems configured in SPRO SAP NetWeaver Gateway Service Enablement Backend OData Channel Connection Settings to SAP NetWeaver Gateway SAP NetWeaver Gateway Settings .
Client
The client of the SAP NetWeaver Gateway hub system.
RFC Destination
The RFC destination of the SAP NetWeaver Gateway hub system.
Registration Status
This is an Indicator that represents the registration status of the service in the selected system. The statuses are as follows: Service Registered from this system - The service is registered from the current system. Service with the same name registered from another system -
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 64 of 65
There may be instances when a service with the same name as your service is already registered in the target SAP NetWeaver system. In such instances this status is shown. Service not registered - The service is not yet not registered in this system. You can proceed and register the service in the current system. Could not retrieve the registration status - There may be instances when the target system's status could not be retrieved due to some technical reasons, for example, due to system unavailability or authorization failure.
7. Right click the system in which you would like to register the service and select Register. Alternatively, you can select the system and choose the Register button in the mass maintenance view. The Select System Alias window displays.
Note The System Alias window displays only if there is more than one system that points to the system from which you are trying to register the service. If only one system applies, the System Alias window is not displayed since this system is selected as default. 8. Select the system by using the input help available for this field. 9. Choose Continue. The Add Service window displays. 10. Details about the selected service are displayed in the Add Service window. 11. Enter the valid package details in the Package field. 12. Choose Continue to add the service to the selected system. 13. You can also perform the following functions in the mass maintenance view: 1. Choose Maintain to open the Maintain Services window. See Activate and Maintain Services for more information. 2. Select a system, and choose the Error Log button to view the error log for the service in the selected system.
Note Error logs for the current service are displayed for all users on the current date.
PUBLIC © 2014 SAP AG or an SAP affiliate company. All rights reserved.
Page 65 of 65
View more...
Comments