2-sap netweaver gateway service builder

65
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

Upload: kokocodename47

Post on 20-Jan-2016

470 views

Category:

Documents


4 download

DESCRIPTION

2-SAP NetWeaver Gateway Service Builder

TRANSCRIPT

Page 1: 2-SAP NetWeaver Gateway Service Builder

SAP NetWeaver Gateway Service BuilderPDF 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 purposewithout the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AGand its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided bySAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not beliable 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 expresswarranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. SAP and otherSAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and othercountries. 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

Page 2: 2-SAP NetWeaver Gateway Service Builder

Table of content1 SAP NetWeaver Gateway Service Builder1.1 Development Approaches1.2 User Interface1.2.1 Working with the Mass Maintenance View1.3 Creating a Service Builder Project1.3.1 Copying a Service Builder Project1.3.2 Generating Runtime Artifacts for Copied Projects1.4 Data Modeling Basics1.4.1 Defining a Data Model1.4.2 Copying Data Model Artifacts1.4.3 Entity Types1.4.3.1 Defining Properties1.4.3.1.1 Mappings and the ABAP Type Editor1.4.3.2 Navigation Properties1.4.4 Complex Types1.4.5 Associations1.4.5.1 Referential Constraints1.4.6 Entity Sets1.4.7 Association Sets1.4.8 Function Imports1.4.8.1 Function Import Parameters1.4.9 Working with Annotations1.4.9.1 Uploading Vocabularies into the Vocabulary Repository1.4.9.2 Importing a Vocabulary File1.4.9.3 Adding Vocabulary-Based Annotations to Data Model Artifacts1.5 Data Modeling Options1.5.1 Importing a Data Model1.5.2 Importing a DDIC Structure1.5.3 Importing a Data Source (RFC/BOR Interface)1.5.4 Importing Search Help as a Data Source1.5.5 Including an OData Service1.6 Redefining Services1.6.1 Extending an OData Service Using Service Builder1.6.2 Redefining OData Service (GW)1.6.3 Redefining Services from External Framework (SPI, BW Query, GenIL)1.7 Service Implementation1.7.1 Redefining Methods of the Operations1.7.2 Mapping to a Data Source1.7.2.1 Creating the Mapping1.7.2.1.1 Mapping UI1.7.2.1.1.1 Mapping Table1.7.2.1.1.2 Data Source View1.7.2.1.1.3 Deleting the Mapping1.7.2.1.1.4 Mapping Rules1.7.2.2 Setting Constant Values1.7.2.3 Mapping the Query Operation1.7.2.3.1 Ranges Table and Structures1.7.2.4 Mapping the Read Operation1.7.2.5 Mapping the Create Operation1.7.2.6 Mapping Delete or Update Operations1.7.3 Implementation Support for Association1.8 Runtime Artifacts1.8.1 Generating Runtime Objects1.8.1.1 Creating the ABAP Classes and Registering the Service1.8.1.2 BOP Interface Naming Rules1.8.1.3 Generated ABAP Classes and Service Registration1.8.1.3.1 Generated Classes for Model Provider Class1.8.1.3.1.1 Base Class: Model Provider Class1.8.1.3.1.2 Implementation Class: Model Provider Class1.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

Page 3: 2-SAP NetWeaver Gateway Service Builder

1.8.1.3.2.1 Base Class: Data Provider Class1.8.1.3.2.2 Implementation Class: Data Provider Class1.9 Service Maintenance

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 3 of 65

Page 4: 2-SAP NetWeaver Gateway Service Builder

1 SAP NetWeaver Gateway Service Builder

UseSAP NetWeaver Gateway Service Builder (transaction SEGW) is a design-time environment, which provides developers with an easy-to-use set of tools forcreating services. It has been conceived for the code-based OData Channel and supports developers throughout the entire development life cycle of a service.

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

FeaturesIn one single transaction, SAP NetWeaver Gateway Service Builder caters for the needs of both experienced and less experienced developers who want toexpose data for easy consumption using a variety of platforms, frameworks, and devices. While experienced developers have maximum flexibility to define a newservice from scratch and integrate their own source code, less experienced developers can reduce the time and effort involved in creating services by importingexisting 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 forprogramming.

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 serviceOData artifacts such as entity set, entity type, and properties

Project-Based Service DevelopmentThe Service Builder introduces a new service development concept, which is organized around projects. Projects are used to store all the artifacts developersneed to create a service and model together in one place. Since projects consolidate all related data, developers can easily work on multiple projects in paralleland reuse data between projects before generating and activating the actual service. Consequently, projects provide developers with the freedom to interrupt theservice development and modeling process at any time, without being bound to runtime artifacts and without risk of losing data. Organizing the servicedevelopment and modeling process in projects has the advantage that all project data can be transported easily between one system and another for maximumefficiency and reuse.

1.1 Development Approaches

UseSAP NetWeaver Gateway Service Builder supports different development approaches and life cycles to provide developers with maximum flexibility so they canfulfill changing development prerequisites and meet diverse requirements. When developers need a service to expose specific data, they can decide whether todefine 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 couldbe 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 numerousways 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 increasingefficiency without compromising on quality. Whichever development approach is taken, the appropriate set of ABAP classes is generated. This ensures thatdevelopers 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

Page 5: 2-SAP NetWeaver Gateway Service Builder

Service Builder (transaction SEGW)

Data Model DefinitionOData services require a data model definition (model provider class). In the case of client development projects, the development process invariably starts witha 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, seeImport:

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 tapinto a multitude of existing Remote Function Calls (RFCs) and Business Application Interfaces (BAPIs) from the Business Object Repository. Afteryou have imported an existing interface definition, you can map the operations from the same RFC or BAPI to obtain the service operations yourequire 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 systemlandscape. 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, itconnects existing service operations so you do not need to create an individual service implementation. Consequently, you can skip the serviceimplementation 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, itallows 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 theservice implementation phase.Subsequent development phase: Service Maintenance.For more information, see Including an OData Service.

Service ImplementationIn the service implementation phase, you define the runtime artifacts (operations and methods) for the data provider class. You can define the runtime artifacts inthe following ways:

Code-based implementation: The Service Builder generates the required ABAP classes based on the data model you define. Subsequently you cannavigate directly from the Service Builder to ABAP Workbench where you can access the appropriate methods and write the source code for the variousdifferent 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. Youcan map data sources of type Remote Function Call (RFC) and Business Object Repository (BOR). This function is designed for use in conjunction with theImport 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 MaintenanceThe final development phase in the life cycle of an OData service is Service Maintenance and this must be carried out regardless of your chosen developmentapproach. Service Maintenance entails registering and activating each service in an SAP NetWeaver Gateway system.

For more information, see Service Maintenance.

1.2 User Interface

UseSAP NetWeaver Gateway Service Builder simplifies and structures the service development and modeling process required for exposing and consuming data byusing projects. Developers first create a project to develop, model, and store all the development artifacts they need to define a service. The focus on project-based service development is consequently reflected in the Service Builder user interface.

Screen AreasThe 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 dataobject 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, complextypes, associations, and function imports. To display details about a data object, select the relevant row in the mass maintenance view and chooseDetails .

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

Page 6: 2-SAP NetWeaver Gateway Service Builder

1.2.1 Working with the Mass Maintenance View

UseSAP NetWeaver Gateway Service Builder provides an easy-to-use mass maintenance view, which allows you to create, edit, delete, and organize data objectsand their properties in your Service Builder project. Regardless of the data object type you want to edit, the editing process is identical.

OverviewOverview of functions available in the mass maintenance view:

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

Related InformationCopying Data Model Artifacts

1.3 Creating a Service Builder Project

UseTo 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 servicedevelopment and modeling process. You can use projects to organize the transport of objects from one system environment to another meaning that all artifactsremain together at all times.Choose from two project types in the Service Builder when you create a new prpoject:

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 massmaintenance 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 dataartifacts 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 inserta new row above the current cursor position.

