Вы находитесь на странице: 1из 25

SAP NetWeaver

How-To Guide

How To Model a Gateway Service based on


CDS View for ABAP using SADL

Applicable Releases:
SAP NetWeaver AS ABAP 7.4 SP5
Target Audience:
ABAP Developers
Version 1.0
February 2014
© Copyright 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 http://www.sap.com/corporate-
en/legal/copyright/index.epx#trademark for additional trademark information and notices.

SAP NetWeaver “How-to” Guides are intended to simplify the product implementation. While specific product features and
procedures typically are explained in a practical business context, it is not implied that those features and procedures are
the only approach in solving a specific business problem using SAP NetWeaver. Should you wish to receive additional
information, clarification or support, please refer to SAP Consulting.
Any software coding and/or code lines / strings (“Code”) included in this documentation are only examples and are not
intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax
and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein,
and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused
by SAP intentionally or grossly negligent.

Disclaimer:
Some components of this product are based on Java™. Any code change in these components may cause unpredictable
and severe malfunctions and is therefore expressively prohibited, as is any decompilation of these components.
Any Java™ Source Code delivered with this product is only to be used by SAP’s Support Services and may not be modified
or altered in any way.

i
Document History

Document Version Description


1.00 First official release of this guide

ii
Typographic Conventions Icons

Type Style Description Icon Description


Example Text Words or characters quoted Caution
from the screen. These
include field names, screen Important
titles, pushbuttons labels,
Note
menu names, menu paths,
and menu options. Recommendation or Tip
Cross-references to other
documentation Example
Example text Emphasized words or
phrases in body text, graphic
titles, and table titles
Example text File and directory names and
their paths, messages,
names of variables and
parameters, source text, and
names of installation,
upgrade and database tools.
Example text User entry texts. These are
words or characters that you
enter in the system exactly as
they appear in the
documentation.
<Example text> Variable user entry. Angle
brackets indicate that you
replace these words and
characters with appropriate
entries to make entries in the
system.
EXAMPLE TEXT Keys on the keyboard, for
example, F2 or ENTER.

iii
Table of Contents
1. Scenario ................................................................................................................................ 1
2. Background Information ..................................................................................................... 1
2.1 Service Adaptation Definition Language (SADL) and Business Entities ...................... 1
2.2 Core Data Services (CDS) for ABAP............................................................................ 1
2.3 Data Model ................................................................................................................... 2
3. Prerequisites ........................................................................................................................ 2
4. Step-by-Step Procedure ...................................................................................................... 3
4.1 Open SAPGUI within ADT ............................................................................................ 3
4.2 Create Gateway Project ............................................................................................... 3
4.3 Create Entity Type ........................................................................................................ 4
4.4 Create Entity Set........................................................................................................... 6
4.5 Service Implementation ................................................................................................ 7
4.6 Generate Runtime Objects ......................................................................................... 10
4.7 Service Registration ................................................................................................... 12
4.8 Testing Gateway Service ............................................................................................ 14
5. Appendix ............................................................................................................................ 18
5.1 Appendix A – Abbreviations ....................................................................................... 18
5.2 Appendix B – References ........................................................................................... 18
5.3 Appendix C – Link to ABAP for SAP HANA Reference Scenarios ............................ 18
5.4 Appendix D- Links to SAP NetWeaver Gateway Documents .................................... 19

iv
How To Model a Gateway Service based on CDS View for ABAP using SADL

1. Scenario
This guide will help you to create read-only OData Service, using SAP NetWeaver Gateway, which
consumes Core Data Services (CDS) view as its data model. This guide shows a model-based
approach of creating the service. The model-based approach substantially reduces the manual efforts
and thereby reducing the Total Cost of Development (TCD). This guide will assist you to:
 Create a OData Service using SAP NetWeaver Gateway
 Consume Core Data Services (CDS) view as data model
 Generate code for Read (GetEntity), Query (GetEntities) for an Entity Set thereby avoiding
