0% found this document useful (0 votes)
130 views81 pages

CAA361 Compound

CAA361_compound

Uploaded by

VerticalStatue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
130 views81 pages

CAA361 Compound

CAA361_compound

Uploaded by

VerticalStatue
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

BUILD A TRANSACTIONAL SAP FIORI APP

WITH THE ABAP RESTFUL PROGRAMMING


MODEL
CAA361

Exercises / Solutions
Shyam Balachandran, Simon Collet, Volker Drees, Thomas
Gauweiler, Gopalakrishnan Ramachandran / SAP SE
CAA361

TABLE OF CONTENTS

BEFORE YOU START ............................................................................................................................................ 3


FIND THE CODE SNIPPETS AND CONNECT TO THE SYSTEM ........................................................................ 7
Overview ................................................................................................................................................................. 7
Code Snippets ....................................................................................................................................................... 7
Connect to the system .......................................................................................................................................... 8
Summary .............................................................................................................................................................. 18
BUSINESS SERVICES ......................................................................................................................................... 19
Overview ............................................................................................................................................................... 19
SERVICE DEFINITION ......................................................................................................................................... 20
SERVICE BINDING ............................................................................................................................................... 21
FIORI ELEMENTS APP PREVIEW ...................................................................................................................... 22
Create a Service Definition ................................................................................................................................. 22
Create a Service Binding .................................................................................................................................... 27
Fiori Elements App Preview ............................................................................................................................... 30
Summary .............................................................................................................................................................. 31
TRANSACTIONAL SCENARIO............................................................................................................................ 33
Overview ............................................................................................................................................................... 33
Composition Model ............................................................................................................................................. 36
Behavior Definition .............................................................................................................................................. 38
Optional: Entity Manipulation Language .......................................................................................................... 45
Validation.............................................................................................................................................................. 53
Static Field Control .............................................................................................................................................. 58
Determination ...................................................................................................................................................... 59
Action.................................................................................................................................................................... 62
Dynamic Feature Control .................................................................................................................................... 68
Optional: Testing ................................................................................................................................................. 73
Summary .............................................................................................................................................................. 78
COPYRIGHT ......................................................................................................................................................... 81

2
CAA361

BEFORE YOU START


Introduction
This document will guide you to build a transactional SAP Fiori Elements Application based
on the ABAP RESTful Programming Model, which will finally look like this:

We’ll build the application step by step starting with exposing an OData service based on a
prepared Core Data Services model with annotations and display it in a List Report based on
Fiori Elements. Then we’ll enhance this model to a Business Object with CRUD (Create,
Read, Update, Delete) operations and business specific functionality.

Further reading:
Link: Developing New Managed Transactional Apps

