In this exercise, you will create a transactional UI service along with the underlying RAP business object.
First you will create an ABAP package, a database table, and an ABAP class to fill the database table with demo data. Then you will use an ADT wizard to generate all the needed development RAP artefacts of your UI service on top of the database table. This includes the CDS data model, behavior definition, service definition, and service binding. Afterwards you will publish and check your Travel application with the SAP Fiori elements preview.
- 1.1 - Create Package
- 1.2 - Create database table
- 1.3 - Create data generator class
- 1.4 - Generate the transactional UI services
- 1.5 - Publish and Preview the Travel App
- Summary
Reminder:
Don't forget to replace all occurences of the placeholder###
with your group ID in the exercise steps below.
You can use the ADT function Replace All (Ctrl+F) for the purpose.
If you don't have a group ID yet, then check the section Getting Started - Group ID.
Create your exercise package.
This ABAP package will contain all the artefacts you will be creating in the different exercises of this hands-on session.
Click to expand!
-
In ADT, go to the Project Explorer, right-click on the package
ZLOCAL
, and select New > ABAP Package from the context menu. -
Maintain the required information (
###
is your group ID, please choose a suitable combination of numbers and characters, e.g.088
orZT1
):- Name:
ZRAP100_###
- Description:
RAP100 Package ###
- Select the box Add to favorites package
- Superpackage:
ZLOCAL
Click Next >.
- Name:
-
Select a transport request, maintain a description (e.g. RAP100 Package ###), and click Finish.
Create a database table to store the Travel data.
A Travel entity defines general travel data, such as the agency ID or customer ID, overall status of the travel booking, and the price of travel.
Click to expand!
-
Right-click on your ABAP package
ZRAP100_###
and select New > Other ABAP Repository Object from the context menu. -
Search for database table, select it, and click Next >.
-
Maintain the required information (
###
is your group ID) and click Next >.- Name:
ZRAP100_ATRAV###
- Description:
Travel data
- Name:
-
Select a transport request, and click Finish to create the database table.
-
Replace the default code with the code snippet provided below and replace all occurences of the placeholder
###
with your group ID using the Replace All function (Ctrl+F).Hint: Hover the code snippet and choose the Copy raw contents icon appearing in the upper-right corner to copy it.
@EndUserText.label : 'Travel data' @AbapCatalog.enhancement.category : #NOT_EXTENSIBLE @AbapCatalog.tableCategory : #TRANSPARENT @AbapCatalog.deliveryClass : #A @AbapCatalog.dataMaintenance : #RESTRICTED define table zrap100_atrav### { key client : abap.clnt not null; key travel_id : /dmo/travel_id not null; agency_id : /dmo/agency_id; customer_id : /dmo/customer_id; begin_date : /dmo/begin_date; end_date : /dmo/end_date; @Semantics.amount.currencyCode : 'zrap100_atrav###.currency_code' booking_fee : /dmo/booking_fee; @Semantics.amount.currencyCode : 'zrap100_atrav###.currency_code' total_price : /dmo/total_price; currency_code : /dmo/currency_code; description : /dmo/description; overall_status : /dmo/overall_status; attachment : /dmo/attachment; mime_type : /dmo/mime_type; file_name : /dmo/filename; created_by : abp_creation_user; created_at : abp_creation_tstmpl; local_last_changed_by : abp_locinst_lastchange_user; local_last_changed_at : abp_locinst_lastchange_tstmpl; last_changed_at : abp_lastchange_tstmpl; }
Click to expand!
-
Right-click your ABAP package
ZRAP100_###
and select New > ABAP Class from the context menu. -
Maintain the required information (
###
is your group ID) and click Next >.- Name:
ZCL_RAP100_GEN_DATA_###
- Description:
Generate demo data
- Name:
-
Select a transport request and click Finish to create the class.
-
Replace the default source code with the code snippet provided in the source code document
ZRAP100_GEN_DATA_###
linked below and replace all occurences of the placeholder###
with your group ID using the Replace All function (Ctrl+F).You can use the ABAP Pretty Printer (ABAP Formatter) function using by pressing Shift+F1 to format the source code. You will be requested to configure it, if this is the first time you use it on the system.
Hint: Open the document in a new tab. In the document editor, use the Copy raw contents icon in the toolbar to copy the full source code.
Source code document: Class ZRAP100_GEN_DATA_###
-
Run your console application.
For that, select your ABAP class
ZCL_RAP100_GEN_DATA_###
, select the run button > Run As > ABAP Application (Console) F9 or press F9.A message will be displayed ABAP Console.
-
Open your database table
ZRAP100_ATRAV###
and press F8 to start the data preview and display the filled database entries, i.e. travel data.
Create your OData v4 based UI services and the RAP business object (BO) with all the needed ABAP artefacts - e.g. CDS view entities, behavior definition and implementation - using the built-in ADT generator.
The generated business service will be transactional, draft-enabled, and enriched with UI semantics for the generation of the Fiori elements app.
Click to expand!
-
Right-click your database table
___________________________________________________________________________________________________________________________________________________ZRAP100_ATRAV###
and select Generate ABAP Repository Objects from the context menu. -
Maintain the required information on the Configure Generator dialog to provide the name of your data model and generate them.
For that, navigate through the wizard tree (Business Objects, Data Model, etc...), maintain the artefact names provided in the table below, and press Next >.
Verify the maintained entries and press Next > to confirm. The needed artefacts will be generated.
ℹ Info about Naming Conventions
The main aspects of the naming conventions of SAP S/4HANA's Virtual Data Model (VDM) are used in this exercise.
More information on VDM can be found on the SAP Help portal: Here.⚠ Attention ⚠
Please make sure to replace all the name proposals in the wizard with the names provided below.
Doing this is important to ensure the correctness of the code snippets provided in the following exercises.RAP Layer Artefacts Artefact Names Business Object Data Model Data Definition Name: ZRAP100_R_TravelTP_###
Alias Name: Travel
Behavior Implementation Class: ZRAP100_BP_TravelTP_###
Draft Table Name: ZRAP100_DTRAV###
Service Projection (BO Projection) Name: ZRAP100_C_TravelTP_###
Business Services Service Definition Name: ZRAP100_UI_Travel_###
Service Binding Name: ZRAP100_UI_Travel_O4_###
Binding Type: OData V4 - UI
-
Go to the Project Explorer, select your package
ZRAP100_###
, refresh it by pressing F5, and check all generated ABAP repository objects
Below is a brief explanation of the generated artefacts for the different RAP layers: Base BO, BO Projection, and Business Service.
Base Business Object (BO) ZRAP100_R_TRAVEL_###
BO Projection ZRAP100_C_TRAVEL_###
The BO projection represents the consumption specific view on the BO data model and behavior.
Business Service
Publish the local service endpoint of your service binding and start the Fiori elements App Preview.
Exercise 1.5.1: Publish and Preview the Travel App on SAP BTP, ABAP environment or SAP S/4HANA, Public Cloud Edition
Publish the local service endpoint of your service binding in the Service Binding editor and start the Fiori elements App Preview.
Click to expand!
Now that you've...
- created an ABAP package,
- created a database table and fill it with demo data,
- created a transactional UI service,
- published a local service point, and started the Fiori elements App Preview in ADT,
you can continue with the next exercise - Exercise 2: Enhance the BO Data Model and Enable OData Streams.