0% found this document useful (0 votes)
456 views38 pages

SAP S4HANA Build A Draft Enabled Business Object For Custom Functionality

This document provides instructions for creating a draft-enabled business object for custom functionality in SAP S/4HANA. It outlines creating a base table, interface view, and transactional processing view to support soft bookings that do not create real tickets but allow users to create travel plans. Requirements include creating a UI, OData services, and database artifacts for soft bookings, and making the creation draft-enabled by updating a draft version until the user saves.

Uploaded by

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

SAP S4HANA Build A Draft Enabled Business Object For Custom Functionality

This document provides instructions for creating a draft-enabled business object for custom functionality in SAP S/4HANA. It outlines creating a base table, interface view, and transactional processing view to support soft bookings that do not create real tickets but allow users to create travel plans. Requirements include creating a UI, OData services, and database artifacts for soft bookings, and making the creation draft-enabled by updating a draft version until the user saves.

Uploaded by

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

SAP S/4HANA: 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

Quick Introduction to the involved technologies:

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 Core Data Services (CDS)

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…]

Metadata Extension (MDE)

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…]

Business Object Processing Framework (BOPF)

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 (Smart Templates)


Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

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:

Session No. 41927


IDE Shortcut on Desktop to ABAP Development Tools
ABAP System QJ9/500
Username DKOM_WK-XX ( where XX is your group number)
Password Welcome123
Package $tmp
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

A.1 Setup IDE for development


Click on ….. in the
folder….
Open Project Explorer
view
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Right click and choose


New ABAP project

Choose the QJ9 system


from the pop-up

Leave settings as
default and click on
next
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Enter the client,


username and
password here.

Create all objects in


your local directory
($tmp)
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

Enter the table


name as
ZDKOM_SOFTBK_
XX and replace XX
with your group
no.

Leave the Project


and Package fields
as default.

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

The table creation


template is
shown. Delete the
default field
which is filled
automatically.

Paste the code in key mandt : mandt not null;


key db_key : raw16 not null;
the field list carrid : s_carr_id;
section and connid : s_conn_id;
change the fldate : s_date;
customid : s_customer;
enhancement
custtype : s_custtype;
category. vegetarian : s_smoker;
cancelled : s_cancel;
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

Save technical settings.

Switch back to the


code file for the
table and activate
the table.

sd
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

B2. Create the interface view for the base table


This interface view is intended to simply expose the required fields of the table and rename
them to make them semantically more meaningful.

Create a new data


definition file
(under Core Data
Services) as shown.

Enter the CDS view


name as
ZI_DKOM_SFBK_XX
and replace XX
with your group
number.

Provide a
meaningful
description for
your view.

Create the view by


pressing Finish.

Update the Before change:


sqlViewName to
ZI_DKOM_SB_XX
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

and change the


data source to
table
ZDKOM_SOFTBK_X
X

After change:

Update the field key db_key as ActiveKey,


carrid as CarrierId,
list with new Alias connid as ConnectionId,
names for fldate as FlightDate,
semantic meaning. customid as CustomerId,
custtype as CustomerType,
vegetarian as Vegetarian,
cancelled as Cancelled

Final code for the


view will look like
this.

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

B3. Create the Transactional Processing view

Create a new data


definition file (under
Core Data Services)
as shown.

Enter the CDS view


name as
ZI_DKOM_SFBK_XX_
TP and replace XX
with your group
number.

Provide a meaningful
description for your
view.

Create the view by


pressing Finish.

Update the Before change:


sqlViewName to
ZI_DKOM_SB_XX_TP
and change the data
source to the
interface view
created in Step B1 -
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

ZI_DKOM_SFBK_XX

After change:

Update the field list key ActiveKey,


CarrierId,
with same fields as ConnectionId,
Interface view. FlightDate,
CustomerId,
CustomerType,
Vegetarian,
Cancelled

View will look like this:

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

View the generated


Draft table and the
generated BOPF
object

View the BOPF


object
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

View the ROOT node


and see the Draft
handling class. Also
there are options to
create Actions,
Determinations and
Validations. Here we
can write business
logic.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Open the draft class


from the directory
tree and edit the
method
copy_draft_to_active
.

Paste the code into


the empty method.
Then replace XX with
your group number
in the code. Please
call the co-ordinator
if you face issues.
Activate the class.

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

ls_key_link TYPE /bobf/s_frw_key_link_act_draft,


ls_draftkey TYPE /bobf/s_frw_key.

" Only One Node in the Business Object. So Direct


Retreive possible.
io_read->retrieve(
EXPORTING
iv_node =
zif_i_dkom_sfbk_xx_tp_c=>sc_node-zi_dkom_sfbk_xx_tp
it_key = it_draft_key
iv_before_image = abap_false
iv_fill_data = abap_true
IMPORTING
et_data = lt_bo_sbook ).

LOOP AT lt_bo_sbook INTO ls_bo_sbook.

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.

MODIFY zdkom_softbk_xx FROM TABLE lt_sbook.


IF sy-subrc <> 0.
ENDIF.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

B4. Create the Consumption View for the User Interface

Create a new data


definition file (under
Core Data Services) as
shown.

Enter the CDS view


name as
ZC_DKOM_SFBK_XX
and replace XX with
your group number.

Provide a meaningful
description for your
view.

Create the view by


pressing Finish.

Update the Before change:


sqlViewName to
ZC_DKOM_SB_XX and
change the data
source to the
transactional view
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

created in Step B3-


ZI_DKOM_SFBK_XX_T
P

After change:

Update the following @Metadata.allowExtensions: true


@VDM.viewType: #CONSUMPTION
annotations. The @ObjectModel.createEnabled: true
transactional @ObjectModel.updateEnabled: true
processing is @ObjectModel.deleteEnabled: true
@ObjectModel.draftEnabled: true
delegated.
@ObjectModel.compositionRoot: true
@ObjectModel.transactionalProcessingDelegated: true
@ObjectModel.semanticKey: [ 'ActiveKey' ]

Update the field list


with UI annotations.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

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

Now we update the


annotations to
generate OData
services.

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.

Open SAP GUI in


Eclipse CTRL + 6
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Go to the transaction
/
IWFND/MAINT_SERVI
CE

Add a service:

Check the Co-


deployed checkbox
and search for your
service
ZC_DKOM_SFBK_XX_CD
S
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Select your service and


press Add Service.

Save the generated


objects in Local
directory and press
the tick mark

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

B5. Create the UI for soft booking


Please visit the link
https://code-
fiori.dispatcher.cert.hana.on
demand.com/
Create a new project from
template.

Select List Application


Report template and press
Next
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Fill the project name,


description, application
component and press Next

Select the system


QJ9CLNT500 from the
service catalog

If you get a popup- please


provide you login details
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Once connected, search for


your service
ZC_DKOM_SFBK_XX_CDS

Select the service and press


next

Wait until the two


annotations appear and
then Press Next
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Select your CDS view from


the drop down and press
next

Press Finish

Run your new app


Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Choose the Sandbox.html

C. TEST YOUR APPLICATION

Log into SAPGUI and


check your draft
table in SE16N
transaction. It will
be empty initially.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Start your
application after
running it as
described in Step
B5.

Click on the Create


button
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

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.

Close the browser


tab and reopen your
app. Press Go and
you will see your
draft to continue
editing.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Now press Save to


move it from Draft
to Active.
Session :41927 SAP S/4HANA: Build a Draft-Enabled Business Object for Custom Functionality

Object is saved

Now check your Please check in SE16N.


main table
ZDKOM_SOFTBK_
XX. It will have the
record and draft
table will be
empty.

You might also like