System Information
Before you start, here is some technical information that you will need during the exercise.
You’ll work on an ABAP system on the SAP Cloud Platform, which is called SAP Cloud
Platform ABAP Environment.
The screenshots for this exercise have been prepared using group number 931 and system
Y08. The explanation in the following exercises will remind you to use your group number
(indicated by ###) on system T06. Moreover, you will create ABAP artifacts in package
ZCAA361_EX_###, while all screenshots show package ZCAA361_EX_931 for illustration
purposes.
You can find suggested solutions to the exercises in package ZCAA361_EX_SOL. As this is a
hands-on exercise, some of the exercises require a certain amount of coding. As we want to
focus on the “getting to know the end-to-end story”, you won’t need to type all that coding
yourself but rather copying the given prepared coding from this document or your user share.

Further reading:
Link: SAP Cloud Platform ABAP Environment

Business Scenario

3
CAA361

The Fiori App you are going to implement is based on the new sample scenario: The Flight
Reference Scenario for the ABAP RESTful Programming Model.
To set the business context the scenario is the following: The department responsible for
managing worldwide Travels for multiple Agencies is requesting you to build a new SAP Fiori
app for processing (i.e. creating, updating and deleting) Travels.

Data Model

A Travel entity defines general travel data,


such as the agency ID or customer ID, status
Travel of the travel booking, and the price of travel.
The travel data is stored in the database table
/DMO/TRAVEL.
An Agency entity defines travel agency data,
such as the address and contact data. The
corresponding data is stored in the database
Agency
table /DMO/AGENCY. The flight data model
defines a 1:n cardinality between Agency and
Travel.
The booking data is stored in the database
table /DMO/BOOKING. The flight data model
Booking
defines a 1:n cardinality between a Travel
and the Booking entity.
The concrete flight data for each connection
is stored in the database table
Flight /DMO/FLIGHT. The flight data model defines
a 1:n cardinality between the Connection and
the Flight entity.
A Customer entity provides a detailed
description of a flight customer (passenger)
Customer such as the name, the address, and contact
data. The corresponding data is stored in the
database table /DMO/CUSTOMER. The flight

4
CAA361

A Travel entity defines general travel data,


such as the agency ID or customer ID, status
Travel of the travel booking, and the price of travel.
The travel data is stored in the database table
/DMO/TRAVEL.
data model defines a 1:n cardinality between
Customer and Travel

Further reading:
Link: Reference Business Scenario

Architecture Overview
The figure below illustrates the architecture components of the ABAP RESTful Programming
Model. It shows the main technologies needed to build an SAP Fiori Elements Application
based on the ABAP RESTful Programming Model. Afterwards you’ll find a description of
these components.

Further reading:
Link: ABAP RESTful Programming Model
Link: Concepts

Hints and Tips


Speed up the typing by making use of the Code Completion feature (shortcut Ctrl+Space) or
the prepared Code Snippets mentioned in the next section.
You can easily open an object with the shortcut Ctrl+Shift+A.
The screenshots in this document have been taken for group number 931.

Chapter 1: Connecting to the System


Estimated Duration: 15 minutes

5
CAA361

Chapter 2: Business Services


Estimated Duration: 20 minutes

Chapter 3: Transactional Scenario


Estimated Duration: 60-95 minutes

6
CAA361

FIND THE CODE SNIPPETS AND


CONNECT TO THE SYSTEM
Overview
Estimated time: 15 minutes

Code Snippets
All the code blocks mentioned in this document are stored on the network share. To save
time and prevent typos, feel free to use them.
Connect to the system
An ABAP cloud project mediates between the ABAP backend for developing ABAP
applications in the context of ABAP Environment and ADT. Projects like these provide a
framework that enables you to create, process, and test development objects for SAP Cloud
Platform products.
Before you can start using ABAP Development Tools (ADT), you first need to create an
ABAP cloud project which represents the system connection to your ABAP backend.

Further reading:
Link: Working with ABAP Cloud Projects
Link: ABAP Cloud Projects

Exercise Description
• You'll be guided to the code snippets which are also mentioned in this document.
• Set up your ABAP Development Tool for Eclipse

Code Snippets

Explanation Screenshot

1. Go to your Desktop and


double click on the entry

Student (Share) to
open it.

7
CAA361

Explanation Screenshot

2. Double click on the entry


CAA361 to open it.

3. In the folder CodeSnippets


you’ll find all the code pieces
mentioned in this document.
(The file T06.txt contains the
system information and will be
used in the next section).

Connect to the system

Explanation Screenshot

8
CAA361

Explanation Screenshot

1. Click the double arrow .

2. Click the SAP Development


Tools menu item to open it.

3. Click the ABAP in Eclipse -


CAA361 menu item to open it.

4. Eclipse will now launch.

9
CAA361

Explanation Screenshot

5. Click Go to the

workbench .

6. Click Open Perspective


in the upper right corner.

10
CAA361

Explanation Screenshot

7. Select the entry ABAP by


clicking it.

8. Click Open.

9. Create a new connection to


the SAP Cloud Platform ABAP
Environment system by clicking
in
the left panel.

11
CAA361

Explanation Screenshot

10. Mark Service Key.

11. Click .

12. Click Import... .

12
CAA361

Explanation Screenshot

13. Go to studentshare...

14. ... and double click on the


entry CAA361 to open it.

15. Select the entry T06.txt by


clicking it.

16. Click Open.

17. Click Next >.

18. Alternatively you can copy


the service key from here:
{
"sap.cloud.service":
"com.sap.cloud.abap",
"url":
"https://40fc02fc-57b0-
4eb9-83e0-
2076807bb848.abap.eu10.
hana.ondemand.com",
"systemid": "T06",
"uaa": {
"uaadomain":
"authentication.eu10.ha
na.ondemand.com",
"tenantmode":
"dedicated",
"sburl":
"https://internal-
xsuaa.authentication.eu
10.hana.ondemand.com",

13
CAA361

Explanation Screenshot
"clientid": "sb-xs-
40fc02fc-57b0-4eb9-
83e0-
2076807bb848!b17744|xsu
aa-abapcp-prod-
eu10!b4584",
"verificationkey": "-
----BEGIN PUBLIC KEY---
--
MIICIjANBgkqhkiG9w0BAQE
FAAOCAg8AMIICCgKCAgEAwT
hn6OO9kj0bchkOGkqYBnV1d
Q3zU/xtj7Kj7nDd8nyRMcEW
CtVzrzjzhiisRhlrzlRIEY8
2wRAZNGKMnw7cvCwNixcfcD
Jnjzgr2pJ+5/yDZUc0IXXyI
WPZD+XdL+0EogC3d4+fqyvg
/BF/F0t2hKHWr/UTXE6zrGh
BKaL0d8rKfYd6olGWigFd+3
+24CKI14zWVxUBtC+P9Fhng
c9DRzkXqhxOK/EKn0HzSgot
f5duq6Tmk9DCNM4sLW4+ERc
6xzrgbeEexakabvax/Az9WZ
4qhwgw+fwIhKIC7WLwCEJaR
sW4m7NKkv+eJR2LKYesuQ9S
VAJ3EXV86RwdnH4uAv7lQHs
KURPVAQBlranSqyQu0EXs2N
9OlWTxe+FyNkIvyZvoLrZl/
CdlYc8AKxRm5rn2/88nkrYQ
0XZSrnICM5FRWgVF2hn5KfZ
GwtBN85/D4Yck6B3ocMfyX7
e4URUm9lRPQFUJGTXaZnEIg
e0R159HUwhTN1HvyXrs6uT1
ZZmW+c3p47dw1+LmUf/hIf8
zd+uvHQjIeHEJqxjqfyA8yq
AFKRHKVFrwnwdMHIsRap2EK
BhHMfeVf0P2th5C9MggYoGC
vdIaIUgMBX3TtCdvGrcWML7
hnyS2zkrlA8SoKJnRcRF2Kx
WKs355FhpHpzqyZflO5l98+
O8wOsFjGpL9d0ECAwEAAQ==
-----END PUBLIC KEY----
-",
"apiurl":
"https://api.authentica
tion.eu10.hana.ondemand
.com",
"xsappname": "xs-
40fc02fc-57b0-4eb9-
83e0-
2076807bb848!b17744|xsu
aa-abapcp-prod-
eu10!b4584",
"identityzone":

14
CAA361

Explanation Screenshot
"caa361-teched2019",
"identityzoneid":
"ff0c7f17-6c0a-4cb2-
ac65-b4c5d76b84d4",
"clientsecret":
"0G2NHaYSWjbAgimKGb/+eT
sCVEI=",
"tenantid":
"ff0c7f17-6c0a-4cb2-
ac65-b4c5d76b84d4",
"url":
"https://caa361-
teched2019.authenticati
on.eu10.hana.ondemand.c
om"
},
"endpoints": {
"abap":
"https://40fc02fc-57b0-
4eb9-83e0-
2076807bb848.abap.eu10.
hana.ondemand.com"
},
"catalogs": {
"abap": {
"path":
"/sap/opu/odata/IWFND/C
ATALOGSERVICE;v=2",
"type":
"sap_abap_catalog_v1"
}
},
"binding": {
"env": "cf",
"version": "1.0.1.1",
"type": "oauth",
"id":
"h7BxbIXlaUXqmf0RyRtvvS
4snJnmjr9WDvoE"
}
}

15
CAA361

Explanation Screenshot

19. Enter CAA361-


###@teched.cloud.sap in
the Email box.
Remember: ### needs to be
replaced with your group
number.

20. Enter Welcome19 in the


Password box.

21. Click Log On.

22. Click Finish.

16
CAA361

Explanation Screenshot

23. A new ABAP Cloud Project


was created.

24. Click on Favorite


Packages with the right mouse
button.

25. Click the Add Package...


menu item to execute it.

26. Add your exercise package


ZCAA361_EX_###.

27. Select the entry


ZCAA361_EX_###
(Package) by clicking it.

28. Click OK.

17
CAA361

Explanation Screenshot

29. Repeat the step and add


the solution package
ZCAA361_SOL.

30. Select the entry


ZCAA361_SOL (Package) by
clicking it.

31. Click OK.

32. You successfully added the


relevant packages for this
session to your favorites!

Summary
You have completed the exercise!
You are now able to:
• Access the prepared code snippets
• Connect your ABAP Development Tools in Eclipse to an ABAP Cloud Project

18
CAA361

BUSINESS SERVICES
Overview
Estimated time: 20 minutes

Definition

The ABAP development platform can act in the roles of service provider and service
consumer, such as SAP Fiori UI client.
In the context of the ABAP RESTful Programming Model, a business service is a RESTful
service which can be called by a consumer. It is defined by exposing data models and
behavior models. It consists of a Service Definition and a Service Binding.

Business Services in the ABAP RESTful Programming Model


As illustrated in the figure below, the programming model distinguishes between the data
model, behavior and the service that is defined by exposing these models. The data and
behavior model layer contain domain-specific semantic entities like business objects, list
views, and analytical queries, and, in addition, related functionality such as value help,
feature control, and reuse objects.

Further reading:
Link: Business Service
Link: Creating an OData Service

19
CAA361

SERVICE DEFINITION
A Business Service Definition (short form: Service Definition) is an ABAP Repository object
that describes the consumer-specific perspective on a data model. Its transport type is
SRVD.

Use
A Service Definition represents the service model that is generically derived from the
underlying CDS-based data model. You use a Service Definition to define which data is to be
exposed (with the required granularity) as a Business Service. A Service Definition is
independent from the version or type of the protocol that is used for the Business Service;
the protocol is specified in a Business Service Binding (short form: Service Binding).

Further reading:
Link: Service Definition
Link: Creating a Service Definition

20
CAA361

SERVICE BINDING
The business service binding (short form: service binding) is an ABAP Repository object
used to bind a service definition to a client-server communication protocol such as OData.
Like any other repository object, the service binding uses the proven infrastructure of the
ABAP Workbench, including the transport functions. The transport type of a service binding
is SRVB.

Use
As shown in the figure below, a service binding relies directly on a service definition that is
derived from the underlying CDS-based data model. Based on an individual service
definition, a plurality of service bindings can be created. The separation between the service
definition and the service binding enables a service to integrate a variety of service protocols
without any kind of re-implementation. The services implemented in this way are based on a
separation of the service protocol from the actual business logic.

Separation Between the Service Definition and the Service Binding


In SAP Fiori, many role-based and task-oriented apps are based on the same data, and
related functionality must be created to support end users in their daily business and in their
dedicated roles. This is implemented by reusable data and behavior models, where the data
model and the related behavior is projected in a service-specific way. The service definition
is a projection of the data model and the related behavior to be exposed, whereas the
service binding implements a specific protocol and the kind of service to be offered to a
consumer. This separation allows the data models and service definitions to be integrated
into various protocols without any re-implementation.

Further reading:
Link: Service Binding
Link: Creating a Service Binding

21
CAA361

FIORI ELEMENTS APP PREVIEW


Once you have published your OData Service you could build a Fiori Elements List
Report upon it via SAP Web IDE. This would be the usual way if you wish to publish
a UI to your service, or implement UI specific enhancements. If you don’t need any
customization of the Fiori Elements List Report, the Fiori Elements App Preview is a
handy tool to quickly preview a fully functional Fiori Elements List Report.

Further reading:
Link: Previewing the Resulting UI Service
Link: UI Annotations

Exercise Description

• Create a Service Definition and expose the main entities of your service
• Create a Service Binding via a wizard
• Publish the service
• Have a look at the metadata document of the service
• Open the Fiori Elements App Preview and browse through your data

Create a Service Definition

Explanation Screenshot

1. Click Open ABAP


Development Object or
press Ctrl+Shift+A.

22
CAA361

Explanation Screenshot

2. Enter the name of your


Travel Projection CDS View
ZCAA361_C_TRAVEL_###.

3. Select it

4. Click OK

23
CAA361

Explanation Screenshot

5. Hint: If you have Link with


Editor enabled, you’ll see the
CDS View in the Project
Explorer.

6. Right click on your Travel


CDS View
ZCAA361_C_TRAVEL_### in
the Project Explorer ...

24
CAA361

Explanation Screenshot

7. ... and click on New Service


Definition.

8. The New Service Definition


wizard is shown. Enter the
name
ZCAA361_UI_TRAVEL_###
and a proper Description.

9. Click Next.

25
CAA361

Explanation Screenshot

10. Create a new Transport


Request, place a proper
Description, leave the CTS
Project empty.

11. Click Finish.

12. The wizard creates the


exposure of your Travel CDS
View
ZCAA361_C_TRAVEL_###.

13. Add your Booking CDS-


View
ZCAA361_C_BOOKING_###
as well, as you want to be able
to navigate from Travel to
Booking.

expose
ZCAA361_C_Booking_###
as Booking;

Hint: You can use the code


completion for keywords and
objects.

14. Provide an alias for the


Travel entity.
expose
ZCAA361_C_Travel_### as
Travel;

26
CAA361

Explanation Screenshot

15. Save and activate:


• Ctrl + S
• Ctrl + F3

Create a Service Binding

Explanation Screenshot

1. Do a right click on your


Service Definition
ZCAA361_UI_TRAVEL_###
and select New Service
Binding.

27
CAA361

Explanation Screenshot

2. Enter
ZCAA361_UI_TRAVEL_###_
O2 in the Name box.

3. Enter a proper description in


the Description box.

4. For Binding Type select


ODATA V2 - UI.

5. Ensure that the Service


Definition is set to your
ZCAA361_UI_TRAVEL_###.

6. Click Next.

7. Choose your Transport


Request

8. Click Finish.

9. To publish your OData


Service, click on Activate.

28
CAA361

Explanation Screenshot

10. All exposed entities and


their associations are now
listed below.

11. Click on Service URL to


access your service in the
browser.

29
CAA361

Explanation Screenshot

12. Enter CAA361-


###@teched.cloud.sap in
the Email box.

13. Enter Welcome19 in the


Password box.

14. Click Log On.

15. You now see the Service


Document.
Please Note: In case you get a
Forbidden error message,
please wait a few seconds and
refresh.

16. You can also add


$metadata in the URL to see
the Metadata Document of your
service. The screenshot shows
the entity type TravelType.

17. Feel free to play around.


The screenshot shows the
request for the Entity Set
Travel and fetches two entries
with the keyword $top. For
further information have a look
into the OData documentation.

Fiori Elements App Preview

Explanation Screenshot

30
CAA361

Explanation Screenshot

1. Go back to your ADT and


your Service Binding
ZCAA361_UI_TRAVEL_###_
O2 and double-click on the
Travel entity or the navigation
property to_Booking.

2. The Fiori Elements App


Preview opens.

3. Click Go.

4. Feel free to play around

Summary
You have completed the exercise!

31
CAA361

You are now able to:


• Define a service via Service Definition

• Expose your service via Service Binding in several ways

• Consume your service in a Fiori Elements via Fiori Elements App Preview

32
CAA361

TRANSACTIONAL SCENARIO
Overview
Estimated time: 60 minutes ( 95 minutes with optional track )

Introduction
A Business Object (BO) is a common term to represent a real-world artifact in enterprise
application development such as the Product, the Travel, or the SalesOrder. In general, a
business object contains several nodes such as Items and ScheduleLines and common
transactional operations such as for creating, updating and deleting data and additional
application-specific operations, such as Approve in a SalesOrder business object. All
changing operations for all scenario-related business objects form the transactional
behavior in a development scenario.

When going to implement a concrete application scenario based on business objects, we


need to distinguish the external, consumer-related representation of a business object from
the internal provider-related perspective:
• The consumer perspective hides the intrinsic complexity of business objects.
Developers who want to create a service on top of the existing business objects
for role-based UIs do not need to know the respective implementation details.
The same also applies to all developers who need to implement a consumer on
top of the business object’s APIs.
• The provider perspective exposes the internal implementation and the
complexity of business objects. This is required for application developers who
want to provide new or extend existing business objects for the industries, the
globalization and partners.
From a formal point of view, a business object is characterized by
· a structure,
· a behavior and
· the corresponding runtime implementation.

Further reading:
Link: Developing New Managed Transactional Apps
Link: Data Modeling and Behavior

Composition Model
From a structural aspect, a business object consists of a tree of nodes where the nodes are
linked by means of a special kind of associations, the compositions. A composition is a
specialized association that defines a whole-part relationship. A composite part only exists
together with its parent entity (whole).
Each node of this composition tree is an element that is modeled with a CDS entity. The root
entity is of particular importance: It defines the top node in a business object's structure and
serves as a representation of the business object. The root entity is marked with the keyword
ROOT in the CDS data definition’s source code.
Further reading:
Link: Providing Business Object Structure
Link: Developing a Projection Layer for Flexible Service Consumption
Link: Business Object

Behavior Definition

33
CAA361

A Business Object Behavior Definition (Behavior Definition for short) is an ABAP Repository
object that describes the behavior of a business object in the context of the ABAP RESTful
programming model. A behavior definition is defined using the Behavior Definition Language
(BDL) and comprises capabilities and modelling aspects of the business object node or
nodes, for example the supported operations (such as create, update, and delete actions) or
the definition of lock dependencies between the parent and child nodes.
A behavior definition always refers to a CDS data model. This reference results from the
name equality with the root entity. This means that a CDS data model must always exist
before the behavior definition is created.
As shown in the figure below, a behavior definition relies directly on the CDS root entity. One
behavior definition refers exactly to one root entity and one CDS root entity has a maximum
of one behavior definition (0..1 relationship), which also handles all associated (child)
entities. The implementation of a behavior definition can be done in a single ABAP class
(behavior pool) or can be split between an arbitrary set of ABAP classes (behavior pools).
You can assign any number of behavior pools to a behavior definition (1: n relationship).

Relationship Between the Data Model, the Behavior Definition, and the Behavior
Implementation.
Further reading:
Link: Defining Elementary Behavior for Ready-to-Run Business Object
Link: Working with Behavior Definitions

Entity Manipulation Language


The Entity Manipulation Language (EML) is a typed API to access business objects,
conceptually very similar to Open SQL. EML is not for DB tables but for business objects
including their business logic.
Further reading:
Link: Entity Manipulation Language (EML)
Link: Consuming Business Objects with EML

Validation
A validation is an implicitly executed function intended to check the data consistency of an
existing instance of an entity (consistency validation). It is implicitly invoked by the business
object’s framework as soon as a trigger condition at a predefined point in time is fulfilled.
Validation can return messages to the consumer and reject inconsistent instance data from
being saved.
Further reading:
Link: Developing Validations

Static Field Control

34
CAA361

As an application developer, you may want to determine, which fields of your business
object’s entities should be read-only or mandatory. If this property is valid for all instances of
your business object then Static Field Control is the answer.
Further reading:
Link: Adding Static and Dynamic Feature Control

Determination
A determination is an implicitly executed function that handles side effects of modified entity
instances. It is invoked by the business object’s framework as soon as a determination’s
trigger condition at a predefined point in time, the determination time, is fulfilled.
Determinations are triggered internally based on changes made to the entity instance of a
business object. The trigger conditions are checked by business object framework at
different points during the transaction cycle, depending on the determination time and the
changing operations on the relevant entity instances. For each determination, it is necessary
to specify both the determination time and the changes that form the trigger condition. A
trigger condition consists of a list of fields belonging to the same entity the determination is
assigned to and the changing operations that include creating or updating entity instances.
We call this operations trigger operations.
In case a field is changed (after creation or update), the condition is fulfilled. The framework
evaluates the triggering condition of all determinations at certain points in time (determination
time). For determinations, this is today either after each modification or during the save
phase.
You can use a determination primarily to compute data that is derived from the values of
other fields. The determined fields and the determining fields either belong to the same entity
or to different entities of a business object.
As a result, determination can modify entity instances and return transition messages (error,
warning, information, success).
Further reading:
Link: Developing Determinations

Action
An action is assigned to an individual entity of a business object and is used to implement a
modifying non-standard operation as part of the business logic.
Further reading:
Link: Developing Actions

Dynamic Feature Control


As an application developer you may want to determine based on certain attributes of your
business object entity, which fields should be read-only or mandatory or which functionality
like update or actions are allowed. As this property is related to an instance of this business
object it is called Dynamic Feature Control.
Further reading:
Link: Adding Static and Dynamic Feature Control

Testing
As an application developer you may want to write integration tests to verify the behavior as
a whole.
Further reading:
Link: Testing the Business Object
Link: Ensuring Quality of ABAP Code

Objective
In the following exercises you will learn how to setup a transactional scenario. The
following topics will be covered:

Exercise Description

35
CAA361

• Composition Model
• See the composition Travel with root and Booking as child
• See Projection Views
• Behavior Definition
• Create a Behavior Definition via wizard
• Enable Create, Update and Delete on Travel entity
• Enable Create by Association, Update and Delete for the sub node
Booking
• Entity Manipulation Language
• Create an executable class which returns the output in the console of
your ABAP Development Tools
• Perform a Read operation on the Travel entity
• Validation
• Define and implement a Validation to check that the Begin Date is before
the End Date
• Static Field Control
• Define Static Field Control by keeping the Status as read only
• Determination and Actions
• Define and implement a Determination to set the Status for new Travel to
New
• Define and implement an Action to set the Status to Booked
• Dynamic Feature Control
• Set the Travel_ID to read-only if it’s filled.
• Enable the action bookTravel and the Update operation depending on the
Status of the Travel.
• Testing the application
• Create a new ABAP Unit Test Class.

• Get in touch with the ABAP Unit Test Methods class_setup, setup and
teardown.

• Use the OpenSQL Test Environment to mock the related database tables.

• Implement ABAP Unit Test using Entity Manipulation Language and the
ABAP Unit Test environment.

Composition Model

Explanation Screenshot

36
CAA361

Explanation Screenshot

1. Open your Travel CDS View


ZCAA361_I_TRAVEL_### by
pressing Ctrl+Shift+A or by
using the Project Explorer.

2. Select it.

3. Click OK.

4. The keyword root indicates


that this entity is the root of the
Business Object.

5. At the association definitions


you find composition which
defines a child entity.

6. Navigate via Ctrl+Click


to your Booking CDS View
ZCAA361_I_BOOKING_###.

7. Here you find the backward


association from the child
Booking to the parent Travel.

37
CAA361

Explanation Screenshot

8. Open your Travel


Consumption CDS View
ZCAA361_C_TRAVEL_### by
pressing Ctrl+Shift+A or by
using the Project Explorer.

9. Select it.

10. Click OK.

11. Have a look at the new


CDS entity type Projection
View.

12. Associations and


compositions are defined at the
field list like _Booking.

Behavior Definition

Explanation Screenshot

38
CAA361

Explanation Screenshot

1. Right click on your Travel


CDS View
ZCAA361_I_TRAVEL_### in
the Project Explorer.

2. Click New Behavior


Definition.

3. The New Behavior


Definition wizard is shown. If
you like you can adjust the
Description. Ensure that the
Implementation Type is set to
Managed.

4. Click Next.

39
CAA361

Explanation Screenshot

5. Select your Transport ...

6. ... and click Finish.

7. A skeleton of a Behavior
Definition is generated.

8. Provide an alias for Travel.


The alias is used when
accessing the entity via ABAP
code.
alias Travel

9. Use the generated


comments to enable lock
master for the Travel entity.
In the managed scenario the
lock is handled generic by the
framework.
lock master

40
CAA361

Explanation Screenshot
10. Change the
<field_name> at etag to
Last_Changed_At for the
Travel entity. This enables
OData etag-handling for the
entity.
etag Last_Changed_At

11. For the Booking entity set


the persistent table to
ZCAA361_BOOK_###.
persistent table
zcaa361_book_###
Hint: Use the code completion
by pressing Ctrl+Space.

12. Enable lock dependent


for Booking by linking
Booking’s Travel_ID to that
of Travel’s. Lock master and
lock dependent(s) define the
lock-shadow of a business
object.
lock dependent(
Travel_ID = Travel_ID )

13. Provide an alias for


Booking.
alias Booking

14. Set Last_Changed_At


as Booking’s Etag.
etag Last_Changed_At

15. Set Travel_ID for the


Booking entity as read-only.
This ensures the parent-key is
derived properly when
performing a create-by-
association (like the Fiori
Elements app is doing it).
field ( readonly )
Travel_ID;

41
CAA361

Explanation Screenshot

16. Save and activate:


• Ctrl + S
• Ctrl + F3

17. Switch back to your Fiori


Elements app and refresh it. It
still does not have any
transactional behavior, for
example, there is no create
button.

18. To define the transactional


behavior for the Fiori Elements
app you need a Behavior
Definition for the Business
Object Projection
ZCAA361_C_Travel_###.
Therefore, switch back to your
ADT and right click on your
Travel CDS Projection View
ZCAA361_C_TRAVEL_### in
the Project Explorer and select
New Behavior Definition.

19. Click New Behavior


Definition.

42
CAA361

Explanation Screenshot

20. If you like you can adjust


the Description. Ensure that the
Implementation Type is set to
Projection.

21. Click Next.

22. Select your Transport


Request.

23. Click Finish.

24. The wizard generated the


whole transactional behavior
inherited from the Behavior
Definition
ZCAA361_I_TRAVEL_###
underneath.

43
CAA361

Explanation Screenshot
25. Provide an alias for Travel.
alias Travel

26. Make use of the ETag.


use etag

27. Provide an alias for


Booking.
alias Booking

28. Save and activate:


• Ctrl + S
• Ctrl + F3

29. Switch back to your Fiori


Elements app and refresh it.
Now, you can create, update
and delete Travels and
Bookings.
Please Note: You have to
manually provide a unique
Travel_ID when creating new
Travels.

44
CAA361

Explanation Screenshot

30. Feel free to play around.


The screenshot shows a Travel
in Edit mode.

Optional: Entity Manipulation Language

Explanation Screenshot

1. Create a new Class by right-


clicking on your package
ZCAA361_EX_###.

2. Click New and ABAP Class.

3. The New ABAP Class wizard


is shown. As Name provide
ZCL_CAA361_EML_### and
give it a proper Description.

4. Click Next.

45
CAA361

Explanation Screenshot

5. Select your Transport


Request.

6. Click Finish.

7. An ABAP Class skeleton is


generated automatically.

46
CAA361

Explanation Screenshot

8. In the Public Section add the


interface
IF_OO_ADT_CLASSRUN.
INTERFACES
if_oo_adt_classrun.

9. Keep your cursor in the line


and press Ctrl+1 to access
the Quick Assist and choose
Add implementation for
main.

10. Method
if_oo_adt_classrun~ma
in is generated.

47
CAA361

Explanation Screenshot
11. We start by reading all
Bookings related to its Travel.
To do so use the EML
statement READ. In this
particular case it’s a Read-by-
Association.
READ ENTITIES OF
zcaa361_i_travel_###
ENTITY travel
BY \_Booking
FROM VALUE #( (
Travel_ID = '1337' ) )
RESULT
DATA(lt_bookings).
lt_bookings contains now all
Bookings of Travel 1337. You’ll
use these Bookings later.

