Professional Documents
Culture Documents
SAP Fiori - Implementation and Development
SAP Fiori - Implementation and Development
Reading Sample
OData services help connect the SAP Fiori frontend to the SAP
S/4HANA or SAP BTP backend system. This sample chapter will pro-
vide an overview of OData, including new features in OData V4.
You’ll learn to model and generate OData services with step-by-
step instructions, primarily for SAP S/4HANA.
Contents
Index
The Authors
Understanding the concept and use of OData is extremely important for developing
your own SAP Fiori applications or troubleshooting any standard SAP Fiori applica-
tions, as the SAP Fiori UI interacts with the backend services based on the OData proto-
col. Although you can use a plain REST protocol or can use a custom approach to
consume data, using OData is the recommended approach for SAPUI5–based SAP Fiori
applications. In this chapter, we’ll explain the OData protocol, its main query options,
different ways of implementing an OData service, and how to test such a service before
using it in your SAP Fiori application. So, let’s begin our OData learning journey!
6.1.1 Overview
Before explaining OData, let’s go over representational state transfer (REST) first. REST
is a designed principle based on six architectural constraints:
쐍 Client-server architecture
쐍 Statelessness
쐍 Cacheability
쐍 Layered systems
쐍 Uniform interface between clients and servers
쐍 Code on demand (optional)
185
6 Creating OData Services 6.1 Introduction to OData
Any software system that follows these five or six (with five mandatory and one If you enter the URI into the address bar of your browser and press (Enter), it displays
optional) principles is referred to as RESTful. The World Wide Web is a key example of a the service document shown in Figure 6.1. As you can see, the service document refers
software system that fully implements REST principles. REST commands are of differ- to multiple collections: Customers, Orders, Products, and so on.
ent types, like GET to get one or multiple entries, POST to create an entry, PUT to update
an entry, DELETE to remove an entry, or UPDATE to update single properties of an existing
entry. HTTP(S) is the protocol that implements the server-side resource manipulation
techniques by providing methods that match the REST commands, like GET, PUT, and so
6
on.
OData is a web protocol based on REST, for querying and updating data and for provid-
ing access to information from a variety of applications. In our case, OData will provide
access to SAP S/4HANA and SAP BTP backend information via SAP Fiori applications.
OData is easy to understand and extensible and provides consumers with a predictable
interface for querying a variety of data sources. OData services can be queried like SQL
queries and thus are easy to implement in a consumer application.
Moreover, OData methods are aligned with HTTP methods like GET, PUT, and so on,
which helps developers easily understand how data is getting queried or updated.
Using OData is extremely simple and easy and a unique approach irrespective of the
service you’re using. Prior to OData, there were standardization problems with con-
suming pure REST services as the query option and payload structure were different for
each service and developers had to put some significant effort into consuming any
RESTful services. Using OData, developers can now query any services like database
SQL with a consistent approach, thus saving a lot of time.
SAP Gateway is an ABAP component that provides tools and infrastructure to create
and consume OData services. SAP Gateway is an integral part of SAP S/4HANA and thus
you do not need to install the SAP Gateway-specific components separately.
Now let’s examine the structure of an OData service and different available query
options.
Figure 6.1 OData Service Document
6.1.2 Query Options If you want to see the metadata document, you need to add “$metadata” at the end of
the root URI. So the metadata URI would be https://services.odata.org/Northwind/
Let’s go over the OData structure first, which we can do using a publicly available
Northwind.svc/$metadata, and Figure 6.2 displays the metadata of this service. The
Northwind OData service. We’ll be using this service in future chapters as well for build-
metadata shows various entity types, attributes for each entity types, entity sets, asso-
ing various SAP Fiori applications.
ciations, and more, so you can get to know more about the service by studying its meta-
Each OData service must have a root URI. For the Northwind OData service, the root data document. All the EntitySet elements are combined under EntityContainer, as
URI is https://services.odata.org/Northwind/Northwind.svc/. Each service has two types shown in Figure 6.3.
of documents associated with it: service documents and service metadata documents.
186 187
6 Creating OData Services 6.1 Introduction to OData
Figure 6.2 Service Metadata Document The $select option will help you limit the number of attributes to be returned. For
example, https://services.odata.org/Northwind/Northwind.svc/Orders?$format=json&
$select=OrderID,CustomerID will only return two attributes, OrderID and CustomerID,
as shown in Figure 6.5. This $select option is like the SQL field list option in a query.
If you want to display the data for any entity sets, you need to enter the entity’s name
next to the root URI; for example, https://services.odata.org/Northwind/Northwind.svc/
Orders will display all the available orders. If you add “?$format=json”—that is, the URL
becomes https://services.odata.org/Northwind/Northwind.svc/Orders?$format=json—then
it will display the data in JSON format, as shown in Figure 6.4. Figure 6.5 $select Option
188 189
6 Creating OData Services 6.1 Introduction to OData
Using the $filter option, you can filter based on certain attributes values. For example, Now you can understand the simplicity of OData queries and how similar they are to
https://services.odata.org/Northwind/Northwind.svc/Orders?$format=json&$select=Order SQL queries. Frontend developers can use this concept consistently to build service
ID,CustomerID&$filter=CustomerID eq ‘HANAR’ will display only those orders related to query options. Before we move to service development options, let’s quickly go over
customer HANAR, as shown in Figure 6.6. OData versions and how V4 is different than V2.
190 191
6 Creating OData Services 6.2 SAP Gateway Service Builder
any need for programming. As shown in Figure 6.8, a typical OData service generated
using SAP Gateway Service Builder includes the following: Figure 6.9 Overview of Development Approach for SAP Gateway Service Builder
쐍 SAP Gateway runtime artifacts, such as a model provider class (MPC), data provider
class (DPC) model, annotation provider class (APC), and service Now let’s look at the high-level steps involved in the creation of an OData service (see
쐍 OData artifacts such as an entity set, an entity type, and properties Figure 6.10) and the steps you can perform in SAP Gateway Service Builder.
192 193
6 Creating OData Services 6.3 Modeling OData Services
There are several options under the Project Type dropdown menu:
쐍 Service with SAP Annotations
Performed in Use this type if the OData service in your project is to use standard SAP annotations:
Define Data SAP Gateway Creatable, Updatable, Label.
Project Creation Service Builder
Model
쐍 Service with Vocabulary-Based Annotations
Select this type if the OData service in your project is to use vocabulary-based anno-
tations. Standard SAP annotations aren’t available for this project type. In this case, 6
terms are consolidated in a vocabulary and uploaded into the vocabulary repository.
Generation of Service
쐍 Annotation Model for Referenced Service
Runtime Objects Implementation
When the OData service has to be annotated externally without modifying the ser-
vice, you can create and upload customer-specific vocabularies into the vocabulary
repository. The uploading of vocabulary files is an optional preparatory step as there
are standard-delivered vocabularies available.
Service
쐍 OData 4.0 Service
Registration and Test Service
Activation Use this type when you want to create an OData V4 service.
You’ll mostly be using the Service with SAP Annotation and Service with Vocabulary-
Based Annotation options for your OData V2 service developments, which are more
Figure 6.10 High-Level Steps to Develop OData Service
common in SAP Fiori application development. OData V4 is new and not frequently
used in older versions of SAP S/4HANA. The annotation model approach is used to add
To develop a service using SAP Gateway Service Builder, you first have to create a proj-
additional annotations for your existing service and can be helpful for developing SAP
ect. Projects bundle all the development artifacts of a service in one central place and
Fiori applications based on an existing service definition.
thereby help organize the service development and modeling process. A project also
helps you organize the transport of objects from one system environment to another In the next section, we’ll discuss the various options for modeling OData services from
so that all the artifacts always remain together. You can create four types of projects in SAP Gateway Service Builder.
Transaction SEGW, as shown in Figure 6.11.
194 195
6 Creating OData Services 6.3 Modeling OData Services
Entity
Types
Entity Sets
쐍 Entity Sets
Association An entity type describes a data structure, and an entity set contains the instances of
Sets the given structure. Figure 6.14 shows all the entity sets and their corresponding
entity types.
Function
Import
Complex
Types
Figure 6.12 Different Tasks for Defining Data Models Figure 6.14 Entity Sets
We’ve created a Transaction SEGW project with of the service with SAP annotations 쐍 Association
types. So now let’s discuss the various elements of the project in detail: An association is a named relationship between two entities. An association defines
a peer-to-peer relationship between participating entity types. An example of an
쐍 Entity Types
association is the relationship between the Customer and Sales Order entity types.
Entity types in SAP Gateway Service Builder projects describe the structure of data in
쐍 Association Set
the Entity Data Model (EDM). Entity types represent a specific type of data. Figure
An association set specifies a relationship between two entity sets, such as Custom-
6.13 shows the definition of entity types and the properties of the same.
ers and Sales Orders. For example: one customer will have N sales orders. Figure 6.15
shows the different associations within this data model.
196 197
6 Creating OData Services 6.3 Modeling OData Services
To meet this requirement, we’ll start with project creation and two entity types, one for
customer and another one for sales order, and we’ll define their necessary properties.
Figure 6.18 shows the basic project information, such as the project name, package
name, and project type.
6
Figure 6.15 Association between Entity Types
쐍 Function Import
OData includes standard CRUD operations that map to the POST, GET, PUT/MERGE, and
DELETE HTTP methods. OData supports function imports that can be invoked by the
GET or POST HTTP methods for anything that can’t be mapped to the standard CRUD
operations, such as confirming/canceling a sales order line item, as shown in Figure
6.16.
쐍 Complex Types Once you create your project, you need to create one or more entity types by selecting
Complex types consist of a collection of properties without a unique key. These can Data Model • Create • Entity Type from the context menu, as shown in Figure 6.19.
only exist as properties of a containing entity or, outside an entity, as temporary val-
ues. Figure 6.17 shows the definition of complex types and their reference within an
entity type.
198 199
6 Creating OData Services 6.3 Modeling OData Services
Figure 6.22 shows another entity type and entity set you can create as a part of this
exercise.
Figure 6.25 shows the creation of an association between the customer and sales order.
As shown in Figure 6.23, define different properties and their attributes for the second Figure 6.25 Definition of Association between Customer and Sales Order
entity, Sales Order.
Click Next to display the principal entity and dependent entity, as shown in Figure 6.26.
200 201
6 Creating OData Services 6.3 Modeling OData Services
Click Finish in the association set–related screen shown in Figure 6.27, and the system
Figure 6.29 Data Model Creation Using Import File
will create the related association and association set, as shown in Figure 6.28.
Next, you need to select the metadata file you want to import. There are two radio but-
tons on this screen, Custom Import and Full Import, as shown in Figure 6.30. If you
already have an existing project with defined entities and you want to overwrite that
with new entities from a file, you can use the custom import option. Here, we’re using
a new project with no previously defined entities, so the custom import option is dis-
abled. Select Full Import and then use the Browse button on the Browse File field to
locate your metadata file. This metadata file must be available on your computer prior
to executing these steps. Depending on your scenario, this metadata file can be down-
loaded from other SAP or non-SAP OData service definitions.
Figure 6.28 Association and Association Set
Now you’ve completed the data modeling portion of this requirement. Next, you need
to implement the service, which we’ll cover later in Section 6.4.
202 203
6 Creating OData Services 6.3 Modeling OData Services
You need to confirm that the content of the metadata is correct, as shown in Figure 6.31, Importing a DDIC Structure
and click Finish. Import a DDIC structure to reuse an existing ABAP structure as a complex type or
entity type.
This feature helps reduce the time required to create complex types and entity types in
a data model. The import DDIC structure option can import an existing ABAP (DDIC)
structure that you can reuse to create new complex types and entity types with ease.
You can import the following DDIC structures into SAP Gateway Service Builder: 6
쐍 Views
쐍 Database tables
쐍 Structures
Let’s quickly develop a data model with step-by-step instructions. We’ll start with an
import wizard, as shown in Figure 6.33.
Figure 6.32 Newly Created Data Model Using Imported Metadata File Figure 6.34 DDIC Structure Reference
204 205
6 Creating OData Services 6.3 Modeling OData Services
If needed, you can avoid creating an entity type by selecting the Complex Type option. After completing the wizard, the data model will be generated, as shown in Figure 6.37.
In that case, you may need to manually create the entity type to refer to this complex
type. In addition, the Create Default Entity Set option, shown in Figure 6.34, will reduce
your effort by automatically creating an entity set for the entity type if needed.
Depending on your requirements, you may or may not need all the fields from the
DDIC structure. In this example, we’re not interested in all the available fields, so we
select only the fields we need, as shown in Figure 6.35.
6
Now let’s look at importing a data source (an RFC/BOR interface). This approach
reduces the time required to create entity types in the data model. The Import • RFC/
BOR Interface function can import an existing data source and reuse this data to create
new entity types with less manual effort. Start with the wizard, as shown in Figure 6.38.
Figure 6.35 Selection of Fields Needed
In the next step, you’ll select the key fields for the entity type, as shown in Figure 6.36.
Determination of the key fields will be dependent on your design, and you may need to
spend time analyzing that before you determine the key fields.
Next you need to fill out the Entity Type Name field, select Remote Function Call or
Business Object under Type, and enter the name of the data source to generate the data
model, as shown in Figure 6.39. Here we’re using the current system and thus selected
the Local option for Target System, as shown in Figure 6.39. We also entered “BAPI_
CUSTOMER_GETDETAIL2” for the RFC data source to use.
Figure 6.36 Confirming Key Fields
206 207
6 Creating OData Services 6.3 Modeling OData Services
Another option is to import search help and associate it with the model so that you can
Now you need to select the fields that need to be the keys for the entity, as shown in Fig-
reuse it in you project. You can reuse existing search helps in a system as data sources
ure 6.41. Determining key fields is one of the primary design elements of defining the
to create new entity types.
OData service, and it’s also dependent on your backend data modeling.
208 209
6 Creating OData Services 6.3 Modeling OData Services
To begin, start the wizard by right-clicking Data Model and selecting Import • Search
Help, as shown in Figure 6.43.
Next you need to provide the Entity Type Name and enter the Name of the search help
you’re using to generate the data model, as shown in Figure 6.44.
After completion of the wizard, you’ll see that the data model is generated, as shown in
Figure 6.47.
Now select the fields that need to be part of the entity types for the entity type as shown
in Figure 6.45. The number of selected fields will be a subset of the available fields,
depending on your requirements.
Next, select the fields that need to be keys for the entity, as shown in Figure 6.46. Again,
determination of key fields is a design element and significantly dependent on back-
end data and your requirements.
Figure 6.47 Generated Data Model Using Imported Search Help
210 211
6 Creating OData Services 6.3 Modeling OData Services
In this section, we’ll discuss how to redefine a service in an empty project for the first
time. To begin, start the wizard by right-clicking Data Model and selecting Redefine •
OData Service (SAP GW), as shown in Figure 6.48.
Next you need to select the reference OData service, as shown in Figure 6.49. This is the
existing service you want to redefine with additional functionality. Here we selected a
standard SAP service, SRA020_PO_TRACKING_SRV, as an example.
Figure 6.50 Selecting Entity Sets to Be Redefined
Now select the artifacts you need in your new service, as shown in Figure 6.50. The new
service may or may not need all the entity sets. Here, we selected four entity sets as an After completion of the wizard, you’ll see that the data model is generated, as shown in
example: POItemDetailData, SupplierInfo, PODetailedData, and POItem. These are the Figure 6.51.
entity sets that need redefinition with new or enhanced logic or fields.
212 213
6 Creating OData Services 6.3 Modeling OData Services
Now we can see, under Model References in the data model tree, that the material
OData service is added, as shown in Figure 6.54.
6.3.4 Including an OData Service Next you need to create the association using the model reference. For that, we came to
When you’re creating a new OData service for a business need, it’s very common to add the association mass maintenance editor from the data model and provided the name.
a list of different types of master data. For example, to develop a custom purchase order Then, click External Association Editor, as shown in Figure 6.55, and select the model
application, you need to have a list of products, suppliers, purchase organizations, and reference that was added in the previous step.
so on. For most of these, SAP-standard OData services already exist. By including an
OData service, you can link to an existing model’s list instead of recreating it.
Let’s look at an example. We’ll be adding the material OData service to the purchase
order service. To begin, start the wizard by right-clicking Data Model and selecting
Include • OData Service (SAP GW), as shown in Figure 6.52.
Next, select the existing OData service to be included as a part of this new service defi- Figure 6.55 External Association Creation Using Model Reference
nition. In this case, include the MDG_MATERIAL_SRV service, as shown in Figure 6.53.
214 215
6 Creating OData Services 6.4 Service Implementation
Now you need to add the principal entity and the dependent entity. In this case, the
dependent entity is from the reference model. As shown in Figure 6.56, in the Depen-
dent Entity dropdown, you can see all the entities from the model reference. Here you
need to select the one that addresses your requirements. Because you’re defining an
association between the PO and material, select Material, as shown in Figure 6.57.
Once the correct entities and cardinality are selected, you can see that the association
was created, as shown in Figure 6.57.
6
216 217
6 Creating OData Services 6.4 Service Implementation
쐍 RFCs
쐍 Business object repositories (BORs)
Let’s walk through an example in the system. We’ll be using the EPM sales order exam-
ple for this. First, start the wizard by right-clicking Service Implementation and select-
ing SalesOrderSet • GetEntitySet (Query) • Map to Data Source, as shown in Figure 6.62.
Next, you need to map the RFC or business object, as shown in Figure 6.63. In this exam-
ple, we used a standard EPM RFC function, BAPI_EPM_SO_GET_LIST.
218 219
6 Creating OData Services 6.5 Registering an OData Service
Now, you need to map the RFC function’s fields to the entity type’s fields by dragging Once the mapping is completed, the service implementation tree will look as shown in
the RFC field and dropping it onto the entity type. The final mapping is shown in Figure Figure 6.67.
6.64, with an arrow for each field. The arrow means the field is mapped to a target entity
type field.
In the same way, for the GetEntity method, map to the data source, as shown in Figure
6.65, and perform mapping, as shown in Figure 6.66.
In the same way, you can select the appropriate business object or remote function to
implement create or update methods as well. As a part of your whole OData service
design, you need to first analyze your backend functionality and determine the remote
function or business object to be responsible for create, update, or get functionality.
Now that we’ve explained various aspects of creating an OData service, next we’ll dis-
cuss how to register and test the OData service.
220 221
6 Creating OData Services 6.6 Testing an OData Service
2. On the next screen, enter the backend system alias in which the service is exposed. Your service should now be registered and activated, as highlighted in Figure 6.71. You
You can optionally provide the service name (full or partial with wildcard) to search can now test your service, which we’ll explain in the next section.
for the service, as shown in Figure 6.69.
Figure 6.69 Add OData Service for Registration Figure 6.71 Service Registration and Activation
3. On the next screen, most of the details will be autopopulated, as shown in Figure 6.70.
You can additionally enter the Package Assignment, select Set Current Client as Default 6.6 Testing an OData Service
Client in ICF Node, and, optionally, select Enable OAuth for Service (see Figure 6.70).
Once the service is registered and activated, next you need to test the service before
you hand it over to the frontend SAP Fiori developer for service consumption. To test
an OData service, select the OData service in Transaction /IWFND/MAINT_SERVICE and
then click SAP Gateway Client. This will open Transaction /IWFND/SUTIL_GW_CLIENT
for testing the OData service, as shown in Figure 6.72.
SAP Gateway Client should prepopulate your service name along with the service path,
as shown in Figure 6.73. You should now select the entity sets by clicking EntitySets and
then selecting the entity set to be tested. Once you select your entity set, you can exe-
cute it to get a list of sales orders, as shown in Figure 6.73. This is a simple OData get call
to retrieve the data, so you don’t need to enter a payload for execution. For creating or
updating any entity sets, you need to properly enter the payload either in XML or JSON
Figure 6.70 Add Additional Parameters format in the blank area available to the left of the screen, highlighted in Figure 6.73.
222 223
6 Creating OData Services 6.7 Generating an OData Service from a CDS View in SAP S/4HANA
We’ve now explained different code-based OData service implementation options. But
in SAP S/4HANA, you have a better choice: creating an OData service directly from a
CDS view! Let’s explore that concept next.
As shown, you get the list of sales orders. Now, if you want to see the details of a partic-
ular sales order, you can test the same service with the sales order number set in paren-
thesis, as shown in Figure 6.74. This brings up all the related attribute values defined for
the sales order entity for that sales order—here, sales order 500000002—as shown in
Figure 6.74.
224 225
6 Creating OData Services 6.7 Generating an OData Service from a CDS View in SAP S/4HANA
As shown in Figure 6.76, the main components of the autoexposure process refer to the
most important activities that are involved. After adding the annotation, you need to
launch Transaction /IWFND/MAINT_SERVICE to register the OData service to the ser-
vice catalog of the SAP Gateway hub, as discussed in Section 6.5. After this step, the
OData service is ready for consumption.
SAP NetWeaver
6
Service Catalog
RFC or LOCAL Figure 6.77 OData Service from CDS Using Reference Data Source
CDS OData
ABAP Development Tools
Runtime
Edit/Save
…
@OData.publish:true Activate CDS Data
Service
define view … Definition
Artifact
This approach is simple, but it lacks an option to add complex coding that may be
required for one or more fields. The next section will highlight how to overcome this
limitation.
226 227
6 Creating OData Services 6.7 Generating an OData Service from a CDS View in SAP S/4HANA
Now the service and model are generated. Because you’re generating the DPC and MPC
classes, you can enhance their implementation to address complex data-retrieval logic.
Once your service definition is fully implemented, you need to launch Transaction
/IWFND/MAINT_SERVICE to register the OData service to the service catalog of the SAP
Gateway hub, as shown in Section 6.5. After this step, the OData service is ready for con-
sumption.
6
6.7.3 OData Service Based on Mapped Data Source
You also can create OData service from a CDS view using a mapped data source. Say that
you have the CDS view shown in Figure 6.82.
After the data model is completed, you can generate the service, and it will prompt you
for the DPC, MPC classes, and model and service names. Enter those as per your naming
conventions, as shown in Figure 6.81.
Figure 6.82 CDS View to Be Exposed as OData Service
You can see the ABAP view name here, and you’ll use that to import the entity type, as
shown in Figure 6.83 and Figure 6.84.
Figure 6.83 Data Model Creation Using DDIC Structure Option for CDS View
Figure 6.81 Model- and Service-Related Technical Details
228 229
6 Creating OData Services 6.7 Generating an OData Service from a CDS View in SAP S/4HANA
Figure 6.84 Create an Entity Type Referencing the ABAP Structure of the CDS
Figure 6.86 Select CDS to be Mapped to Entity Type
After the import is completed and the data model is generated, you need to work on the
service implementation part. For that, right-click the entity set name under the Service
Implementation folder and choose Map to Data Source, as shown in Figure 6.85.
Figure 6.85 OData Service Creation Using Map to Data Source Option for CDS View Figure 6.87 Select CDS Business Entity (Highlighted as CDS~<CDS Name>)
Next, select Business Entity from the Type dropdown. For the Name field, we will be Next, you need to perform the mapping as shown in Figure 6.88.
using the search help. Select CDS Core Data Services as SADL Model Type and enter the
view name in the SADL Model field, as shown in Figure 6.86.
After the data entry from the previous step, the Map to Data Source window will open,
as shown in Figure 6.87.
230 231
6 Creating OData Services 6.8 ABAP RESTful Application Programming Model and OData
Finally, you can save the project and click the Generate button. This will open the win-
dow shown in Figure 6.89, in which you can enter technical details for the DPC, MPC, SERVICE SAP Fiori UI WEB API
CONSUMPTION Consume OData UI Services Consume OData Web APIs
model, and service.
SERVICE BINDING
Bind to Protocol Version and Scenario
SERVICE DEFINITION
BUSINESS Definition Scope to be Exposed
SERVICES 6
PROVISIONING Business Object Projection
As you can see in Figure 6.90, the model has three distinct layers—data modeling and
behavior, business service provisioning, and service consumption:
Figure 6.89 Model- and Service-Related Technical Details 쐍 In the data modeling and behavior layer, you model your data using different CDS
views and link them using associations. This is the layer for creating business
Now the service and model are generated. Next you need to launch Transaction objects. In addition, you can add behavior definitions and implementation for cre-
/IWFND/MAINT_SERVICE to register the OData service to the service catalog of the SAP ate, change, and delete scenarios.
Gateway hub, as discussed in Section 6.5. After this step, the OData service is ready for 쐍 In the business service provisioning layer, you project a subset of your business
consumption. object created in the data modeling layer. In addition, you can define the scope of
We’ve explained a couple of different ways of creating OData services in this chapter, your service and bind your service to a protocol (OData V2 versus V4).
but let’s discuss one more. SAP recently introduced the ABAP RESTful application pro- 쐍 The service consumption layer determines whether the service is a UI service or a
gramming model in SAP S/4HANA and SAP BTP, ABAP environment. So now we’ll pro-
web API.
vide an overview of creating OData services in this model.
There are different types of applications you can develop using ABAP RESTful applica-
tion programming model: read-only list report applications, managed transactional
6.8 ABAP RESTful Application Programming Model and OData applications, unmanaged transactional applications, draft applications, and so on. In
addition, you can simply expose CDS views as web APIs. We won’t go over all the types
The ABAP RESTful application programming model is the primary programming
of applications here, as this chapter is focused on OData services. So, we’ll simply
model for SAP S/4HANA for efficient end-to-end development of SAP HANA–opti-
explain how you can expose your CDS view as a web API so that it can be consumed by
mized OData services and SAP Fiori apps. This programming model helps ABAP devel-
any external application. Let’s go over the steps:
opers to develop all types of SAP Fiori applications and to publish web APIs. These web
APIs are nothing but OData services, so we’ll cover them to some extent here. This pro- 1. As a prerequisite, please make sure you have an SAP S/4HANA on-premise system
gramming model is based on CDS and follows a layered development approach, as available, and its version should be 1909 or above. In addition, you should have ADT
shown in Figure 6.90. An OData service is exposed that can be consumed by an SAP or installed on your local computer and able to connect to your development client.
a third-party application or can be used to build a frontend application.
232 233
6 Creating OData Services 6.8 ABAP RESTful Application Programming Model and OData
2. Your CDS view should be available with all its attributes, associations, and the like. 4. Now create a service binding. Again, ADT will provide an option to create a service
Figure 6.91 displays a simple CDS view created from sales order header table VBAK. binding, as you see in Figure 6.93. While creating a service binding, you can select
OData V2 or OData V4, as shown in Figure 6.94. The resulting service binding should
look as shown in Figure 6.95.
3. Next, create a service definition. You can create this object from ADT, as shown in Fig-
ure 6.92. Figure 6.93 displays a service definition created for the example CDS view.
Figure 6.95 Service Binding
5. You can now publish your binding by clicking the Publish option. After publishing,
the status will have changed appropriately, as shown in Figure 6.96.
234 235
6 Creating OData Services
6. Once you publish your service, you can activate the service using Transaction
/IWND/MAINT_SERVICE, and then your service is ready to be consumed.
As you can see, we haven’t defined any behavior definition or behavior implementa-
tion. We didn’t even create a projection view as we want to keep this example very sim-
ple. However, you can build complex web APIs or complex applications by utilizing
various application development patterns available with the ABAP RESTful application
programming model.
That wraps up the ABAP RESTful application programming model and OData overview.
Now let’s briefly go over another important topic related to OData services: annota-
tions.
6.10 Summary
OData is the primary way to consume the backend data for SAP Fiori applications. Both
OData V2 and V4 are supported, though V4 may have certain limitations depending on
your backend release. SAP provides different options to build OData services, such as
code-based implementation using Transaction SEGW, no-code implementation from
CDS views, and so on. Using OData helps frontend developers to build query-like oper-
ations to consume backend data in a consistent way, thus simplifying the overall ser-
vice-consumption approach.
236
Contents
Preface ....................................................................................................................................................... 15
1 Introduction 19
7
Contents Contents
2.3 Installation ............................................................................................................................... 70 4.2.1 Activating the SAPUI5 Component .................................................................. 118
2.3.1 SAP Fiori Frontend Server ..................................................................................... 71 4.2.2 Activating the OData Services ............................................................................ 122
2.3.2 SAP Web Dispatcher .............................................................................................. 76 4.2.3 Frontend Roles ......................................................................................................... 131
2.3.3 SAP Fiori Client ........................................................................................................ 77 4.3 Backend Implementation Tasks ...................................................................................... 154
2.4 Configuration .......................................................................................................................... 77 4.3.1 Assigning RFC Authorization to Users ............................................................. 154
2.4.1 SAP Fiori Initial Setup ............................................................................................ 78 4.3.2 Creating Authorization Roles for Catalogs .................................................... 154
2.4.2 Communication Channels ................................................................................... 82 4.4 Rapid Activation of SAP Fiori Applications in SAP S/4HANA ............................. 156
2.4.3 Setup of SAP Fiori Launchpad ............................................................................. 92
4.5 Running Applications .......................................................................................................... 162
2.4.4 Setup of SAP Fiori Search ..................................................................................... 93
4.5.1 SAP Fiori Launchpad from End User Perspective ......................................... 162
2.4.5 Optional Configuration ........................................................................................ 93
4.5.2 Personalizing and Adapting Apps ..................................................................... 163
2.5 Getting the Latest SAP Fiori Design in Your System Landscape ....................... 93 4.5.3 Personalizing the Launchpad ............................................................................. 164
2.5.1 Preupgrade Considerations ................................................................................ 94
4.6 Summary ................................................................................................................................... 164
2.5.2 Upgrading an Existing SAP Fiori Landscape .................................................. 94
2.6 Summary ................................................................................................................................... 99
3 Security 101
5.1 Architecture and Overview of Embedded Analytics in SAP S/4HANA ........... 166
8 9
Contents Contents
6.3 Modeling OData Services ................................................................................................... 195 8 Methods of SAP Fiori Application Development 257
6.3.1 Defining a Data Model ......................................................................................... 196
6.3.2 Importing Data Model .......................................................................................... 202
8.1 SAP Fiori Elements Framework ........................................................................................ 257
6.3.3 Redefining OData Services .................................................................................. 212
8.1.1 List Report ................................................................................................................. 259
6.3.4 Including an OData Service ................................................................................. 214
8.1.2 Object Page ............................................................................................................... 260
6.4 Service Implementation ..................................................................................................... 216 8.1.3 Analytical List Page ................................................................................................ 261
6.4.1 Redefining Methods of the Operations .......................................................... 217 8.1.4 Overview Page ......................................................................................................... 262
6.4.2 Mapping a Data Source ........................................................................................ 218 8.1.5 Worklist ...................................................................................................................... 264
6.5 Registering an OData Service ........................................................................................... 221 8.2 Freestyle Application Development .............................................................................. 265
6.6 Testing an OData Service ................................................................................................... 223 8.2.1 SAP Fiori Worklist Application ............................................................................ 265
8.2.2 SAP Fiori Master-Detail Application ................................................................. 266
6.7 Generating an OData Service from a CDS View in SAP S/4HANA ................... 225
8.2.3 SAPUI5 Basic Application ..................................................................................... 267
6.7.1 Autoexposure Using Annotations .................................................................... 225
6.7.2 Based on Reference Data Source ....................................................................... 226 8.3 Freestyle Development versus SAP Fiori Elements ................................................ 267
6.7.3 OData Service Based on Mapped Data Source ............................................. 229 8.4 Summary ................................................................................................................................... 268
6.8 ABAP RESTful Application Programming Model and OData .............................. 232
7.6 SAP Fiori Tools in SAP Business Application Studio ............................................... 255
10 Building and Extending Freestyle SAP Fiori
7.7 Summary ................................................................................................................................... 256
Applications 339
10 11
Contents Contents
10.1.1 Floorplans .................................................................................................................. 339 12.3.2 Scopes for Adapting Launchpad Content ....................................................... 421
10.1.2 Data Sources ............................................................................................................ 341 12.3.3 Spaces and Pages .................................................................................................... 422
10.1.3 App Overview: The Basic Files of the Application ........................................ 341 12.3.4 Groups and Catalogs ............................................................................................. 427
10.1.4 List-Detail Application .......................................................................................... 342 12.3.5 Setting Up Navigation for a Custom Application ........................................ 427
10.1.5 Worklist Application .............................................................................................. 351 12.4 Personalization ....................................................................................................................... 431
10.1.6 SAPUI5 Application ................................................................................................ 357
12.4.1 End User App Personalization ............................................................................ 431
10.2 Extending Freestyle Applications ................................................................................... 361 12.4.2 Adapting SAP Fiori UIs at Runtime—Key User Adaptation ...................... 435
10.2.1 Extending SAP Fiori Applications in the SAP S/4HANA 12.4.3 Personalizing the Classic Home Page .............................................................. 436
Application Layer .................................................................................................... 361 12.4.4 Personalizing a Page .............................................................................................. 437
10.2.2 Extending SAP Fiori Applications in the OData Service Layer .................. 363 12.4.5 Adding Apps using App Finder ........................................................................... 438
10.2.3 Extending the UI Layer of a Freestyle SAP Fiori/SAPUI5 Application .... 370 12.5 Extensions ................................................................................................................................. 439
10.3 Summary ................................................................................................................................... 375 12.6 Security ...................................................................................................................................... 443
12.6.1 Role Configuration to Start Launchpad .......................................................... 443
12.6.2 Role Configuration for Catalogs, Groups, and Spaces ............................... 444
11 Building and Extending Analytical Applications 377 12.6.3 Additional Security Considerations .................................................................. 446
12.7 Summary ................................................................................................................................... 447
11.1 Creating Analytical Applications .................................................................................... 377
11.1.1 Creating CDS Views ............................................................................................... 377
11.1.2 Creating OData Service ........................................................................................ 381
13 SAP Screen Personas 449
11.1.3 Creating Custom Analytical Queries ................................................................ 382
11.1.4 Manage KPIs and Reports .................................................................................... 386
11.1.5 Creating Analysis Path Framework Applications ......................................... 395
13.1 Architecture and Components ........................................................................................ 450
11.1.6 Creating Multidimensional Reports ................................................................. 396 13.2 Navigation to SAP Screen Personas–Enabled Screens .......................................... 451
11.1.7 Manage Date Functions ....................................................................................... 401 13.2.1 Accessing SAP Screen Personas Using SAP GUI
11.2 Extending Analytical Applications ................................................................................. 403 (SAP GUI for Windows/Java) .............................................................................. 451
13.2.2 Accessing SAP Screen Personas Using Web GUI .......................................... 453
11.2.1 Extending CDS Views ............................................................................................ 403
11.2.2 Extending OData Services ................................................................................... 407 13.3 SAP Screen Personas versus SAP Fiori ........................................................................... 455
11.2.3 Configuring Analytical UIs ................................................................................... 409 13.4 Applying Elements of Screen Personas ........................................................................ 456
11.3 Summary ................................................................................................................................... 409 13.4.1 Creating a Flavor ..................................................................................................... 456
13.4.2 Creating and Applying a Theme ........................................................................ 460
13.4.3 Scripting ..................................................................................................................... 463
12 Configuring SAP Fiori Launchpad 411 13.5 Enabling SAP Fiori–Like Applications ........................................................................... 465
13.5.1 General Guidelines ................................................................................................ 466
12.1 Key Components .................................................................................................................... 412 13.5.2 Letterbox Theme ..................................................................................................... 466
13.5.3 Floorplans .................................................................................................................. 466
12.2 Initial Setup on ABAP Platform ....................................................................................... 414
13.5.4 Themes and Floorplans in Action ...................................................................... 467
12.2.1 Embedded Deployment ....................................................................................... 415
12.2.2 Hub Deployment .................................................................................................... 418 13.6 Maintenance and Administration .................................................................................. 471
12 13
Contents
Appendices 525
14
Index
563
Index Index
CDS view Descriptor (manifest.json) ................................. 341 Initial authentication .......................................... 101 M
cardinality ........................................................... 379 Design language ...................................................... 15 Integrated development environment
create .................................................................... 377 Design principles ..................................................... 22 (IDE) .......................................................................... 43 Maintaining annotations .................................. 255
data source ......................................................... 378 Design Studio Template ..................................... 182 with language server ......................................... 44
elements ............................................................... 379 Dev spaces ................................................................ 238 J Maintenance Planner .............................. 61, 72, 94
filter conditions ................................................ 380 Digital assistant ..................................................... 500 Manage KPIs and Reports app ................ 175, 386
join conditions .................................................. 379 Dimensions Java ................................................................... 238, 555 Manage Launchpad Settings ............................ 116
parameters ......................................................... 379 filters ...................................................................... 385 Manage Workflows app ..................................... 509
preview ................................................................. 381 Document Object Model (DOM) ....................... 85 K Mapping ................................................................... 218
properties ............................................................ 380 DPC .............................................................................. 217 Metadata documents .......................................... 276
publish .................................................................. 381 Kerberos ................................................................... 102 Mobile security ..................................................... 107
Central hub deployment ...................................... 63 Key pairs ................................................................... 103
Chatbots ................................................................... 475
E Model provider class (MPC) ............................. 192
Key performance indicators (KPIs) ................... 33 MTA ............................................................................ 321
development ...................................................... 478 KPI applications ..................................................... 177
Eclipse Theia ............................................................ 237 build ...................................................................... 322
SAP Conversational AI ................................... 479 analytical list page report ............................ 392
Embedded analytics ............................................. 165 MTAR file ............................................................. 323
skills ....................................................................... 478 APF application ................................................ 392
enabling applications ..................................... 178 Multidimensional reports ................................ 174
training data ...................................................... 478 business catalog ............................................... 393
tools ....................................................................... 168 create .................................................................... 396
Chrome debugger ................................................. 365 create .................................................................... 387
Embedded deployment ................................. 63, 67 data display ....................................................... 399
Classic home page layout .................................. 427 create view .......................................................... 392
Entity Data Model (EDM) ................................... 196 filters ..................................................................... 397
personalize .......................................................... 436 define KPI ............................................................ 388
Entity sets ................................................................. 188 SAP Design Studio grid reports .................. 399
Cloud connector ....................................................... 31 generic drilldown report ................................ 392
Entry page ................................................................ 413 Web Dynpro Grid ............................................. 399
Coherent UX .............................................................. 22 parameters ......................................................... 389
Extensions My Inbox app
Communication channels ................................... 82 report .................................................................... 391
Communication security .................................. 107 BAdIs ...................................................................... 361 semantics ............................................................ 389 configure ............................................................. 511
Component (component.js) ............................. 342 change business logic ..................................... 331 tile configuration ............................................. 391
CONF .......................................................................... 132 complex ................................................................ 331 visualize ............................................................... 390 N
Conversational UI ................................................. 475 deployment ......................................................... 335 KPI modeler ............................................................ 386
Conversational user experience ........................ 56 for end users ....................................................... 324 KPI tiles ........................................................... 113, 387 Native device capabilities ................................. 109
Core data services (CDS) ..................................... 171 groups of users .................................................. 328 Navigation ............................................................... 427
OData layer ......................................................... 363 Node.js ............................................................. 238, 555
CUST ........................................................................... 132 L
Custom analytical query .......................... 172, 550 UI layer ................................................................. 370 Northwind OData service ................................. 186
Custom business object ..................................... 548 Launchpad authorizations ................................ 117
Custom CDS view .................................................. 552 F Launchpad Content Manager .......................... 131 O
Custom logic ........................................................... 547 List-detail application (freestyle) .................... 340
Custom reusable elements ............................... 553 Floorplans ............................................. 259, 270, 339 application type ............................................... 343 Object page .................................................... 259, 270
Freestyle development ....................................... 339 column headings .............................................. 348 add columns ...................................................... 285
D Frontend implementation ................................ 118 column values ................................................... 349 add fields ............................................................. 285
Frontend roles ........................................................ 131 configuration ..................................................... 345 annotation file .................................................. 286
Data model data source and service ................................. 344 deleting ................................................................ 289
Detail.view.xml ................................................. 347
definition ............................................................. 196 G development ...................................................... 279
import ......................................................... 202–203 development ...................................................... 342 enhancements .................................................. 295
Data protection and privacy ............................ 109 Group ......................................................................... 114 header ................................................................... 350 entity selection ................................................. 282
Data provider class (DPC) .................................. 192 Groups and catalogs ............................................. 427 new project ......................................................... 343 guided development ....................................... 283
Data sources ............................................................ 272 Guided development ................................... 44, 255 preview ................................................................. 346 header .................................................................. 291
Date functions ....................................................... 401 project details .................................................... 346
new project ......................................................... 280
List report ....................................................... 259, 270
DDIC structure ....................................................... 205 I add columns ....................................................... 285
preview ................................................................ 286
Delightful UX ............................................................. 22 quick fix ............................................................... 292
add fields ............................................................. 285
Deployment ............................................................ 250 In-app extensibility OData ........................................................ 23, 122, 185
annotation file .................................................. 286
ABAP system ...................................................... 319 custom analytical query ................................ 550 authorizations .................................................. 117
development ...................................................... 279
extended application ...................................... 335 custom business object .................................. 548 create service ..................................................... 381
entity selection .................................................. 282
MTA ....................................................................... 321 custom logic ....................................................... 547 CRUD operations ............................................. 198
guided development ....................................... 283
prerequisites ....................................................... 318 custom reusable elements ............................ 553 new project ......................................................... 280 entity types ........................................................ 187
SAP BTP ................................................................ 321 UI adaptation ..................................................... 546 preview ................................................................. 286 extension ............................................................ 364
564 565
Index Index
566 567
Index Index
SAP Fiori launchpad (Cont.) SAP Logon tickets .................................................. 105 SAPUI5 ....................................................................... 339 Service registration ............................................. 221
groups ................................................................... 430 SAP Mobile Platform .............................................. 53 adaptation project ............................................. 56 Shell ........................................................................... 412
home page layout ............................................ 422 SAP Mobile Server ................................................. 108 application ......................................................... 340 Simple UX ................................................................... 22
hub deployment ............................................... 418 SAP Mobile Services ..................................... 53, 108 extensions ........................................................... 370 Single sign-on (SSO) ............................................... 62
key user adaptation ........................................ 435 SAP NetWeaver AS ABAP system ...................... 25 floorplans ............................................................ 339 Software development kit (SDK) ....................... 53
navigation .......................................................... 427 SAP NetWeaver authorization concept ........ 112 SAPUI5 application (freestyle) Software Provisioning Manager (SWPM) ...... 72
page personalization ...................................... 437 SAP NetWeaver Security Guide ....................... 112 configuration ..................................................... 359 Software Update Manager (SUM) ..................... 72
pages ........................................................................ 30 SAP Portal ................................................................. 252 data source ......................................................... 358 Spaces and pages .................................................. 114
personalization ................................................. 431 SAP S/4HANA .................................................. 61, 250 development ...................................................... 357 add section ......................................................... 425
plug-ins ................................................................ 441 VDM ....................................................................... 167 preview ................................................................. 360 create page ......................................................... 423
rapid activation ................................................ 417 SAP S/4HANA embedded analytics ..... 165, 377 project details .................................................... 359 create space ....................................................... 424
roles ....................................................................... 443 SAP S/4HANA extensibility ............................... 545 SAPUI5 basic template ........................................ 267 enable ................................................................... 426
SAP GUI for HTML apps ................................. 143 SAP S/4HANA flexible workflow ..................... 503 SAPUI5 component .............................................. 118 space ID ............................................................... 425
scopes .................................................................... 421 activate ................................................................. 507 SAPUI5 controls ..................................................... 247 SPNEGO .................................................................... 102
sections ................................................................... 28 activities ............................................................... 506 SAPUI5 freestyle .................................................... 265 SSO ............................................................................. 101
security ................................................................. 443 agent rule mitigation ...................................... 506 data source ......................................................... 341 mechanism ......................................................... 106
semantic object ................................................. 427 agent rules ........................................................... 507 files created ........................................................ 341 Static tiles ................................................................ 138
setup ......................................................................... 92 conditions ............................................................ 507 floorplans ............................................................ 339 SUM ............................................................................... 94
shell header display ......................................... 439 configuration ..................................................... 508 SAP Fiori list-detail template ....................... 340
shell header title ............................................... 439 create ..................................................................... 504 SAP Fiori worklist template .......................... 340 T
spaces ............................................................. 30, 422 flexible block ....................................................... 505 SAPUI5 template ............................................... 340
target mapping ................................................. 429 Manage Workflows app ................................. 509 versus SAP Fiori elements ............................. 267 Target audience ........................................................ 15
task lists ..................................................... 415, 418 properties ............................................................. 505 SAPUI5 freestyle development ................ 50, 339 Target mappings ................................................... 114
tiles ............................................................................ 30 recipient ............................................................... 510 SAPUI5 Repository Upload and Download create .................................................................... 135
tile types ............................................................... 439 SAP S/4HANA Cloud ........................................ 509 Reports ................................................................. 319 Task lists ...................................................................... 78
Transaction PFCG ............................................ 443 save and activate .............................................. 511 SAP Web Dispatcher ................................ 25, 76, 84 Technical catalogs ................................................ 134
Transaction STC01 ........................................... 416 scenario ................................................................ 504 SAP Web IDE .................................................. 237, 527 Templates ............................................. 259, 270, 339
user action menu extension ........................ 441 scenario object ................................................... 504 annotations ........................................................ 534 Time characteristic–based hierarchies ........ 181
user settings extension .................................. 441 step conditions .................................................. 511 application development .............................. 532 Transaction /IWFND/MAINT
Web Dynpro apps ............................................. 143 steps ....................................................................... 510 architecture ........................................................ 527 _SERVICE .................................................... 124, 221
SAP Fiori Master-Detail template ................... 266 Transaction SPRO ............................................. 507 benefits ................................................................. 529 Transactional apps .................................................. 32
SAP Fiori search SAP S/4HANA flexible workflows deployment ........................................................ 541 Transaction PFCG ........................................ 112, 148
setup ......................................................................... 93 basic details ........................................................ 509 enhancements ................................................... 537 Transaction SAML2_IDP ....................................... 88
SAP Fiori tools ........................................................... 44 preconditions ..................................................... 510 migrating from ................................................. 253 Transaction SEGW ............................. 192, 194, 362
SAP Gateway ............................................. 63, 72, 186 SAP Screen Personas ............................................ 449 preview ................................................................. 540 Transaction SICF ................................................... 182
embedded ............................................................ 514 administration .................................................. 471 project ................................................................... 532 Transaction STC01 ...................................... 179, 416
SAP Gateway Client .................................... 125, 223 architecture ......................................................... 450 setup ...................................................................... 529 task lists .................................................................. 79
SAP Gateway server ................................................ 24 components ........................................................ 450 templates ............................................................. 533 Transport Layer Security (TLS) ........................ 103
SAP Gateway Service Builder ........................... 192 elements ............................................................... 456 SAP Workflow Management .................. 503, 514 Trusted communication ...................................... 88
association ......................................................... 197 flavor ..................................................................... 456 application development .............................. 516 Trusted connectivity authorizations ........... 117
association set ................................................... 197 flavor editor ........................................................ 457 create destination ............................................ 516
complex types .................................................... 198 floorplans ............................................................ 466 setup ...................................................................... 515 U
entity sets ............................................................ 197 letterbox ............................................................... 466 SAP Work Zone ...................................................... 252
entity types ......................................................... 196 navigation ........................................................... 451 SAP Work Zone for HR ........................................ 252 UI adaptation ......................................................... 546
function import ................................................ 198 SAP Fiori flavor .................................................. 465 Secure data storage .............................................. 108 UI enhancement ...................................................... 57
SAP Gateway service redefinition .................. 212 SAP GUI ................................................................. 451 Secure Sockets Layer (SSL) ................................. 103 Upgrades ..................................................................... 93
SAP GUI for HTML ................................................ 143 scripting ............................................................... 463 Security ..................................................................... 101 prerequisites ......................................................... 94
SAP HANA ................................................................ 556 theme ..................................................................... 460 Security Assertion Markup Language User actions menu ........................................ 27, 414
SAP HANA Cloud ................................................... 557 versus SAP Fiori ................................................. 455 (SAML) .................................................................. 104 User authentication ............................................ 101
SAP HANA native applications ........................ 238 Web GUI ............................................................... 453 Semantic object ..................................................... 137 User authentication and SSO ............................. 87
SAP Launchpad service ................................ 69, 252 SAP Smart Business ................................................ 34 Service implementation .................................... 216
site manager tools .............................................. 70 Service modeler .............................................. 44, 255
568 569
First-hand knowledge.
SAP Fiori: Implementation and Development We hope you have enjoyed this reading sample. You may recommend or pass it
on to others, but only in its entirety, including all pages. This reading sample and
570 pages | 12/2022 | $89.95 | ISBN 978-1-4932-2204-9
all its parts are protected by copyright law. All usage and exploitation rights are
www.sap-press.com/5449 reserved by the author and the publisher.