manual effort of writing the code.

2. Background Information

2.1 Service Adaptation Definition Language (SADL) and


Business Entities
Service Adaptation Definition Language (SADL) is a framework, which enables consumption of
different business object models, and other entity-based models, in particular DDIC tables and views,
in a uniform way. Knowledge of the details of the modeling frameworks, such as Business Object
Process Framework (BOPF) or Business Object Layer (BOL) is not required. The SADL entity model
exposes all the required information to the gateway service. In Gateway, SADL entities are known as
Business Entities.
With SADL, it is possible to push down queries directly to the database, thereby improving response
cycle times. With SADL, very large amounts of data (millions of records) can be retrieved and
displayed quickly.
Using SADL framework, the Gateway transaction (T-Code) SEGW assists you to create an OData
Service without writing the code for Read (GetEntity), Query (GetEntitySet), Create, Delete, and
Update. As a Gateway developer, you need not understand the internals of SADL framework as
Gateway takes care of everything.

2.2 Core Data Services (CDS) for ABAP


Core Data Services (CDS) enhance SQL to allow defining and consuming semantically rich data
models, thereby improving consumption, performance and interoperability. CDS simplifies and
harmonizes the way you define and consume your data models, regardless of the consumption
technology. CDS in ABAP provides you with a data definition language (DDL) for defining semantically
rich database tables/views (CDS entities) and user-defined types in the database.

For several years for now, it is possible to define views in the ABAP Dictionary, but these views are
quite restricted. For example, you can only define inner join for database views. Outer joins are
available only for help and maintenance views. However, it is not possible to perform aggregations in
views or define nested views. With ABAP 7.4 SP05, a new editor is available to define views directly in
the Eclipse-based ABAP development environment. With this Source-based editor you can define
CDS entities, which can be consumed in ABAP programs using Open SQL.
The CDS View building provides another way of code pushdown using features that are similar as in
Open SQL. With CDS View building it is possible to define
1. Projections, aggregations, and groupings
2. Use expressions (like CASE), SQL built-in functions
3. UNION and UNION ALL and non-equi INNER JOINs
Nesting of Views with associations between the View entities (associations can be consumed in the
WHERE clause as well as in expression in Open SQL queries)

March 2014 1
How To Model a Gateway Service based on CDS View for ABAP using SADL

2.3 Data Model


Before getting started, you must generate data related to Enterprise Procurement Model (EPM). You
can use the transaction SEPM_DG_OIA to generate the data for EPM model. For more information
about EPM, see http://scn.sap.com/docs/DOC-31458
For creating OData service, use the CDS view SEPM_CDS_OPEN_INVOICE_REDUCED. The ABAP
view name of this CDS view is SEPMAPPS_CDS_OIR. This CDS view is part of the package
S_EPM_OIA_APPS_PROVIDER. This CDS view fetches all the Open Sales Orders – sales orders
whose payment is yet to be made by the Buyers. Buyer Name, Dunning Level, Overdue Invoice
Amount, Currency are some of the details retrieved for each of the Sales Order. Each Sales Order can
have one or more Sales Order Items and the invoice amount can be in different currencies. For a
given Sales Order ID the data is grouped by Currency and the aggregated invoice amount is
displayed.

3. Prerequisites
1. Knowledge of creating OData Service using SAP NetWeaver Gateway
2. SAP NetWeaver Gateway is configured and customized in SPRO transaction. Gateway must be
activated, System Aliases must be set with at least one entry for LOCAL system, Remote
Function Call (RFC) destination for local Gateway registration is configured and required
Gateway Settings are set
3. SICF service /default_host/sap/opu is activated
4. SAP NetWeaver (NW) version 7.4 SP5 or higher is installed
5. Knowledge of working with ABAP Development Tools (ADT)
6. Knowledge of NW Reference Scenario, Enterprise Procurement Model (EPM) will be useful
7. Knowledge of ABAP Core Data Services (CDS) and CDS View Building will be useful
8. Use ADT to connect to the ABAP system and thereby create ABAP project in the Project
Explorer [ABAP Perspective]. Refer to this link to follow step- by- step
processhttp://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/10e2502e-29f4-2f10-ab9a-
d34504de3ed7&overridelayout=true