12. Save and activate:


• Ctrl + S
• Ctrl + F3

48
CAA361

Explanation Screenshot

13. Optional: Set a breakpoint


at ENDMETHOD by double
clicking on the line number.
The blue circle indicates a
breakpoint.

14. Press F9 to run the ABAP


Application as a console
application.

15. Click Switch.

16. Optional: Double click on


lt_bookings.

17. Optional: In the ABAP


Internal Table (Debugger) view
you will find all read bookings.
Keep in mind that we have only
requested the keys and not any
other fields.

18. Optional: Click Resume to


continue the debug session.

49
CAA361

Explanation Screenshot

19. Optional: Switch back to


the ABAP perspective.

20. Optional: Remove the


breakpoint by double clicking it.

21. Next, do an Update on the


Travel with ID 1337 and
change the Description.
MODIFY ENTITIES OF
zcaa361_i_travel_###
ENTITY travel
UPDATE FROM VALUE
#( ( travel_id
= '1337'
description
= 'I like ABAP'
%control-
description =
if_abap_behv=>mk-on )
).
Remark: For productive
purpose make sure to
implement FAILED and
REPORTED for proper error
handling.

50
CAA361

Explanation Screenshot

22. Optional: Save and


activate. Run the class with F9.
Then have a look at your Fiori
App and filter the Travel ID by
1337. Remember the leading
zeros! It’s numc(8). You’ll see
that the Description has
not changed.

