SAP S4HANA Build A Draft Enabled Business Object For Custom Functionality
SAP S4HANA Build A Draft Enabled Business Object For Custom Functionality
Session ID 41927
Welcome!
Welcome to the exercises of the SAP d-kom 2017 Session 41927 at Bangalore. In this
document you will create a transactional application, based on the new ABAP programming
model for SAP S/4HANA applications, making use of some of the latest and greatest
technologies available in the ABAP platform.
Business Scenario
The Fiori app you are going to implement will be for a custom development scenario.
The example is based on the SFLIGHT data model and considers the following
business case.
Users should be able to create soft bookings which will not create real blocking tickets but will
allow users to create travel plans. The business requirement is to build a new object called
“Soft Booking”. It will be similar to booking except that it will reside in a new Z table instead of
the standard SBOOK table. Conversion of a soft booking into a real booking is not in scope.
Requirements
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
1. You have to create a UI, OData services, and database artifacts to enable the creation
of soft bookings.
2. Also the soft booking creation should be draft-enabled – which means every action of
the user on the UI should update a draft version in the DB and only on pressing save
on UI it should become a soft booking.
Architecture Overview
The figure below illustrates the architecture components in our scenarios. It shows the main
technologies needed in order to build a Fiori Elements app based on the new ABAP
application programming for SAP S/4HANA.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
The figure below shows gives an overview of the main development objects and technologies
involved when creating a transactional, draft-enabled Fiori app based on the new ABAP
programming model for S/4HANA.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
ABAP CDS provides a data modeling infrastructure for defining and consuming semantically
rich data models in the ABAP platform starting with SAP NetWeaver AS for ABAP 7.4 SP05..
CDS advanced data modeling capability like field computation using a rich set of functions, build
views on views, associations and table functions. CDS data models can be enhanced at data
model using CDS view extensions, but also at metadata level using CDS metadata extensions.
ABAP CDS is a core technology within SAP S/4HANA, and the ABAP development for SAP
HANA in general. [More…]
MDEs are used to define CDS annotations for a CDS view outside of the corresponding data
definition. A CDS metadata extension is always assigned to a layer such as core, industry,
partner or customer. MDEs allow a separation of concerns by separating the data model from
domain-specific semantics – e.g. UI-related information for Fiori Elements. [More…]
BOPF is a framework that provides a set of generic services and functionalities to speed up,
standardize, and modularize your development. BOPF manages the entire life cycle of your
business objects and covers all aspects of your business application development. Instead of
expending effort for developing an application infrastructure, the developer can focus on the
individual business logic. Using BOPF, you get the whole application infrastructure and
integration of various components for free. This allows you to rapidly build applications on a
stable and customer-proved infrastructure. [More…]
Following options are offered in order to add application-specific business logic:
BOPF determinations which are used to calculate side-effects (automatically triggered by
changes)
BOPF validations which are consistency checks raising messages (automatically triggered
by changes)
BOPF actions which are named operations that can be called (usually by a button on the UI)
SAP Fiori Elements (formerly known as Smart Templates) allows the automatic generation of
SAP Fiori apps based on UI-specific annotations which can for example be specified in a CDS
view or in locale annotations within the SAP Web IDE. The set of predefined domain-specific
CDS annotations has been enhanced with such UI annotations with ABAP 7.5x. The
development of Fiori Elements apps take place in the SAP Web IDE. [More…]
A. SETUP INSTRUCTIONS
NOTE: RSA SecureID is needed for this session as the systems are in SAP Network.
Before you start, here is some technical information on the system, usernames, passwords,
etc. that you will need during the exercise:
Leave settings as
default and click on
next
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
B. EXERCISE SOLUTION
B1. Create base table for soft bookings
Right click on
Dictionary and
choose New
Database table
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
No transport
required for local
objects. Note:
Throughout this
workshop, you
will not require a
transport.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
Update technical
settings. Select
the table in the
project hierarchy
and open in SAP
GUI.
Click Technical
settings. Update
the data class to
APPL1 and size
category to 4.
Then save the
settings.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
sd
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
Provide a
meaningful
description for
your view.
After change:
Activate the view You have successfully created the interface view for the table.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
Provide a meaningful
description for your
view.
ZI_DKOM_SFBK_XX
After change:
Now we update the Paste these annotations before the define view statement:
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
annotations to
enable transactional @VDM.viewType: #TRANSACTIONAL
@ObjectModel.transactionalProcessingEnabled: true
processing and @ObjectModel.compositionRoot: true
automatically create @ObjectModel.writeDraftPersistence: 'ZDKOM_SFBK_XX_D'
a BOPF object. @ObjectModel.draftEnabled:true
@ObjectModel.createEnabled: true
Replace the XX with
@ObjectModel.deleteEnabled: true
your group number. @ObjectModel.updateEnabled: true
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.dataClass: #TRANSACTIONAL
@ObjectModel.modelCategory: #BUSINESS_OBJECT
@ObjectModel.semanticKey: [ 'ActiveKey' ]
After paste:
Activate the view You have successfully created the transactional view for the table.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
Code:
DATA:
lt_bo_sbook TYPE ztidkom_sfbk_xx_tp,
ls_bo_sbook TYPE zsidkom_sfbk_xx_tp,
ls_sbook TYPE zdkom_softbk_xx,
lt_sbook TYPE TABLE OF zdkom_softbk_xx,
lv_number TYPE char8,
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
CLEAR: ls_sbook.
ls_sbook-carrid = ls_bo_sbook-carrierid.
ls_sbook-connid = ls_bo_sbook-connectionid.
ls_sbook-customid = ls_bo_sbook-customerid.
ls_sbook-fldate = ls_bo_sbook-flightdate.
* CLEAR: ls_key_link.
READ TABLE it_draft_key INTO ls_draftkey INDEX 1.
IF sy-subrc = 0.
IF ls_bo_sbook-activeuuid IS NOT INITIAL.
ls_sbook-db_key = ls_bo_sbook-activeuuid.
ls_key_link-draft = ls_draftkey-key.
ls_key_link-active = ls_bo_sbook-activeuuid.
ELSE.
ls_sbook-db_key = ls_bo_sbook-key.
ls_key_link-active = ls_key_link-draft =
ls_draftkey-key.
ENDIF.
APPEND ls_sbook TO lt_sbook.
APPEND ls_key_link TO et_key_link.
ENDIF.
ENDLOOP.
Provide a meaningful
description for your
view.
After change:
Code:
@UI.hidden: true
key ActiveKey,
@UI.identification.position: 1
@UI.identification.label: 'CarrierID'
@UI.lineItem.position: 1
@UI.lineItem.label: 'CarrierID'
CarrierId,
@UI.identification.position: 2
@UI.identification.label: 'ConnectionID'
@UI.lineItem.position: 2
@UI.lineItem.label: 'ConnectionID'
ConnectionId,
@UI.identification.position: 3
@UI.identification.label: 'FlightDate'
@UI.lineItem.position: 3
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
@UI.lineItem.label: 'FlightDate'
FlightDate,
@UI.identification.position: 4
@UI.lineItem.position: 4
@UI.lineItem.label: 'CustomerID'
CustomerId,
CustomerType,
Vegetarian,
Cancelled
Activate the view You have successfully created the consumption view and generated
Odata services for the same. The UI annotations mentioned before
each field, will help Fiori Elements to generate the UI.
Note that there is a
warning saying the
OData service is not
activated.
Go to the transaction
/
IWFND/MAINT_SERVI
CE
Add a service:
OData services are Now we shall create the Fiori Elements based UI to consume this service.
generated
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
Press Finish
Start your
application after
running it as
described in Step
B5.
As soon as you
enter any
information like
Carrier, notice the
Draft Saved
message
Check again in
SE16N to see the
new record.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality
Continue filling
values and see the
DB getting refreshed
after every change
in the UI. This is the
draft enablement
concept.
Object is saved