Delete Row Select appropriate row in the mass maintenance view and choose Delete Row to deletethe row at the current cursor position.

Sort in Ascending/Descending Order Choose Sort Ascending/Sort Descending Order to sort data objects in ascending ordescending 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 soyou 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 theclipboard 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 toa new location.

Invert Checkboxes When selecting and deselecting checkbox values in the mass maintenance view, forexample, to define properties, select the cells or whole columns for which you want toinvert the current checkbox values and choose Invert . This enables you to change thecheckbox values from selected or deselected for one or more cells, that is, invert thecurrent values.Furthermore, choose Select or Deselect from the dropdown list to select or deselect allcheckboxes in the selected columns.

Redefine Attributes When redefining an existing service in your project that is referenced from anothermodel, 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 isreferenced from another model, choose Undo Redefinition to reset the attributes youhave redefined to the original service attributes.

Undo Identical Redefinition After you have redefined the attributes of an existing service in your project that isreferenced from another model, choose Undo Identical Redefinition to retain theredefined attributes, while resetting the attributes you have not changed to the originalservice 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 mustcreate a project of type Service with Vocabulary-Based Annotations .

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 6 of 65

Page 7: 2-SAP NetWeaver Gateway Service Builder

Choose Service with SAP Annotations if you want to annoate your data model artifacts using standard SAP annotations. SAP annotations includeCreatable, 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 includesABAP 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 attributesand provide additional descriptive information about the artifact. In this case, additional terms can be consolidated in a vocabulary and uploaded into theVocabulary Repository. The Vocabulary Repository includes a selection of vocabulary files for ODate vocabulary-based annotations, such asOrg.OData.Atom.V1 and Org.OData.Capabilities.V1.

ProcedureTo 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 anew 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 Buildertogether 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 60characters.

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 andupload your own customer-specific vocabularies into the Vocabulary Repository. The uploading of vocabulary files is an optional preparatory step forimplementation.

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

NoteIf 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 packagename or choose the Local Object pushbutton. This ensures that the object is created locally.

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

The project structure comprises the following folders and subfolders:

Data ModelEntity TypesAssociationsEntity Sets

The following subfolders are automatically added to the tree only when you define new entity entries for them:Association SetsComplex TypesFunction ImportsVocabularies: Imports - Lists the vocabulary or vocabularies imported for your project. Implicit References - Lists the vocabulary or vocabulariesreferenced by the vocabulary file that was explicitly imported.

Service ImplementationRuntime ArtifactsService 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 anytime, 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 InformationCopying a Service Builder Project

1.3.1 Copying a Service Builder ProjectHow to copy an existing Service Builder project for a similar use case to save time and effort.

ContextTo 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 serviceimplementation. Note that while you can copy the mapping information contained in a project's service implementation, you cannot copy the generated ABAPclasses 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

Page 8: 2-SAP NetWeaver Gateway Service Builder

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 minimalchanges being required.

To copy an existing Service Builder project, proceed as follows:

Procedure1. 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 helpfulto 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 shortdescription, 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 verifythat 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 Implementationcheckboxes. In this context, copying the service implementation refers to the copying of the mapping information, not the actual runtime artifacts. Note that ifyou 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 havingto 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 asa 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 theoriginal 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 thesame 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 thecopy 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 orchoose the Local Object pushbutton.

ResultsThe 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-handside of the screen. The newly created projects contains the same arfiacts as the tempate project you copied. Consequently, if you selected the Data Model andService 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 datamodel.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 thisproject, 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 artifactshave been generated, you must register the new service in the relevant system using the Service Maintenance function.

Related InformationGenerating Runtime Artifacts for Copied ProjectsCreating a Service Builder ProjectCopying Data Model ArtifactsService Maintenance

1.3.2 Generating Runtime Artifacts for Copied ProjectsExplains how to generate runtime artifacts for projects that you created by copying an existing project in the Service Builder.

ContextSince the Copy Project function does not enable you to copy a project's runtime artifacts, you need to generate the runtime artifacts as follows:

Procedure1. 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 manualcoding, however, and provided that the service was created using the Standard generation strategy, follow the next steps outlined below. You only need toperform 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 thecustom-specific instructions for this instead.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 8 of 65

Page 9: 2-SAP NetWeaver Gateway Service Builder

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'scontent.MPC_EXT class: check if the DEFINE method is redefined in the template project.

Next StepsAfter 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

UseAfter you have created a project in SAP NetWeaver Gateway Service Builder, you can start the data modeling process. The data model defines, for example, theentity types, complex types, properties, and associations required for the service. After you have defined the artifacts contained in the data model, you canconsider the operations you want to perform at runtime, and you map these operations to data objects and properties within your Service Builder project. Atruntime, the data model is exposed to SAP NetWeaver Gateway services that trigger the operations you have defined at design time and return the relevant dataand 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 canaccess this data from a mobile device while on the road without having to log onto the relevant SAP system directly.

Data Modeling AlternativesDepending 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 ServiceTo facilitate a superior user experience when working with the Service Builder, copy and paste functions are available. For more information, see CopyingData Model Artifacts and Copying a Service Builder Project.

1.4.1 Defining a Data ModelIn 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 youwant to expose at runtime.

ContextYou 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 thedata model folder structure to create and edit the individual data model elements. The data model structure comprises the following subfolders for each of theelement types:

Entity TypesComplex TypesAssociationsEntity SetsAssociation SetsFunction 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 modelelement, 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:

Procedure1. 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 InformationData Modeling Options

1.4.2 Copying Data Model ArtifactsExplains 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

Page 10: 2-SAP NetWeaver Gateway Service Builder

ContextTo 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 theService 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 editmode. You can copy and paste the following data model artifacts:

Entity types (including properties and navigation properties)AssociationsEntity setsAssociation setsFunction importsComplex types

Working with Copy and Paste Icons in the Mass Maintenance ViewThe 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 informationmessage 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 thescreen 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 andpasted 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 ViewIn 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 openprojects. 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 arecopied 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 toconfirm the number of nodes pasted from the clipboard.

Working with Copy and Paste Context Menu in the Tree ViewYou 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 easilyreuse 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:

Procedure1. 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 copiedto 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 thathave been pasted from the clipboard.

Related InformationCopying a Service Builder Project

1.4.3 Entity Types

UseUse 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, forexample an item or a concept. Entity types comprise:

A unique nameA 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 uniqueidentifier 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

Page 11: 2-SAP NetWeaver Gateway Service Builder

ProcedureTo 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 NameSpecify 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 SetSelect 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 toreuse 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:

9. Choose Save to create the new entity type.

NoteIn 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 popupis 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 PropertiesAfter 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 alsodefine 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

Column Description

Semantics Specifies how the entity type is to be used. For example, classifies a number as atelephone number or a fax number.

Thing Type Select this checkbox if the entity type is a thing as opposed to a subordinate object. Forexample, a thing type is a tangible object such as a purchase order and a subordinateobject is a purchase order item.

Media Select this checkbox if the entity type belongs to a media collection and has a mediasource stream. This means every instance of this entity type points to an additionalresource with some arbitary (MIME) type, for example, a photo with type image orjpeg.

As Author Property OData feed customizing setting. Enter a property to be used for populating theatom:author element at runtime. Use the input help to select an existing propertyfrom the same entity type.

As ETag Property OData feed customizing setting. Enter a property to be used as an ETag to supportOData optimistic currency control for modifying requests. Use the input help to selectan existing property from the same entity type.

As Published Property OData feed customizing setting. Enter a property to be used for populating theatom:published element at runtime. Use the input help to select an existing propertyfrom the same entity type.

As Title Property OData feed customizing setting. Enter a property to be used for populating theatom:title element at runtime. Use the input help to select an existing property fromthe same entity type.

As Updated Property OData feed customizing setting. Enter a property to be used for populating theatom:updated element at runtime. Use the input help to select an existing propertyfrom the same entity type.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 11 of 65

Page 12: 2-SAP NetWeaver Gateway Service Builder