23. Now commit the entities.


COMMIT ENTITIES.
Save and activate and run the
class with F9.

24. Go to your Fiori App, reload


it and have a look at the Travel
where Travel ID is 1337. The
easiest way to find this Travel
is by using the related filter.

25. Click Go.

26. Click the found Travel.

51
CAA361

Explanation Screenshot

27. The description has


changed!

28. Go back to your ADT and


select any Flight as you will
now implement a create by
association.
SELECT SINGLE FROM
/dmo/flight
FIELDS carrier_id,
connection_id,
flight_date
INTO
@DATA(ls_flight).

29. Expand the MODIFY but


this time with the create by
association. Mind the dot.
CREATE BY \_booking
FROM VALUE
#( (
travel_id =
'1337'
%target = VALUE
#(
(
booking_id
= VALUE #( lt_bookings[
lines( lt_bookings ) ]-
booking_id OPTIONAL ) +
1
booking_date
=
cl_abap_context_info=>g
et_system_date( )
carrier_id
= ls_flight-carrier_id
connection_id
= ls_flight-
connection_id

52
CAA361

Explanation Screenshot
flight_date
= ls_flight-
flight_date
Customer_ID
= '4'
%control
= VALUE #( booking_id
= if_abap_behv=>mk-on

booking_date
= if_abap_behv=>mk-on