March 2014 2
How To Model a Gateway Service based on CDS View for ABAP using SADL

4. Step-by-Step Procedure

4.1 Open SAPGUI within ADT


This step is for opening the SAP GUI within ADT. You can skip this step if you want to directly work in
SAP GUI instead of working in ADT as all the subsequent steps are SAP GUI based.
1. Open ABAP Development Tool (ADT) that is ABAP in Eclipse (AiE).
2. Go to the ABAP perspective.
3. Open the ABAP project corresponding to the ABAP AS where you want to create the OData
Service using SAP NetWeaver Gateway. You may have to provide ABAP username and
password if single sign-on is not enabled.
4. Press Ctrl + 6 or click on Open SAP GUI toolbar icon to open the SAP GUI within ADT. SAP
GUI Launcher dialog appears. Choose OK to open SAP GUI within ADT.

4.2 Create Gateway Project


First create a Gateway Project. Follow the steps below to create the project in SAP GUI / ABAP
Workbench.
1. Open transaction SEGW in SAP GUI. The transaction opens SAP NetWeaver Gateway Service
Builder.
2. Choose Create Project on the toolbar
3. Enter details in the Create Project dialog box.
i. Enter appropriate name for the field Project. In our example, project name used is
ZSAP_GW_SAMPLE_CONSUMING_CDS.
ii. Enter appropriate Description.
iii. Choose Local Object to create the Gateway project in the $TMP package. [If you want, you
can specify the package name in the field Package and then press Enter or choose
Continue]

March 2014 3
How To Model a Gateway Service based on CDS View for ABAP using SADL

4.3 Create Entity Type


The next logical step after creating the Gateway Project is to define the Data Model. In this
case, define the structure by importing it from the DDIC entity / CDS view. Follow the steps
below to define the Data Model for the Gateway service.
1. Right- click Data Model as shown in the screenshot below
2. Choose Import > DDIC Structure.

3. In DDIC Import dialog, enter details:

March 2014 4
How To Model a Gateway Service based on CDS View for ABAP using SADL

i. Select ABAP Structure as SEPMAPPS_CDS_OIR from the search help. This is


the ABAP Dictionary View name for the CDS View
SEPM_CDS_OPEN_INVOICE_REDUCED. After selecting, press Enter.
ii. Check As Entity Type, if not checked.
iii. Enter the name of the Entity as OpenInvoice.
iv. Set Usage for each of the fields as shown below:

Field Path Usage


MANDT Ignore
SO_ID Key
COMPANY_NAME Property
CURRENT_DUNNING_LEVEL Property
DUNLEV_LANGU Ignore
DUNLEV_DESCR Property
CURRENCY_CODE Key
GROSS_AMOUNT Ignore

4. You can now see the Entity Type OpenInvoice.

March 2014 5
How To Model a Gateway Service based on CDS View for ABAP using SADL

Choose Save button in the SAP GUI.

4.4 Create Entity Set

1. Right-click Entity Sets and choose Create.

March 2014 6
How To Model a Gateway Service based on CDS View for ABAP using SADL

2. Enter Entity Set Name as OpenInvoiceSet and EntityType Name as OpenInvoice.

3. Press Enter or click on the Continue button


4. You can now see the Entity Set OpenInvoiceSet created.

5. Click on Save button in the SAPGUI to save the changes.

4.5 Service Implementation


The next step is to provide mapping between the CDS View and the Entity Set. In this step you
will model the service implementation.
1. Expand Service Implementation. You will find OpenInvoiceSet under Service Implementation.
Right-click OpenInvoiceSet, which is under Service Implementation (i.e. open context menu of
OpenInvoiceSet) and choose Map to Data Source.