UseIn SAP NetWeaver Gateway Service Builder, you can define properties for entity type and complex types. Properties define the characteristics of the data that anentity type or complex type instance will contain at runtime. The properties of entity types and complex types are stored in a separate Properties subfolder withinthe Entity Types and Complex Types folders in your Service Builder project.Properties comprise the following:

AttributesNameType (Edm type (with facets such as Nullable, MaxLength, FixedLength, Precision, Scale ) or complex type

AnnotationsSAP annotations (such as Creatable, Deletable, Label, UnitProperty )Vocabulary-based annotations

ABAP type informationABAP field nameABAP type assignment

ProcedureTo 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:

NoteThe columns in the Properties table differ depending on whether the project is of type Service with SAP Annotations , for which Edm Core Type andComplex 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. Ifyou have imported the complex type or entity type, a name is already displayed, forexample, 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 typeService with Vocabulary-Based Annoations .

Data Type Enter the data type that corresponds to the complex type or core type property. If it is acore 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. Thevalue defines the maximum number of decimal places permitted to the left and rightof the decimal point.

Scale EDM facet. Enter the maximum number of decimal digits permitted after the decimalpoint.

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 fromthe same complex type or entity type. For example, if the property comprises anumber that refers to a currency or amount, you can specify the relevant currency orunit of measure.

Creatable SAP annotation for projects of type Service with SAP Annotations . Select thischeckbox 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 operationin the data model.

Updatable SAP annotation for projects of type Service with SAP Annotations . Select thischeckbox 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 anUpdate operation in the data model.

Sortable SAP annotation for projects of type Service with SAP Annotations . Select thischeckbox if you want to allow this property to be used in $orderby statements forsorting data at runtime.

Nullable EDM facet. Select this checkbox if you want to allow a null value to be entered for thisproperty at runtime.

Filterable Select this checkbox if you want to allow this property to be used in $filter statementsfor filtering data at runtime.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 12 of 65

Page 13: 2-SAP NetWeaver Gateway Service Builder

NoteTo 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 ofthe service with additional information. However, if you are developing a specific application, you could include validation checks in the relevant dataprovider classes. Since the validation checks require a specific use case, these must be tailored to suit the particular customer application. Since it ispossible 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 mismatchbetween the values. Mismatches of this kind where one type is more restrictive than the other, for example DateTime and Date, may lead to dataloss. In case of non-compatibility between an EDM type and an ABAP type, an error message is displayed.

More InformationFor information about defining navigation properties for entity types, see Navigation Properties.

1.4.3.1.1 Mappings and the ABAP Type EditorUse 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 orComplex Type , Explicit Assignment or Determination by Runtime Object Generator that is to be used. If you choose Structure Binding at Entity or ComplexType , 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 theentity type or complex type is subsequently used by the generator. If an ABAP structure is not assigned at design time, the generator will subsequently generatea new structure based on the type information displayed. If you choose Explicit Assignment , you can maintain the category and subsequently the fields that areapplicable 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 anautomatic 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 correspondingABAP or EDM type might not be a perfect match. Consequently, you must always review determined type mappings to ensure that you choose the best matchpossible. The Service Builder includes a validation check that determines possible inconsistencies and appropriate warning messages are displayed so you canprevent 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 potentialloss of data, possible conversion errors, and the applicability of ABAP types.

Mapping ABAP Types and EDM TypesThe following example focuses on ABAP Datetime handling for properties with Edm.Datetime as just one example where inconsistencies can arise whenmapping 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 withfractional seconds or a timestamp without fractional seconds. Consequently, a property in the Service Builder with the EDM type Edm.Datetime requiresadditional 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 typedirectly. 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)

Label SAP annotation for projects of type Service with SAP Annotations . Enter alanguage-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 theinput 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 entityor complex type, this denotes a component of this structure. Enter the ABAP fieldname. If you have imported the entity type, this field contains the ABAP field name inuppercase. 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 tobe 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 atelephone number or a fax number.

Value Collection Indicates whether or not the imported vocabulary includes a property for which acollection of values (multiple entries) exists. Applies to projects of type Service withVocabulary-Based Annotations . This field is read-only in the properties for view forthe data model.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 13 of 65

Page 14: 2-SAP NetWeaver Gateway Service Builder

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 canmanually 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 aDDIC 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 Importfrom 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 type P length 11 decimals 7

Refer to the following EdmType usage and conversion to backend ABAP type:

Table 1: EdmType Usage and Conversion

NoteIf 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 thesame ABAP name as the element name of the ABAP structure. When using Datetime and its related properties as an optional field, set the attributeNullable to true.

1.4.3.2 Navigation Properties

IntroductionThe Entity Types includes one or more Navigation Properties. Navigation Properties describe the navigation path between the relationship of an entity. It is theproperty 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 thenavigation 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 oneentity to another via an association.

Creating Navigation Properties

ProcedureTo create a Navigation Property for Entity Types proceed as follows:

NoteCreate Entity Types before creating Navigation Property. The Navigation Property folder displays only when an entity type is added. See Entity Types forcreating entity types.

1. Open the Service Builder.2. Expand the Data Model folder in the tree view of your project.3. Expand the Entity Types folder to view the entity types.4. Expand the listed entity types to view the Navigation Properties folder.5. 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 Insert Row button to create a new association.

A row will be added.

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

Edm.DateTimeOffset dateTimeOffsetLiteral DateTimeOffset as Timestamp PACKED LENGTH 8, DECIMALS 0,PACKED LENGTH 11, DECIMALS 7

Edm.Time timeLiteral Duration in seconds PACKED, DECFLOAT16, DECFLOAT

Duration as Time TIME

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 14 of 65

Page 15: 2-SAP NetWeaver Gateway Service Builder

A row will be added.8. Do the following in the mass edit view under Navigation Properties :

NoteIn 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 isdisplayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.

9. Save the changes

More InformationSee Associations for more information on additional functions.

1.4.4 Complex Types

UseUse complex types to define structured properties for entity types or other complex types without exposing complex types themselves as independent ODataentities.

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

Unlike entity types, complex types cannot form either end of an association between data objects, and therefore you cannot define navigation properties forcomplex types. However, complex types can contain other complex types, meaning that they can have a deep structure. Within a complex type the cardinality isalways 1:1.

Complex types comprise:

A unique nameProperties (optional)

ExampleA complex type structure called Fullname could comprise two properties, firstname and lastname .

Creating a Complex Type

ProcedureTo 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. Expand the Data Model folder in the tree view of your project.2. Double-click the Complex Types subfolder to open the mass maintenance view.3. Choose Edit and then Insert Row to add a new row to the table for the new complex type.4. 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 toreuse 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 notselected. 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 toenter 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.

NoteIn 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 isdisplayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.

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 toselect 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 ReferenceEditor enables you to enter the reference type.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 15 of 65

Page 16: 2-SAP NetWeaver Gateway Service Builder

To delete an existing complex type, select the relevant row in the mass maintenance view and choose Delete Row .

Creating Complex Type PropertiesAfter 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

ConceptAn Association is a named relationship between two or more Entities. Association defines a peer-to-peer relationship between participating Entity Types and cansupport different multiplicities at both the ends. An example of an association is the relationship between the Customer and Order entities. The Service Builderprovides 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 WizardUse the Association wizard to quickly define the following for a data model:

AssociationsAssociation SetsReferential ConstraintsNavigation Properties

Using the Mass Edit ViewCreate 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.

NoteMake 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 nameSpecifies 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 EntityThe Principal Entity represents the leading end of the association.

Entity Type NameSpecifies the name of the entity type for the new association. The entity at this end of the association can exist independently of the entityon the dependent end of the association.Press F4 to select the entity type.CardinalitySpecifies 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..1Only one instance occurs, zero is also allowed.1One-to-one relations. Exactly one instance occurs.M: 1..nOne-to-many relations. One or more instances can occur.N: 0..nZero-to-many relations. Zero or more instances can occur.