carrier_id
= if_abap_behv=>mk-on

connection_id
= if_abap_behv=>mk-on

flight_date
= if_abap_behv=>mk-on

Customer_ID
= if_abap_behv=>mk-on
)
) )
) ).

Save and activate and run the


class with F9.

30. Go to your Fiori App, reload


it and have a look at the Travel
where Travel ID is 1337. You’ll
now see an additional Booking.

Validation

Explanation Screenshot

53
CAA361

Explanation Screenshot

1. Go back to your Behavior


Definition
ZCAA361_I_TRAVEL_###.

2. Define a Validation in the


Travel entity which is triggered
on save and uses the date
fields Begin_Date and
End_Date.
validation
validateDates on save {
field begin_date,
end_date; }

3. As the error says you need


to specify a unique
implementation class.

4. Use the generated proposal


in the first line. Mind the
semicolon!
managed implementation
in class
zbp_caa361_i_travel_###
unique;

5. Save and activate:


• Ctrl + S
• Ctrl + F3

6. Set your cursor at the


proposed class name and
press Ctrl+1 to access the
Quick Assist.

7. Click Create behavior


implementation class
ZBP_CAA361_I_TRAVEL_###
.

54
CAA361

Explanation Screenshot

8. A wizard for creating the


Behavior Implementation
appears. You might want to
change the Description.

