Академический Документы
Профессиональный Документы
Культура Документы
How-To Guide
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
ii
Typographic Conventions Icons
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
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
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
March 2014 3
How To Model a Gateway Service based on CDS View for ABAP using SADL
March 2014 4
How To Model a Gateway Service based on CDS View for ABAP using SADL
March 2014 5
How To Model a Gateway Service based on CDS View for ABAP using SADL
March 2014 6
How To Model a Gateway Service based on CDS View for ABAP using SADL
March 2014 7
How To Model a Gateway Service based on CDS View for ABAP using SADL
March 2014 8
How To Model a Gateway Service based on CDS View for ABAP using SADL
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
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.
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
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.
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).
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.
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.
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
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
March 2014 18
How To Model a Gateway Service based on CDS View for ABAP using SADL
March 2014 19
www.sdn.sap.com/irj/sdn/howtoguides