NoteMany-to-many relations is not supported in the wizard.

Create related navigation propertyOptional. 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 PropertyAvailable 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 EntityThe Dependent Entity represents the secondary part of the association.

Entity Type NameSpecifies 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

Page 17: 2-SAP NetWeaver Gateway Service Builder

The entity at this part of the association exists only if an entity type has been defined for the Principal EntityCardinalitySpecifies 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 propertyOptional. 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 PropertyAvailable 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.

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

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

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

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

NoteIn 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 isdisplayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.

6. You can also use additional functions available in the mass edit view as described in the table below:

7. Click to save the association.The new Association will appear under the Associations folder in the tree view.

Fields Description

Name Enter a name for the new association in this field.

NoteAn 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 anassociation 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 FromRole 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 ToRole 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 serviceis consumed.

Label Text Reference Editor To define the label, use the Label Text Reference Editor. The Label Text Reference Editorenables you to enter the reference type.

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

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 17 of 65

Page 18: 2-SAP NetWeaver Gateway Service Builder

NoteGenerated services based on BOR and RFC data sources in the Service Builder support navigation between entities within the same service, and betweenentities 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 InformationSee Including an OData Service.

See Navigation Properties

See Referential Constraints

See Association Sets

1.4.5.1 Referential Constraints

IntroductionA referential Constraint can be used to specify the foreign key relationship for 1:1 or 1:n associations.

Creating Referential Constraints

ProcedureTo create Referential Constraints proceed as follows:

1. Open the Service Builder.2. Expand the Data Model folder in the tree view of your project.3. Expand the Entity Types folder to view the entity types.4. Expand the entity types to view the Navigation Properties folder .5. 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:

NoteYou have to add one mapping for each Key Property of the Principle Entity Type.

NoteTo create Referential Constraint, both the Principle and Dependent Property fields are mandatory.

NoteIn 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 isdisplayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.

9. Save the changes.

More InformationSee Associations for more information on additional functions.

1.4.6 Entity Sets

Use

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 anexisting 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 Keyproperty of the principle Type. Use the input help to select an existing property.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 18 of 65

Page 19: 2-SAP NetWeaver Gateway Service Builder

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

ProcedureAlternatively, use the following steps:

1. Expand the Data Model folder in the tree view of your project.2. Double-click the Entity Sets folder to open the mass maintenance view.3. 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.4. 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:

8. Choose Save to create the new entity set.

NoteIn 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 isdisplayed, 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

IntroductionAn Association Set groups Association instances (similar to how an Entity Set groups Entity Type instances). Hence, it specifies a relationship between two EntitySets based on the respective Entity Types of the underlying Association.

ExampleAssuming you have a 1:n association Author_To_Books based on Entity Types Author and Book there may be an Association Set WrittenBy for theEntity Sets Authors and Books , as well as another Association Set FictionWrittenBy for the Entity Sets FictionAuthors and FictionBooks . This means ifyou 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 theFictionAuthors 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

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

Updatable Select this checkbox to indicate that updating is supported by your serviceimplementation.

Deletable Select this checkbox to indicate that deletion is supported by your serviceimplementation.

Pageable Select this checkbox to indicate that paging is supported by your serviceimplementation.

Addressable Select this checkbox to indicate that the addressable function is supported by yourservice implementation.

Searchable Select this checkbox to indicate that searches are supported by your serviceimplementation.

Subscribable Select this checkbox to indicate that subscriptions are supported by your serviceimplementation.

Requires Filter Select this checkbox to indicate that a filter is required by your serviceimplementation. If you select this checkbox, the entity set cannot be accessed directlyand cannot be queried without a $filter expression.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 19 of 65

Page 20: 2-SAP NetWeaver Gateway Service Builder

ProcedureTo 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 arealso 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 :

NoteIn 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 isdisplayed, which lists the group descriptions and corresponding cell content. The information displayed in this popup is read-only.

6. Save the changes.

More InformationSee Associations for more information about additional options.

1.4.8 Function Imports

UseThe 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 bemapped to the standard CRUD operations. You can implement such additional service operations in the Service Builder by creating function imports within yourdata model.

For example, you could create function imports for the following custom operations:

Confirm Work ItemCheck 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.

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

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

Dependent Entity Set Name Enter the name of the Dependent Entity Set for which the association set has to becreated.

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 ReferenceEditor enables you to enter the reference type.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 20 of 65

Page 21: 2-SAP NetWeaver Gateway Service Builder

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 typeEntity typeNo 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 anexisting 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 yourproject. 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

UseYou define function import parameters in SAP NetWeaver Gateway Service Builder to fine tune new function imports you have created that will invoke the requiredcustom 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.

OverviewYou can define the following parameters:

1.4.9 Working with AnnotationsExplains 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 byan 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. Whileannotations provide precise instructions as to how a data model should be consumed they also act as an extension point to provide additional information that isuseful 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 bepossible 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 aresupported 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.

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 dataelement, its type attributes will be reflected in the resulting OData service metadata. Thisis provided that you do not overwrite the type attributes by specifying a maximum lengthfor the function import parameter explicitly.

Precision Enter the number of decimal places permitted for numeric data types. The value definesthe maximum number of decimal places permitted to the left and right of the decimalpoint.

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 tospecify 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 telephonenumber or a fax number.

Unit Reference Parameter Enter the unit reference to be used. For example, if the parameter comprises a numberthat refers to a currency or amount, you can specify the currency or unit of measure thatis to be used.

Label Enter a label text to be displayed at runtime.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 21 of 65

Page 22: 2-SAP NetWeaver Gateway Service Builder

Annotation CompositionPut 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 thisreason, only one annotation may exist for a particular artifact in a data model. Essentially, annotations provide you with much greater freedom to define moreprecise and explicit information about an artifact than the definition of core attributes alone can allow. Annotations are consolidated in vocabularies and care shouldbe taken to ensure that the newly defined annotations can be clearly understood by a wide audience.

Annotations in Service Builder ProjectsWhen 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 standardvocabulary files in the /IWBEP/ namespace for vocabulary-based annotations, but you can also upload customer-specific vocabulary files for greaterflexibility. Use the standard vocabulary files as a template for defining your own vocabulary files if required. You can import one or more of the vocabularyfiles from the Vocabulary Repository to your data model contained in the Service Builder project.

NoteThe project type you define when you create a new project cannot be changed at a later time.

Related InformationCreating a Service Builder ProjectUploading Vocabularies into the Vocabulary RepositoryAdding Vocabulary-Based Annotations to Data Model Artifacts

1.4.9.1 Uploading Vocabularies into the Vocabulary RepositoryInstructions for uploading a vocabulary file into the Vocabulary Repository.

ContextIf you want to use customer-specific annotations in addition to core attributes (SAP annotations) when defining data model artifacts in Service Builder projects, youcan upload the annotations you require collectively in the form of a vocabulary file into the Vocabulary Repository. The Vocabulary Repository already includes aselection of standard vocabulary files and these are available in the /IWBEP/ namespace. You can import the annotations contained in a vocabulary file intoService Builder projects of type Service with Vocabulary-Based Annotations . After you have imported the relevant vocabulary files into your project, you can usevocabulary-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:

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

ResultsSubsequently, the uploaded vocabulary file can be imported into Service Builder projects of type Service with Vocabulary-Based Annotations so the termsdefined in this file can be used to annotate data models.

Related InformationImporting a Vocabulary FileAdding Vocabulary-Based Annotations to Data Model Artifacts

1.4.9.2 Importing a Vocabulary FileInstructions 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

Page 23: 2-SAP NetWeaver Gateway Service Builder

ContextAfter 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:

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

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

NoteParsing 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 addingvocabularies 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 theImplicit References folder.

Related InformationCreating a Service Builder ProjectUploading Vocabularies into the Vocabulary RepositoryAdding Vocabulary-Based Annotations to Data Model Artifacts