9. Click Next.

10. Select your Transport ...

11. ... and click Finish.

12. A new class opens with a


generated method for your
Validation.

55
CAA361

Explanation Screenshot
13. Let’s start with reading the
date fields of the incoming
Travel keys.
READ ENTITY
zcaa361_i_travel_###\\t
ravel FROM VALUE #(
FOR <root_key> IN
keys
( %key =
<root_key>
%control = VALUE
#(

begin_date =
if_abap_behv=>mk-on

end_date =
if_abap_behv=>mk-on ) )
)
RESULT
DATA(lt_travel_result).

14. Loop over the Read result


LOOP AT
lt_travel_result INTO
DATA(ls_travel_result).
ENDLOOP.

15. We want to ensure that the


End_Date is after the
Begin_Date. So only if this
condition is violated messages
are necessary.
IF ls_travel_result-
end_date <
ls_travel_result-
begin_date.
ENDIF.

56
CAA361

Explanation Screenshot

16. To prevent the erroneous


entry to be saved, append its
%key to failed.
APPEND VALUE #( %key =
ls_travel_result-%key )
TO failed.

17. Now define a proper


message and append it with
%key and the corresponding
elements flagged in %element
to reported.
APPEND VALUE #(
%key =
ls_travel_result-%key
%msg =
new_message(
id
=
/dmo/cx_flight_legacy=>
end_date_before_begin_d
ate-msgid

number =
/dmo/cx_flight_legacy=>
end_date_before_begin_d
ate-msgno
v1
= ls_travel_result-
begin_date
v2
= ls_travel_result-
end_date
v3
= ls_travel_result-
travel_id

severity =
if_abap_behv_message=>s
everity-error )
%element-begin_date
= if_abap_behv=>mk-on
%element-end_date
= if_abap_behv=>mk-on
) TO reported.

57
CAA361

Explanation Screenshot
18. Save and activate:
• Ctrl + S
• Ctrl + F3

19. Switch back to your Fiori


Elements app ...

20. Click Create.

21. Try to create a Travel with


an end date before the
start date.

22. Click Save.

23. You’ll get an error


message.

Static Field Control

Explanation Screenshot

58
CAA361

Explanation Screenshot

1. Go back to your Behavior


Definition
ZCAA361_I_TRAVEL_###.

2. Make the field Status read


only.
field ( readonly )
Status;

3. Save and activate:


• Ctrl + S
• Ctrl + F3

4. Switch back to your Fiori


Elements app and refresh it.

5. Click Edit.

6. The field Status is now no


longer editable.

Determination

Explanation Screenshot

59
CAA361

Explanation Screenshot

1. Switch back to your Behavior


Definition
ZCAA361_I_TRAVEL_###.

2. Define a Determination
which sets the field Status to
N(new) if none is set. It’ll be
triggered when a new Travel
will be created.
determination
setInitialStatus on
modify { create; }

3. Save and activate:


• Ctrl + S
• Ctrl + F3

4. Open your Behavior