March 2014 7
How To Model a Gateway Service based on CDS View for ABAP using SADL

The Map to Data Source dialog box appears.

2. In the Map to Data Source dialog, enter the details as follows:


i. Choose Target System as Local.
ii. Choose Type as Business Entity.
iii. Provide CDS View name SEPM_CDS_OPEN_INVOICE_REDUCED with prefix
CDS~ in the Name field. You can also search and select the CDS view in the
available F4 help.

March 2014 8
How To Model a Gateway Service based on CDS View for ABAP using SADL

iv. Press Enter or click on the Continue button.

3. The Mapping Editor with two panels appears. You can use this editor to map the data source
elements (in our example, CDS View fields) to Entity Set properties.

4. Drag relevant data source elements (CDS view fields) from the right panel to properties of the
Entity Type OpenInvoice, which is displayed in the left panel, one at a time. Instead of drag and
drop, you can also select data source elements for each of the properties of Entity Type
OpenInvoice using F4 functionality. The screenshot below shows CDS view fields that have
been mapped to the properties of Entity Type OpenInvoice.

March 2014 9
How To Model a Gateway Service based on CDS View for ABAP using SADL

5. Click on Save button in the SAPGUI to save the changes.

4.6 Generate Runtime Objects


The next step is to provide service implementation. In this step you will see that the GW Model
and Data Provider classes are being generated and the code for GET_ENTITY and
GET_ENTITIES being automatically generated by the framework [i.e., zero coding].

1. Choose the button shown in the screenshot below for generating the runtime objects.
2. Model and Service Definition dialog appears displaying the default class names for Model
Provider and Data Provider. The dialog also shows default names for Technical Model and
Technical Service with version number. Keep all the defaults and press Enter or choose
Continue.

March 2014 10
How To Model a Gateway Service based on CDS View for ABAP using SADL

3. Choose Local Object when Create Object Directory Entry dialog appears. This will generate the
two Model Provider classes and the two Data Provider classes in $TMP package. Alternatively,
you can also specify the package where you want to generate these classes and press Enter or
choose Continue.
4. You should now see the success messages displayed with generation of the classes. The
classes appear under $TMP (or the package that you had chosen in the previous step).

March 2014 11
How To Model a Gateway Service based on CDS View for ABAP using SADL

5. Open the class ZCL_ZSAP_GW_SAMPLE_CON_DPC (or the class name that you had given
for data provider if you had changed the default class name. The default class name can be
different based on what Gateway project name has been provided by you in Create Gateway
Project step) to see the service implementation. The following methods are generated with the
business logic implemented:
i. OPENINVOICESET_GET_ENTITY
ii. OPENINVOICESET_GET_ENTITYSET
OpenInvoiceSet is the name of the Entity Set. The methods above correspond to
GetEntity and GetEntities of the Entity Set OpenInvoiceSet with Entity Type
OpenInvoice.

4.7 Service Registration


The next step is to register the Gateway Service with SAP NetWeaver Gateway Hub
System.
1. For registering the service, double-click on Service Maintenance node and choose Register.

A warning dialog as shown below pops up. Choose Yes.

2. Enter System Alias where service should be deployed. In our example, register the service in
the same system, so enter the System Alias as LOCAL.

March 2014 12
How To Model a Gateway Service based on CDS View for ABAP using SADL

Press Enter or choose Continue.

3. The Add Service dialog box with default values appear. Choose Local Object or type $TMP in
the Package Assignment field.
NOTE
You can also register the service in any other package. To register the service in a different
package, enter appropriate package details.

After Package Assignment, press Enter or choose Continue.

March 2014 13
How To Model a Gateway Service based on CDS View for ABAP using SADL

The Registration Status column appears Green. This indicates successful registration of
the Service with the Gateway Hub (in the example Gateway Hub is LOCAL system) and
to the Internet Communication Framework (ICF).

4.8 Testing Gateway Service


1. After registering the service, choose Maintain.