1.4.9.3 Adding Vocabulary-Based Annotations to Data ModelArtifactsExplains how to add vocabulary-based annotations to data model artifacts in the Service Builder.

ContextAdd vocabulary-based annotations to data model artifacts such as complex types, entity types, and associations, for example, to specify information about aparticular artifact that would not be possible using core attributes alone. To add vocabulary-based annotations, you can use the vocabulary files available in theVocabulary Repository as standard in the /IWBEP namespace or you can define and upload customer-specific vocabulary files. For example, you might want touse ths standard vocabulary Ord.OData.Aggregation.V1 to add the annotations LeveledHierarchy or RecursiveHierarchy to entity types for whichotherwise 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 modelprovided 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 typeService 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 Vocabulariessubfolder includes:

Imports subfolder that lists the name of the vocabulary files explicitly imported from the Vocabulary Repository to the data model. For each importedvocabulary 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 definedterms.

Double-click the Vocabularies subfolder to display the available vocabularies in an overview table in the mass maintenance view. This overview displays thevocabulary ID, version, namespace, and a description (if available). Futher, nestled inside each subfolder for a particular entity type or complex type, forexample, in the data model, an Annotations subfolder exists that lists the imported vocabularies and specifies the number of applicable terms each vocabularydefines 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 givenartifact, the vocabulary is displayed in a grey (as opposed to black) font and the following descriptive text is displayed, Vocabulary does not define applicableterms 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:

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

Page 24: 2-SAP NetWeaver Gateway Service Builder

vocabularies includes applicable terms for entity sets, for example, this pushbutton is not enabled. After you have selected the vocabulary you want to usefor 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.

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

4. To display detailed information (annotation data, term type, and expression value) about an annotation, double-click the annotation. The annotation data isthen displayed in an additional table. If you want to display detailed information about all the annotations created for a particular entity set, double-click theentity set itself.

5. If you want to delete any annotations, select the relevat rows or cells and choose the Delete Annotation pushbutton.6. 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 InformationImporting a Vocabulary File

1.5 Data Modeling Options

UseSAP NetWeaver Gateway Service Builder provides a variety of data modeling options to simplify the data modeling process for you significantly by enabling youto reuse existing data models or redefine existing services. Depending on your development experience and the time you have available, you can choose whichoption is best suited to your needs.

Options for Reusing Data ModelsIf 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 ServicesIncluding an OData Service (Gateway)

1.5.1 Importing a Data Model

Introduction

UseThe 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 metadatafiles 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 beoverwritten.

PrerequisitesEnsure 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

Page 25: 2-SAP NetWeaver Gateway Service Builder

More InformationFor 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

ProcedureTo 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 theleft-hand screen area.

NoteFor 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

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

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

NoteIf 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

Page 26: 2-SAP NetWeaver Gateway Service Builder

Importing a Model File - Existing Project

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

ActivitiesYou 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

UseTo reduce the time required to create complex types and entity types in your data model, the Service Builder provides you with an Import DDIC Structurefunction 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:

ViewsDatabase tablesStructures

ProcedureImporting the DDIC Structure comprises three steps:

Import the DDIC StructureSelect the parameters from the DDIC StructureModify 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

Page 27: 2-SAP NetWeaver Gateway Service Builder

2. Open transaction SEGW.The SAP NetWeaver Gateway Service Builder opens.

3. Create a new project. For more information, see Creating a Service Builder Project4. 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 thecreation 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 field2. 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.

NoteInput help (F4 Help) is not available for class/interface-based type structures End of the note.

4. Click Next to proceed.

NoteIf 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, DDICassignment 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 entitytype/complex type.

10. The Modify Entity Type screen provides the following editable and non-editable information:Table 1: Modify Entity Type Screen Details

NoteThe 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 byunselect 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 Entitytype name is E1 then the default entity set name will be E1Set. End of the note.

11. Choose Finish.ResultThe 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

UseTo reduce the time required to create entity types in your data model, SAP NetWeaver Gateway Service Builder provides you with the Import RFC/BOR Interfacefunction 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 theprocess. 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:

Name Description

ISEntity If the property belongs to the entity type, this check boxis selected. If it is not selected, the property belongs tothe complex type.

Non-Editable

Complex/Entity Type Name This is the name of the property. It can either be acomplex type or entity type

Editable

ABAP Name This is the technical name. This will not be displayed inthe metadata.

Non-Editable

Is Key Indicates whether the imported property is to be importedas a key of the entity type. Each entity type must defineat least one key property.

Editable

Name Name of the property Editable

Label Name of the property Editable

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 27 of 65

Page 28: 2-SAP NetWeaver Gateway Service Builder

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 thecreation 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 field2. 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 RFCDestination 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 forLocal option.

NoteIn cases when a model is created using the Import RFC/BOR function and later has to be transported to another system where the DDIC objectsmay not be available, it is recommended to create the model using the RFC destination as NONE. If the RFC destination is NONE, then no DDICobjects will be assigned to the entity type and the individual data element assignment to the properties (in the ABAP type editor) will not happenand 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 toretrieve 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 helpavailable for this field.

6. Choose Next to proceed.

NoteIf 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 wizardappears.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 typesTables types are imported into the Service Builder as new entity typesProperties are defined for the entity type and complex type importedTo 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 thecorresponding 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 theComplex Type/Entity Type. Whereas, if the Target System is Remote, then the DDIC structure assignment will not happen.

RecommendationThe new entity type if created with a structure assigned to it has the following advantages:

Conversion exit routines are used automaticallyLabels are used from the DDICIn the DPC class, the RFC or BOR interface parameters with structure or table types can be directly assigned instead of using move-corresponding.

NoteThe parameters marked as mandatory are mandatory in the data source.

NoteUnselected parameters can be selected later by using the Import Properties function as mentioned in the Importing Properties sectionbelow.

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

NoteThe 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

Page 29: 2-SAP NetWeaver Gateway Service Builder

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:

NoteThe 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 byunselect 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 Entitytype 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 automaticallyLabels are used from the DDICIn the DPC class, the RFC or BOR interface parameters with structure or table types can be directly assigned instead of using move-corresponding.

Name Description Edit Status

Is Entity If the property belongs to the entity type, this check boxis selected. If it is not selected, the property belongs tothe complex type.

Non-Editable

Complex/Entity Type Name This is the name of the property. It can either be acomplex type or entity type

Editable

ABAP Name This is the technical name. This will not be displayed inthe 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 importedas a key of the entity type. Each entity type must defineat least one key property.

Editable

Label This is the label for the properties which will bedisplayed in the metadata.

Editable

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 29 of 65

Page 30: 2-SAP NetWeaver Gateway Service Builder

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

NoteThe Service Builder runs an OData compliance check. The appropriate information messages resulting from the check are displayed. Double click themessage 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.

NoteIf 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 thetransported 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 beused to import more properties from the same data source.

NoteImporting 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 SourceIn 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

Page 31: 2-SAP NetWeaver Gateway Service Builder

ContextOnly 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 allowsyou to do the following:

Import the search help parametersCreate OData model entities based on the imported search help parametersMap 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 ParametersYou 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 asearch 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:

Procedure1. 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 theresult 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 hasbeen selected (flagged) for EXPORT, that parameter is presented in the results list. The implemented logic relates to the search help definition in thedata 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 acorresponding 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 StepsMapping Search Help ParametersYou 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 bemapped 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 ofeach 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 aconstant value.

ConstraintsThe 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 InformationImporting a Data ModelCreating the Mapping

1.5.5 Including an OData Service

Introduction

UseWhen 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 theIncluding 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

Page 32: 2-SAP NetWeaver Gateway Service Builder

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:

CustomerProduct

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

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

NoteTo add further models, repeat the steps listed above.

8. Double-click the included model, which can be found under the project Folder Data Model Model References to view it in the massmaintenance view.The details of the referenced model are displayed in the mass maintenance view.

NoteThe 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. Open the Service Builder.2. Expand the Data Model folder in the tree view of your project.3. Double-click the Association folder to open it in the mass maintenance view.4. 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.