Implementation
ZBP_CAA361_I_TRAVEL_###
.

5. Click Local Types.

6. Declare a new method which


will implement the
Determination.
METHODS
set_initial_status
FOR DETERMINATION
Travel~setInitialStatus
IMPORTING keys FOR
Travel.

60
CAA361

Explanation Screenshot

7. As the method is not


implemented an error occurs.
Set your cursor on the method
name set_initial_status
and press Ctrl+1 to access
the Quick Fix proposals.
Choose Add implementation
for status_initial_status.

8. A new method was created.

9. Finally, hand over the


changes.
MODIFY ENTITIES OF
zcaa361_i_travel_### IN
LOCAL MODE
ENTITY Travel
UPDATE FROM VALUE
#( FOR travel IN keys (
%key
= travel-%key
Status
=
/dmo/if_flight_legacy=>
travel_status-new
%control-Status
= if_abap_behv=>mk-on
) )
REPORTED reported.

10. Save and activate:


• Ctrl + S
• Ctrl + F3

61
CAA361

Explanation Screenshot

11. Switch back to your Fiori


Elements app.

12. Click Create.

13. Enter some valid values,


especially a valid Travel ID.

14. Click Save.

15. The Status is


automatically set to N(New).

Action

Explanation Screenshot

62
CAA361

Explanation Screenshot

1. Switch back to your Behavior


Definition
ZCAA361_I_TRAVEL_###.

2. Define an Action for Travel to


set the Status to Booked.
action bookTravel
result [1] $self;

3. Save and activate:


• Ctrl + S
• Ctrl + F3

4. Open your Behavior


Implementation
ZBP_CAA361_I_TRAVEL_###
.

5. Click Local Types.

63
CAA361

Explanation Screenshot

6. Declare a new method which


will implement the Action.
METHODS book_travel FOR
MODIFY IMPORTING keys
FOR ACTION
travel~bookTravel
RESULT result.

7. As the method is not


implemented an error occurs.
Set your cursor on the method
name book_travel and
press Ctrl+1 to access the
Quick Fix proposals. Choose
Add implementation for
book_travel.

8. A method was created.

9. Without further check apply


the Status booked to the
incoming Travels.
MODIFY ENTITIES OF
zcaa361_i_travel_### IN
LOCAL MODE
ENTITY travel
UPDATE FROM VALUE
#( FOR key IN keys
( travel_id =
key-travel_id
status
=
/dmo/if_flight_legacy=>
travel_status-booked
%control-
status =
if_abap_behv=>mk-on ) )
FAILED failed
REPORTED reported.

64
CAA361

Explanation Screenshot

10. As you specified $self as


result for your action, you’ll first
need to load the data via Read.
READ ENTITIES OF
zcaa361_i_travel_### IN
LOCAL MODE
ENTITY Travel
FROM VALUE #(
FOR key IN keys
( travel_id
= key-travel_id
%control-
Travel_ID =
if_abap_behv=>mk-on
%control-
agency_id =
if_abap_behv=>mk-on
%control-
customer_id =
if_abap_behv=>mk-on
%control-
begin_date =
if_abap_behv=>mk-on
%control-
end_date =
if_abap_behv=>mk-on
%control-
booking_fee =
if_abap_behv=>mk-on
%control-
total_price =
if_abap_behv=>mk-on
%control-
currency_code =
if_abap_behv=>mk-on
%control-
status =
if_abap_behv=>mk-on
%control-
description =
if_abap_behv=>mk-on
%control-
created_by =
if_abap_behv=>mk-on
%control-
created_at =
if_abap_behv=>mk-on
%control-
last_changed_by =
if_abap_behv=>mk-on
%control-
last_changed_at =

65
CAA361

Explanation Screenshot
if_abap_behv=>mk-on
) )
RESULT
DATA(lt_travel_result).

11. Fill the result table.


result = VALUE #( FOR
ls_travel IN
lt_travel_result
(
travel_id = ls_travel-
Travel_ID

%param = CORRESPONDING
#( ls_travel )
) ).

12. Save and activate:


• Ctrl + S
• Ctrl + F3

13. Open your Behavior


Definition
ZCAA361_C_TRAVEL_### of
your Business Object
Projection
ZCAA361_C_TRAVEL_###.

14. To expose this action,


enhance the Travel entity.
use action bookTravel;

15. Save and activate:


• Ctrl + S
• Ctrl + F3

66
CAA361

Explanation Screenshot

16. Finally, open your


Projection CDS View
ZCAA361_C_Travel_###.

17. Go to the field


TravelStatus and activate
the inactive annotations at
@UI.lineItem and
@UI.identification.
The easiest way is to go to Edit
and click on Select All. Then
right click in the marked source
code, choose Source Code and
click on Remove Comment.

18. Save and activate:


• Ctrl + S
• Ctrl + F3

19. Select your Transport


Request.

20. Click Ok.

21. Switch back to your Fiori


Elements app, refresh it and
press the Book Travel button.

67
CAA361

Explanation Screenshot

22. Your Travel is now set to


B(Booked).

Dynamic Feature Control

Explanation Screenshot

1. Switch back to your Behavior


Definition
ZCAA361_I_TRAVEL_###.

2. After setting a Travel_ID it


should be read-only. Therefore,
a Dynamic Feature Control is
needed.
field ( features :
instance ) Travel_ID;

68
CAA361

Explanation Screenshot

3. For a booked Travel an


Update should not be possible.
Apply ( features :
instance ) to the update
operation.
update ( features :
instance );

4. The Action to book Travel


should also only be active if the
Status isn’t already set to
Booked. Therefore add (
features : instance ) to
the existing definition of the
Action bookTravel as well.
action ( features :
instance ) bookTravel
result [1] $self;

5. Save and activate:


• Ctrl + S
• Ctrl + F3

6. Open your Behavior


Implementation
ZBP_CAA361_I_TRAVEL_###
...

7. ... and go to the Local


Types

69
CAA361

Explanation Screenshot
8. Declare a new method which
will implement the Dynamic
Feature Control.
METHODS get_features
FOR FEATURES IMPORTING
keys
REQUEST
requested_features FOR
travel RESULT result.

9. As the method is not


implemented an error occurs.
Set your cursor on the method
name get_features and
press Ctrl+1 to access the
Quick Fix proposals.
Choose Add implementation
for get_features.

10. A new method was created.

11. Begin with reading the


Status of your incoming
Travels.
READ ENTITY
zcaa361_i_travel_###\\t
ravel FROM VALUE #(
FOR <root_key> IN
keys
( %key =
<root_key>
%control = VALUE
#( Status =
if_abap_behv=>mk-on ) )
)
RESULT
DATA(lt_travel_result).