2. In the Activate and Maintain Services screen, choose Gateway Client.

3. In the SAP NetWeaver Gateway Client window, test the OData services created using Gateway.
Specify the HTTP method li ke GET, POST, PUT , and D ELET E.

i. Specify the Gateway service URI.

March 2014 14
How To Model a Gateway Service based on CDS View for ABAP using SADL

ii. Specify the HTTP Request body and view the HTTP Response.
In order to test the Gateway Service that you created, retain the URI specified in Request
URI field. Choose Execute.

You can see the HTTP Response for the Gateway Service.

4. To check the metadata, add $metadata to the URI i.e.,


/sap/opu/odata/sap/ZSAP_GW_SAMPLE_CONSUMING_CDS_SRV/$metadata. In this URI,
ZSAP_GW_SAMPLE_CONSUMING_CDS_SRV corresponds to Technical Service name of the
Gateway Service. Choose Execute. You can see the properties of the Entity Type OpenInvoice
and the Entity Set OpenInvoiceSet details.

March 2014 15
How To Model a Gateway Service based on CDS View for ABAP using SADL

5. To check the result of the Entity Set in the Gateway Service, specify
/sap/opu/odata/sap/ZSAP_GW_SAMPLE_CONSUMING_CDS_SRV/OpenInvoiceSet in
Request URI field and then choose Execute. The result shows the data of the CDS view. Thus,
using this procedure it is possible to create Gateway Service in a modeled approach [with zero
coding]. Note that to see the records you must generate the data in EPM data model as
specified in the section Data Model.

6. To test single record fetch, based on the key combination of CURRENCY_CODE and SO_ID,
specify
/sap/opu/odata/sap/ZSAP_GW_SAMPLE_CONSUMING_CDS_SRV/OpenInvoiceSet(Currency
Code='EUR',SoId='500034920') in Request URI field and then choose Execute. [In the URI,
currency code is specified as EUR and SO_ID is specified as 500034920. Change the value as
per the data generated in your system]. You can see that appropriate single record is fetched
from the service.

March 2014 16
How To Model a Gateway Service based on CDS View for ABAP using SADL

March 2014 17
How To Model a Gateway Service based on CDS View for ABAP using SADL

5. Appendix
Appendi x

5.1 Appendix A – Abbreviations

Abbreviation Description
ADT ABAP Development Tools
EPM Enterprise Procurement Model
NW NetWeaver
ABAP AS ABAP Application Server
SADL Service Adaptation Definition Language
CDS Core Data Services
TCD Total Cost of Development
GW Gateway
ICF Internet Communication Framework
BOPF Business Object Processing Framework
BOL Business Object Layer
URI Uniform Resource Identifier

5.2 Appendix B – References

 ABAP Development Tools Tutorials - Learn how to use ABAP in Eclipse:


http://scn.sap.com/docs/DOC-31815
 The NetWeaver Enterprise Procurement Model - An Introduction to EPM:
http://scn.sap.com/docs/DOC-31458

5.3 Appendix C – Link to ABAP for SAP HANA Reference


Scenarios

 ABAP for SAP HANA Reference Scenario - http://scn.sap.com/docs/DOC-35518


 ABAP for SAP HANA Reference Scenario: Implementing Open Items Analysis using SAP
Floorplan Manager - http://scn.sap.com/docs/DOC-47390
 ABAP for SAP HANA Reference Scenario: Implementing Mobile based Open Items Analysis
Using SAP UI5 and SAP Gateway Foundation Component - http://scn.sap.com/docs/DOC-
47388

March 2014 18
How To Model a Gateway Service based on CDS View for ABAP using SADL

5.4 Appendix D- Links to SAP NetWeaver Gateway


Documents

 SCN Link: http://scn.sap.com/community/netweaver-gateway


 How-To Guides: http://scn.sap.com/docs/DOC-27405

March 2014 19
www.sdn.sap.com/irj/sdn/howtoguides

Вам также может понравиться