NoteAn 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 associationbetween the entities of the model that has been included in the Service Builder.

NoteYou 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

Page 33: 2-SAP NetWeaver Gateway Service Builder

NoteDepending on your requirements for the new association, you can enter either the details of the Principle Entity or Dependent Entity orboth. 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 Entityis 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 andselect the model reference node name. The input help displays the model reference node name of all the included models. On selectingthe 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 isrequired only for the models whose metadata will be available in an external system, for example if you include a Gateway servicecreated 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 isfrom 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 andselect the model reference node name. The input help displays the model reference node name of all the included models. On selectingthe 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 isrequired only for the models whose metadata will be available in an external system, for example if you include a Gateway servicecreated 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.

NoteYou 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:

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 InformationFor more information, see Generating Runtime Objects.

1.6 Redefining Services

Fields Description

Association Name Enter a name for the new association in this field.

NoteAn 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 creatingan association with the entities of the model that has been included in the ServiceBuilder.

Principal Entity Enter the name of the principal entity, the entity which is being considered for theFrom Role in the new association. For an external association, if an included model isselected 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 ToRole in the new association. For an external association, if an included model isselected 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 theservice is consumed.

Label Text Reference Editor To define the label, use the Label Text Reference Editor. The Label Text ReferenceEditor enables you to enter the reference type.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 33 of 65

Page 34: 2-SAP NetWeaver Gateway Service Builder

UseThe Service Builder allows you to redefine both OData services created using SAP NetWeaver Gateway and the external services (SPI, BW Query, GenIL) thathave been created using different frameworks.

More InformationSee 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 BuilderExtend the OData services by customizing the generated source code using "Redefine" functionality in the SAP NetWeaver Gateway Service Builder (ServiceBuilder-transaction SEGW)Generated Model Provider Classes- An OverviewWhen redefining a service, a new OData service generates a new Model Provider Class (MPC), and a new Data Provider Class (DPC). The MPC includes theMPC 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) aregenerated 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 ofthe 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 inthe extension class of the extended service ( MPC_EXT B ). The runtime behavior of the newly added properties, entities, function imports and associations canbe handled in the data provider extension class of the extended service ( DPC_EXT B ).Use Cases for Redefining ServicesThis 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 willbe 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 entityUse case 2: Adding a new entityUse case 3: Adding a new Function importUse 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:

SalesOrderSetSalesOrderItemSetSalesOrderProviderSet

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.

NoteIf the metatdata of the selected service resides in another system, then select Metadata to be fetched from an external system. in the Target System forMetadata. On selection of the Metadata to be fetched from an external system the RFC Destination field becomes editable to select the RFC destinationof 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

Page 35: 2-SAP NetWeaver Gateway Service Builder

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 EntityThe 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 structureEntity bound to a DDIC structureDo 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.OROpen the Define_ Entity Name Method in either the _MPC_EXT or _MPC from the Runtime Artifacts folder and check if the following code snippetis 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 MOVEcommand, (either single MOVE, or MOVE-CORRESPONDING) to assign a value to ER_ENTITY, it will be sufficient to extend the DDIC structure, and to extendthe 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 TOer_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_order_item_table.DATA ls_et_order_item TYPE LINE OF zif_zsales_order_get=>zsales_order_item_tableDATA 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 objectio_tech_request_context->get_converted_keys(IMPORTINGes_key_values = ls_converted_keys).*Maps key fields to function module parameterslv_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'EXPORTINGiv_sales_order_item = iv_sales_order_itemiv_sales_order_id = iv_sales_order_idIMPORTINGet_order_item = et_order_itemEXCEPTIONS system_failure = 1000 messagelv_exc_msgOTHERS = 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 tableREAD 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.

NoteIf the service has not been implemented using the MOVE or MOVE-CORRESPONDING commands, the DPC (extension class) of the extended service hasto 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

Page 36: 2-SAP NetWeaver Gateway Service Builder

Entity bound to a DDIC structureYou 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 themodel.

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 structure1. Enter the transaction SE11, and choose Data Type , and then enter the name of the structure you want to enhance2. Click Display . In our example, the structure is, ZSALES_ORDER_ITEM3. 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 fieldsNETVALUE 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 theoriginal 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, ExplicitEnhancement Point or BADI, you can use it instead of redefining the class method.

NoteConversion Exits work without any code change for the newly added properties.

Entity not Bound to a DDIC StructureThe 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.

NoteThe 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 theMPC 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 classto,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 classto,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 classto,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

Page 37: 2-SAP NetWeaver Gateway Service Builder

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

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 callthe backend twice; once for the SAP provided fields, and then again for the additional fields.

Redefine the Dispatching MethodsThe next process is to redefine each dispatching method in the DPC (extension) class. There are typed methods with MPC type, and dispatching methods. Atruntime 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 thenew 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_entitysetTYPE 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 methodsalesorderset_get_ent_ext(EXPORTING iv_entity_name = iv_entity_nameiv_entity_set_name = iv_entity_set_nameiv_source_name = iv_source_nameit_key_tab = it_key_tabit_navigation_path = it_navigation_pathio_tech_request_context = io_tech_request_contextIMPORTING er_entity = salesorderset_get_entityset ).IF salesorderset_get_entityset IS NOT INITIAL.* Send specific entity data to the caller interfacecopy_data_to_ref(EXPORTINGis_data = salesorderset_get_entitysetCHANGINGcr_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_entityEXPORTINGiv_entity_name = iv_entity_nameiv_entity_set_name = iv_entity_set_nameiv_source_name = iv_source_nameit_key_tab = it_key_tab it_navigation_path = it_navigation_pathio_tech_request_context = io_tech_request_contextIMPORTINGer_entity = er_entity.CATCH /iwbep/cx_mgw_busi_exception.* todoCATCH /iwbep/cx_mgw_tech_exception.* todoENDTRY.ENDCASE.ENDMETHOD.

Use Case 2: Adding a New EntityThe 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

Page 38: 2-SAP NetWeaver Gateway Service Builder

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

Page 39: 2-SAP NetWeaver Gateway Service Builder

ENDMETHOD.

Use Case 3: Adding a New Function ImportThe 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,</IWBEP/IF_MGW_CORE_SRV_RUNTIM =>EXEC_SERVICE_OPERATION>, and write your own code for

the newly added function import and call the super class </IWBEP/IF_MGW_CORE_SRV_RUNTIM =>EXEC_SERVICE_OPERATION> method for thefunction imports inherited from the base service

Use Case 4: Adding an Association and a Navigation PropertyThe 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 ConditionsThe following are the enhancement processes for extending an OData service by adding a new function import to the data model:

1. In the redefined service, RFC mapping editor cannot be used for DPC generation.2. 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.3. Redefining a composed service is not supported.4. DIC binding is not supported when the Backend system is different from the IW_BEP & IW_FND system.5. 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.6. Redefining a service from another BEP system is not supported.

Related InformationFunction ImportsRedefining OData Service (GW)Creating a Service Builder ProjectDefining PropertiesAssociations

1.6.2 Redefining OData Service (GW)

Overview

UseThe Service Builder allows you to redefine the OData services for SAP NetWeaver Gateway. The Redefine Gateway Service function allows the user to do thefollowing:

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 artifactsfrom 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 thatare 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 viewallowing the user to select the required artifacts (entity types, associations, function imports) for the new model. The Modification Generator enables the user tomake 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, theModification 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.

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

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

Page 40: 2-SAP NetWeaver Gateway Service Builder

the external system using the input help.10. Click Next to continue.

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

NoteSince 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 "ToOverwrite 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 adata 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 existingmodel 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) .

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

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

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 ofthe external system using the input help.

12. Click Next to continue.

NoteIf 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 overwritingthe 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, theTechnical 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 read-only.

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

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 ofthe external system using the input help.

9. Choose Next to continue.

NoteIf 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

Page 41: 2-SAP NetWeaver Gateway Service Builder

10. On successful validation of the RFC destination, the Wizard Step 2 of 2: Redefine Service opens.

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

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

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 ofthe external system using the input help.

11. Click Next to continue.

NoteIf 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/functionimport. The reverse is not selected. For example, consider the following model:

ExampleCOMPLEX TYPES

complex_type_1complex_type_2

ENTITY TYPESentity_type_1entity_type_2entity_type_3

ASSOCIATIONSassociation_1 (between Entity_type_1 & Entity_type_2)association_2 (between Entity_type_1 & Entity_type_3)

FUNCTION IMPORTSfunction_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 alongwith 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 createdunder 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 beextended.

NoteIf 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

Page 42: 2-SAP NetWeaver Gateway Service Builder

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.

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

NoteGeneration 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). ThisMPC 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 registeredagain 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 InformationSee 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, BWQuery, GenIL)