70
CAA361

Explanation Screenshot
12. Set the fields to read only
according the Status of the
Travel.
result = VALUE #(
FOR ls_travel IN
lt_travel_result
LET
lv_is_not_booked =
COND #( WHEN
ls_travel-status = 'B'

THEN
if_abap_behv=>fc-o-
disabled

ELSE
if_abap_behv=>fc-o-
enabled )

lv_is_travel_initial =
COND #( WHEN ls_travel-
travel_id IS INITIAL

THEN
if_abap_behv=>fc-f-
mandatory

ELSE
if_abap_behv=>fc-f-
read_only ) IN
( %key
=
ls_travel-%key
%update
=
lv_is_not_booked
%field-
Travel_ID =
lv_is_travel_initial
%features-
%action-bookTravel =
lv_is_not_booked
) ).

13. Save and activate:


• Ctrl + S
• Ctrl + F3

71
CAA361

Explanation Screenshot

14. Switch back to your Fiori


Elements app, refresh it and
choose a booked Travel.
There is NO Edit and no Book
Travel button.

15. Select a Travel which is not


booked. The Edit and Book
Travel buttons are available.

16. Press Edit. Travel ID is


read-only.

17. Go back and create a new


Travel. Travel ID is now
editable and marked as
mandatory.

72
CAA361

Optional: Testing

Explanation Screenshot

1. Open your Behavior


Implementation
ZBP_CAA361_I_TRAVEL_###
...

2. ... and go to the Test


Classes tab.

3. Type test and hit


Ctrl+Space for the Code
Completion. Select testClass.

4. The test class skeleton is


inserted, ready for renaming
the artifacts...

5. Name the class


ltcl_integration_test
and the provided method
det_status.
Hint: If you stay at your ADT
and let the template active
(recognizable via rectangles)
you can tab between the input
fields.
class
ltcl_integration_test
definition final for
testing

73
CAA361

Explanation Screenshot
duration short
risk level harmless.

private section.
methods:
det_status for
testing raising
cx_static_check.
endclass.

class
ltcl_integration_test
implementation.

method det_status.

cl_abap_unit_assert=>fa
il( 'Implement your
first test here' ).
endmethod.

endclass.

6. Before you start writing the


test, set up mockups.
Therefore, define the methods
class_setup,
class_teardown and
teardown in the Private
Section.
CLASS-METHODS:
class_setup,
class_teardown.
METHODS:
teardown.

7. Set your cursor at one


method name and press
Ctrl+1 or click on the bulb
next to the line number to
access the Quick Assist and
choose Add 3 unimplemented
methods.

74
CAA361

Explanation Screenshot
8. In class_setup create the
mockup environment for the
CDS view
ZCAA361_I_TRAVEL_###.
go_environment =
cl_cds_test_environment
=>create_for_multiple_c
ds(
i_for_entities =
VALUE #( ( i_for_entity
=
'ZCAA361_I_TRAVEL_###'
) )
).

9. Set your cursor in


go_environment, press
Ctrl+1 or click on the bulb
and select Declare attribute
go_environment.

10. In the method


class_teardown destroy the
mockup environment.
go_environment-
>destroy( ).

11. And in the method


teardown clear the doubles.
ROLLBACK ENTITIES.
go_environment-
>clear_doubles( ).

12. Finally, you start


implementing your first test!
Therefore, clean the existing
implementation of the method
det_status.

75
CAA361

Explanation Screenshot
13. Create a new Travel.
MODIFY ENTITIES OF
zcaa361_i_travel_###
ENTITY Travel
CREATE FROM VALUE
#( (
Travel_ID = '1'
%control-
Travel_ID =
if_abap_behv=>mk-on
) )
FAILED
DATA(ls_failed)
REPORTED
DATA(ls_reported).

14. Expect that the create was


successful.
cl_abap_unit_assert=>as
sert_initial(
ls_failed-travel ).
cl_abap_unit_assert=>as
sert_initial(
ls_reported-travel ).

15. Commit the entity. This


triggers the Determination.
COMMIT ENTITIES.

76
CAA361

Explanation Screenshot

16. Read the Travel from the


buffer and request the field
Status.
READ ENTITIES OF
zcaa361_i_travel_###
ENTITY Travel
FROM VALUE #( (
Travel_ID =
'1'
%control-Status =
if_abap_behv=>mk-on
) )
RESULT
DATA(lt_travel).

17. Expect that:


• The read returned any
Travel.
• The Travel with ID 1 is
contained in the table.
• For the Travel with ID 1
the Status is set to N
(New).
cl_abap_unit_assert=>as
sert_not_initial(
lt_travel ).

cl_abap_unit_assert=>as
sert_not_initial(
VALUE #( lt_travel[
KEY entity COMPONENTS
Travel_ID = '1' ]
OPTIONAL )
).

cl_abap_unit_assert=>as
sert_equals(
exp = 'N'
act = lt_travel[
KEY entity COMPONENTS
Travel_ID = '1' ]-
Status
).

18. Save and activate:


• Ctrl + S
• Ctrl + F3

77
CAA361

Explanation Screenshot

19. Run the Unit Test. By either


using Ctrl+Shift+F10 or
right-click in the Outline view on
your test class Run As, then
ABAP Unit Test.

Summary
You have completed the exercise!
You are now able to:
• Define a Composition Model.
• Define the Business Object.

• Define the Consumption via Projection Views.

• Define the Business Behavior.

78
CAA361

• Define the Business Object Projection.

• Implement the Business Behavior.

• Perform a scenario test.

Further Reading:
Link: Developing New Managed Transactional Apps
Link: Data Modeling and Behavior

Thanks for attending today's Build a Transactional SAP Fiori App with the ABAP
RESTful Programming Model session!
You are now able to build a transactional app using the managed scenario on the SAP Cloud
Platform ABAP Environment.

79
CAA361

80
CAA361

COPYRIGHT
© 2019 SAP SE 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 SE or an SAP affiliate company.

The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other
software vendors. National product specifications may vary.

These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies
shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company 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.

In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any
functionality mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or
platforms, directions, and functionality are all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in
this document is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties
that could cause actual results to differ materially from expectations. Readers are cautioned not to place undue reliance on these forward-looking statements, and they should not be
relied upon in making purchasing decisions.

SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in
Germany and other countries. All other product and service names mentioned are the trademarks of their respective companies.
See https://www.sap.com/copyright for additional trademark information and notices.

81

You might also like