Introduction

UseThe Service Builder allows you to create a service and model from different external frameworks (integration topics) and redefine the service and model withouthaving to navigate to a different transaction. This function comprises three steps:

Specify the parameters for the selected external frameworkGenerate the serviceRedefine 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 softwarecomponents they might not be available in every system.

NoteBased 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 ServiceThe following screen opens for the Redefine SPI Service .

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 42 of 65

Page 43: 2-SAP NetWeaver Gateway Service Builder

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 metadataprovisioning options are used to obtain the metadata.

4. Choose Next.Service Generator for BW Query ServiceThe 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 ServiceThe 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

Page 44: 2-SAP NetWeaver Gateway Service Builder

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:

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.

NoteChoose 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 respectivefolders in the tree view of the Service Builder. Also, the name and the version of the service selected for redefinition are displayed in the ModelReferences folder.

More InformationSee Redefining OData Service (GW)

See Generating Runtime Objects

See Service Maintenance

1.7 Service Implementation

UseThe 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 serviceas reflected in the Data Provider Class.

The sub tree consists of the following:

<Entity Set Name >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:

Fields Description

Package Enter the target package name. This is the package in which the generated modelprovider 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 toproceed 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 toproceed without entering a description.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 44 of 65

Page 45: 2-SAP NetWeaver Gateway Service Builder

DisplaySwitches between the ready-only and edit mode for the Service Builder.ChangeSwitches between the ready-only and edit mode for the Service Builder.DetailsThe 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:CreateGetEntity (Read)GetEntitySet (Query)UpdateDelete

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 BuilderChange: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 classand 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 andmethods.

More InformationCreating the ABAP Classes and Registering the Service

Mapping to a Data Source

1.7.1 Redefining Methods of the Operations

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

CautionChanges 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, canresult 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 Builderscreen (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

Page 46: 2-SAP NetWeaver Gateway Service Builder

ExampleRedefining 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 theapplication 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 mechanismThere 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

Page 47: 2-SAP NetWeaver Gateway Service Builder

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 specificimplementing method.Ref to DataAfter 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 InformationCreating the ABAP Classes and Registering the Service

1.7.2 Mapping to a Data Source

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

RecommendationWe recommend that, you familiarize yourself with the documentation for the specific SAP Remote Function Call ( RFC), or BAPI you want to map to an entityset.

More InformationImporting a Data Source (RFC/BOR Interface)

Creating the Mapping

1.7.2.1 Creating the Mapping

UseYou 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: <Business Object>.<Method>.

ProcessEach 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 theService Builder).

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 47 of 65

Page 48: 2-SAP NetWeaver Gateway Service Builder

This option is applicable only where Service Builder is deployed in the SAP NetWeaver Gateway hub system itself.

NoteThe Remote option is applicable only if SAP NetWeaver Gateway deployment is SAP NetWeaver Gateway with IW_BEPInstallation. 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 thatcontain 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 InformationMapping 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

FeaturesYou can create and edit your mappings in the Mapping UI.

The Mapping screen contains the following views:

Mapping table

NoteYou can quickly obtain an automatically generated mapping relationship using the Propose mapping button in the tool bar of the mapping table.

Data source view

NoteYou 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 tomap the data source.

Related InformationMap to Data SourceMapping TableData Source View

1.7.2.1.1.1 Mapping Table

UseThe 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 MappingEdit 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, GroupDescription 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

Page 49: 2-SAP NetWeaver Gateway Service Builder

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 <Name ofEntity Set>.Mapping screen helpOpens the help information for the mapping screen.Propose MappingAvailable 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 thedata source.Full Screen on/offChoose 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 DirectionSpecifies 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 theRFC 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. Youcannot 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 cannotchange it.If the data source parameter is a changing or table parameter, you must decide the direction of flow.

NoteIf 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 theparameter for input and another line for output.

Data Source ParameterSpecifies 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 youwant to map.

More InformationMapping UI

Data Source View

1.7.2.1.1.2 Data Source View

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

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.

NoteDo not map return tables or structures.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 49 of 65

Page 50: 2-SAP NetWeaver Gateway Service Builder

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

UseYou can delete the mappings for an operation of the entity set in the Service Implementation folder.

ProcessTo 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 InformationMapping to a Data Source

1.7.2.1.1.4 Mapping Rules

Implementation ConsiderationsIn the mapping between a data source and an entity set, Service Builder automatically performs certain checks to verify that the mapping you create is logicaland 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 datasource, 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 orchanging.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 theparameters 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 pathas 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 Readoperation.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 mappedCreate, 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 mappedUpdate, 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

Page 51: 2-SAP NetWeaver Gateway Service Builder

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.

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

ExampleFor 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 InformationCreating the Mapping

1.7.2.2 Setting Constant Values

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

RecommendationWhen you familiarize yourself with the documentation for the function or BAPI, you will get information about the parameter for which you can define a constantvalue.

ExampleFor 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_TRUEABAP_FALSESPACEInitial 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 thelatter 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 InformationPUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 51 of 65

Page 52: 2-SAP NetWeaver Gateway Service Builder

More InformationCreating the Mapping

1.7.2.3 Mapping the Query Operation

ProcedureWhen 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, forexample, 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 theparameters 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:

MAXROWSMAX_ROWSMAX_HITSMAX_LINESMAX_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 theunnecessary 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 tothe 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 parametertype.In case, the data source parameter is of type, changing, Service Builder does not automatically set the direction; you must manually set the mappingdirection.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.

ExampleA 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

Page 53: 2-SAP NetWeaver Gateway Service Builder

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

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

NoteNot 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 ismissing, 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 anddefines 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 forwhich 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.

NotePlace 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 CheckIf 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 orHigh.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

Page 54: 2-SAP NetWeaver Gateway Service Builder

Mapping to Data Source

Mapping the Query Operation

1.7.2.4 Mapping the Read Operation

ProcedureWhen 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 entityset 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 InformationImporting a Data Source (RFC/BOR Interface)

Creating the Mapping

1.7.2.5 Mapping the Create Operation

ProcedureYou 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 theparameters 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 InformationImporting a Data Source (RFC/BOR Interface)

Creating the Mapping

1.7.2.6 Mapping Delete or Update Operations

ProcedureWhen 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 datasource 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 theparameters 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 InformationImporting a Data Source (RFC/BOR Interface)

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 54 of 65

Page 55: 2-SAP NetWeaver Gateway Service Builder

Creating the Mapping

1.7.3 Implementation Support for AssociationIn 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 anentity type in the relationship.

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

ContextService Builder can generate code in the DPC base class that implements navigation at runtime, from any end of the relationship.

Referential Constraint

ContextThe 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

ContextNavigation properties enable users to traverse the association between two entity types. Where an entity has a navigation property, you can navigate between thatentity to the related entity in the relationship.

ExampleThe 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 customernumber is extracted. This is then used as a key in a call to get Customer details

1.8 Runtime Artifacts

UseFor more information about the runtime artifacts generated in the Service Builder for SAP NetWeaver Gateway, see:

Generating the ServiceGenerated ABAP Classes and Service Registration

1.8.1 Generating Runtime Objects

ConceptYou 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

Page 56: 2-SAP NetWeaver Gateway Service Builder

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 InformationCreating the ABAP Classes and Registering the Service

1.8.1.1 Creating the ABAP Classes and Registering the Service

ActivitiesYou automatically generate code for the runtime functionality of your data model. The Service Builder generates the classes with the generated code, and handlesthe 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_<PROJECT NAME>_MPC_EXT.3. Enter the name for the base class in the Base Class Name field. Proposed naming is, CL_<PROJECT NAME>_MPC

NoteThe 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 forthe DPC whenever you want.

NoteYou 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 <IF_>.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 interfacename 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 NameSpecify the Technical Model Name. This references the Model Provider Class which provides the metadata for the model.Technical Service NameSpecify the Technical Service Name. This is a key to assign the models to a Service.

NoteMake 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, itis 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 requestpackage, 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 folderof 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

Page 57: 2-SAP NetWeaver Gateway Service Builder

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 InformationOverview of the Generated ABAP Classes and Service Registration

BOP Interface Naming Rules

1.8.1.2 BOP Interface Naming Rules

Implementation ConsiderationsThe 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 charactersand 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

UseThe Service Builder uses patterns to separate between the generated logic and your own code.

It generates two types of classes:

Base ClassThe base classes contain the Service Builder generated logic. The logic in the base class is overwritten every time the project is regenerated.

CautionDo not modify the code in this class, as the Service Builder overwrites its contents.

Extension ClassThe 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 isgenerated 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 youwish 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 yourneeds.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.

NoteAfter 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 thespecific 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 metadatafor the service.Technical Service NameSpecifies 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

Page 58: 2-SAP NetWeaver Gateway Service Builder

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 Backend OData Channel Service Development for Backend OData Channel

Maintain Services .

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 InformationCreating the ABAP Classes and Registering the Service

1.8.1.3.1 Generated Classes for Model Provider Class

IntroductionThe Service Builder provides the user with the option of generating the Model Provider Class and Data Provider Classes. For Model Provider Class, when the userinitiates 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 NameClass Name

NoteThe 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 isunselected 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 ClassThe generated Base class always inherits its code from /IWBEP/CL_MGW_PUSH_ABS_MODEL which in turn inherits from /IWBEP/CL_MGW_ABS_MODEL. Thebase class CL__Project Name_MPC that gets generated will have redefinition for DEFINE() and GET_LAST_MODIFIED() methods. See Base Class: ModelProvider Class for more information.

Fields Description Naming Sample

Class Name - Implementation Class This is the Implementation class that inherits the Baseclass. This class can be modified manually.

CL_<Project Name>_MPC_EXTProject Name is the actual name of project in the ServiceBuilder.

Base Class Name This is the Base class that is generated by the systemduring the generation process.

NoteDo not modify this class manually

CL_<Project Name>_MPCProject Name is the actual name of project in the ServiceBuilder.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 58 of 65

Page 59: 2-SAP NetWeaver Gateway Service Builder

Implementation ClassThe Service Builder creates an extension class CL_<Project Name>_MPC_EXT for the MPC, which is the implementation class. The extension class isinherited 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 GatewayService Builder. See Extension Class: Model Provider Class.

Sample Model - Service BuilderThis is a sample model definition as seen in the Service Builder for project PROJECT_DEMO. A representation of the generated base and implementation classesafter the MPC generation is given in the Generated MPC Classes section below:

StructurePROJECT 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

Page 60: 2-SAP NetWeaver Gateway Service Builder

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 classis opened in SE24. Once the error is rectified delete the generated Model Provider Class before regeneration.

More InformationBase Class: Model Provider Class

Implementation Class: Model Provider ClassMPC Generation Using Inline AnnotationsAnnotation 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.

NoteThe Project Type should be Service with Vocabulary-Based Annotations.

Execute the steps provided in this section in-addition to the steps executed above.

Procedure

Procedure1. Create a Project with Type Service with Vocabulary-based Annotations.2. Import vocabularies as detailed in the Importing a Vocabulary Filesection.3. Click Generate Runtime Objects button to generate the MPC class.4. 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

Page 61: 2-SAP NetWeaver Gateway Service Builder

1. Simple value can be of type of one of the following String, Boolean, Integer, Path, Property path, Navigation property path. For simple valueannotation, 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

UseThe Base Class CL__Project Name_MPC that gets generated will have redefinition for DEFINE() and GET_LAST_MODIFIED() methods.

DEFINE () MethodThe content of the Define () method depends on the OData artifacts which are created for a model in SEGW (such as, entity types, associations, functionimports, complex types, and more). For each of the artifacts created, one method will be generated and called inside this Define () method.

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

Note1. 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 withunique 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 MethodA 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

Page 62: 2-SAP NetWeaver Gateway Service Builder

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

NoteThe 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 bemodified/redefined by the user in the extended class.

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 classand it is required for internal handling of overwrite scenario. Hence this method need not be modified/redefined by the user in the extended class.

1.8.1.3.1.2 Implementation Class: Model Provider Class

UseThe 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( ). <<Code for modifying the model - can use code patterns available>> Endmethod.

6. Save the changes.

1.8.1.3.2 Generated Classes for the Data Provider Classes

ActivitiesThe Service Builder automatically generates classes for the DPC once you generate the project.

The following are the classes:

Method Name LOAD_TEXT_ELEMENTS

Visibility Public

Final X

Parameter Name RT_TEXT_ELEMENTS

Method Name GET_EXTENDED_MODEL

Visibility Public

Final X

Parameter Name EV_EXTENDED_SERVICE Exporting

EV_EXT_SERVICE_VERSION Exporting

EV_EXTENDED_MODEL Exporting

EV_EXT_MODEL_VERSION Exporting

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 62 of 65

Page 63: 2-SAP NetWeaver Gateway Service Builder

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 theabstract 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 InformationCreating the ABAP Classes and Registering the Service

Redefining Methods of the Operations

1.8.1.3.2.1 Base Class: Data Provider Class

UseThe 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 , andRFC_SAVE_LOG.

CautionDo 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 smallnumber 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: <ENTITY SET NAME_OPERATION NAME>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.

NoteWhen 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 topoint 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 InformationCreating the ABAP Classes and Registering the Service

Redefining Methods of the Operations

1.8.1.3.2.2 Implementation Class: Data Provider Class

UseThe 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

Page 64: 2-SAP NetWeaver Gateway Service Builder

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.

ExampleIf you have a model for customer data and you want to implement the Get Entity operation, redefine the method, CUSTOMER_GET_ENTITY , and write yourown 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.

RecommendationWe recommend to redefine each method directly.

CautionChanges 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 inyour code, can result in syntax errors in your implementation.

More InformationCreating the ABAP Classes and Registering the Service

Redefining Methods of the Operations

1.9 Service Maintenance

Introduction

UseUse the Service Maintenance function in the Service Builder to register and maintain each service in an SAP NetWeaver Gateway system. This function alsoenables you to maintain services created and redefined directly in the Service Builder (in an SAP Business Suite backend system) as opposed to navigating toanother 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 .

ProcedureTo 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 ODataChannel Connection Settings to SAP NetWeaver Gateway SAP NetWeaverGateway 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 selectedsystem. The statuses are as follows:

Service Registered from this system - The service is registered fromthe 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

Page 65: 2-SAP NetWeaver Gateway Service Builder

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.

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

NoteError logs for the current service are displayed for all users on the current date.

There may be instances when a service with the same name as your serviceis already registered in the target SAP NetWeaver system. In such instancesthis status is shown.

Service not registered - The service is not yet not registered in thissystem. You can proceed and register the service in the current system.

Could not retrieve the registration status - There may be instanceswhen the target system's status could not be retrieved due to some technicalreasons, for example, due to system unavailability or authorization failure.

PUBLIC© 2014 SAP AG or an SAP affiliate company. All rights reserved.

Page 65 of 65