Skip to main content
SAP BTP

Restful ABAP Programming Model for Fiori (RAP)

Keerthana Subramani Keerthana Subramani, Senior Back End Developer 7 min read

In this blog, we are going to see a transactional FIORI application, which is built using the RAP-managed framework. Many steps are involved in making this application. To begin with, I will show the final output, and then we can understand which kind of application we will develop.

This sample Fiori application is built on the cloud project.

In Image 1, we are going to see the highlighted parts. For example, how to attach a value help for the selection field, how to place an input field, how to make an input field mandatory, how to create a custom button (show/hide scenario based on some conditions), how to make an input field to have range data (e.g., date), how to make a dropdown in an input field, how to show the total count of the data in the line item heading, how to attach an icon in the line item.

Fiori list report for travels with filter fields, Create and Delete buttons and icon column highlighted

Image 2: List Object Page – How to display the list object page as navigation for header data as well as item data and the association

Fiori object page for travel Vacation for Salvador with header, tabs and Edit and Delete buttons highlighted

Image 2.1 Bookings tab that is related to image 2.

Bookings tab of the travel object page with airline logo, booking and flight columns highlighted

For this FIORI application, we need to create a package. Then we go on to make the following;

  1. Data elements, Domains.
  2. Database Tables.
  3. CDS views (Basic view, composite view, consumption view).
  4. Metadata Extensions.
  5. Behavior definitions.
  6. Behavior Implementation (class).
  7. Service Definition.
  8. Service Binding.

Creating a Package:

Open Eclipse / SAP HANA studio and open the cloud project. Right-click the cloud project, and there will be an option to create an ABAP package. We can make our package over there.

ZBLOG_KEEKEE is the package.

Eclipse package ZBLOG_KEEKEE with superpackage and ZLOCAL software component highlighted

After creating the package, we will make the root view entity.

CDS code for root view entity YCDS_TRAVEL_7B with associations, composition and field list

In this root view, we have used

One db table: zfe_atrav_001001–>, will give our FIORI application’s demo data.

If we create our db table, we need to insert data for that table using class as it is a cloud-based application. So, I have used the existing table itself.

ABAP table definition zfe_atrav_001001 with travel fields and currency annotations

Data element YCURRTEXT_D_7B in Eclipse with type TEXT40 and currency text field labels

1 standard view entity: /DMO/I_agency –> for agency data

Three custom cds views:

  1. Ycds_overall_text_7b –> which is going to give the Overallstatus as text in the FIORI application,
  2. Ycds_image_store_7b –> which is going to give the logo for the FIORI application,
  3. Ycds_booking_7b –> booking data.

1) ycds_overall_text_7b —>

CDS code for view entities YCDS_Overall_text_7B and YCDS_Overall_stat_7B

Fiori list report with the Overall Status filter dropdown showing Accepted, Open and Rejected

We need to create both YCDS_Overall_stat_7B and YCDS_Overall_text_7B together and to activate both at the same time using this icon in the eclipse/ SAP HANA studio as it is dependent view entities.

Eclipse toolbar with the activate icon highlighted above a YCDS_TRAVEL_7B editor tab

2) YCDS_IMAGE_STORE_7B—>

CDS code for view entity YCDS_IMAGE_STORE_7B with an imageUrl annotation on pic_url

Fiori list with status logos in the ICON column, above the yimage_store_7b table definition

Fiori list with status logos in the ICON column, above the yimage_store_7b table definition

Data element YSTATUS_IMAGE_7B in Eclipse defined as CHAR length 1 with overall status labels

This table will be filled by the class ‘ycl_image_storing_data_7B’, which is pasted at the end.

3) YCDS_BOOKING_7B —>

CDS code for view entity YCDS_BOOKING_7B with parent and carrier associations

In the view entity ycds_booking_7b —> we have used

  1. Zfe_abook_001001 –>table which will have booking data (I have used the existing ones)

Table definition zfe_abook_001001 and CDS code for interface view zi_fe_carr_001001_7B

In the interface view zi_fe_carr_001001_7B, we have used zfe_acarr_001001–> existing table for airline data and I_Currency –> standard cds view for currency data.

Table definition zfe_acarr_001001 with carrier ID, name, logo URL and currency fields

After this activate both YCDS_BOOKING_7B and YCDS_TRAVEL_7B at the same time.

Now create a projection view for YCDS_TRAVEL_7B —> ycds_travel_projection_7b

Fiori list report with travel description and ID highlighted under a Search.searchable note

Fiori list report with the overall search field highlighted

define root view entity YCDS_TRAVEL_PROJECTION_7B
provider contract transactional_query
as projection on YCDS_TRAVEL_7B

CDS projection field list with text element, value help and search annotations

Fiori list row expanded to show dates, booking fee, total price and Accepted status

Value help for customer, if you click the customer input field, it will show the value help

Fiori Value Help for customer dialog with customer filter fields and results table

In the above projection view, ycds_travel_projection_7b —> create ycds_booking_projection_7b (can be activated at the same time)

CDS code for YCDS_BOOKING_PROJECTION_7B and value help view YCDS_CUSTOMER_VH_7B

/DMO/customer –> standard cds view for customer data

YCDS_OVERALL_TEXT_VH_7B –> value help for overall status

CDS code for value help view YCDS_OVERALL_TEXT_VH_7B and view YCDS_Overall_text_7B

In the above cds, we have used:

/dmo/oall_stat_t –> standard table with overall status with text and language

YCDS_Overall_stat_7B –> custom cds view

CDS code for view entity YCDS_Overall_stat_7B selecting from /dmo/oall_stat

In the cds YCDS_Overall_stat_7B we have used

/dmo/oall_stat –> standard table for status

YCDS_Overall_text_7B –> YCDS_Overall_stat_7B —> need to be activated at the same time.

After activating both the projection views:

YCDS_TRAVEL_PROJECTION_7B, YCDS_booking_PROJECTION_7B

We need to create metadata extensions for both the projection views:

Right click the ycds_travel_projection_7b –> create metadata extension :

Metadata extension for YCDS_TRAVEL_PROJECTION_7B with header info and UI facet annotations

Metadata extension field annotations for line items, selection fields and Calculate Total Price action

Metadata extension annotations for booking fee, total price and overall status fields

Metadata extension note explaining the headerInfo typeNamePlural annotation

Fiori list report with the App for Travels (4,187) heading and count highlighted

Header info title and description annotations next to the object page header they produce

Object page price and status header and General Information facet with their annotations

Object page General and Prices facets highlighted with their facet annotations

Object page Dates facet and Bookings tab with facet and field position annotations

Fiori list report with Travel ID selection field and Travel ID column highlighted

“for identification”

Object page Travel ID and Calculate Total Price button with their annotations

List report icon column and Starting Date range picker with their field annotations

Object page price and status header with dataPoint and lineItem annotations

Metadata extension for YCDS_BOOKING_PROJECTION_7B and the resulting Bookings table

Behavior definition for YCDS_TRAVEL_7B with draft, action, field and mapping statements

Behavior definition for YCDS_BOOKING_7B and start of draft table zfe_dtrav_00107b

Draft table definitions zfe_dtrav_00107b and zfe_dbook_00107b with the draft admin include

Before that we need to create a message class : ycl_msg_travel_7b –> to use in the beh impl class

Message class YCL_MSG_TRAVEL_7B in Eclipse with messages for invalid currency and total price

In the behavior definition :

managed implementation in class zcl_cds_travel2_7B unique;

–> place the cursor on the class name –> ctrl + 1 –> it will create the class –> behavior implementation

We are going to write our custom code in the behavior implementation class only.

CLASS zcl_cds_travel2_7b DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF ycds_travel_7b.
ENDCLASS.
CLASS zcl_cds_travel2_7b IMPLEMENTATION.
ENDCLASS.

While open the class, it will show the local class which is generated.

Generated behavior implementation class ZCL_CDS_TRAVEL2_7B open in the Eclipse editor

Handler class lhc_YCDS_TRAVEL method definitions and commented currency validation code

ABAP code with commented error message handling and the start of method GetCurrCode

ABAP code for GetCurrCode updates and get_instance_features enabling the action for Accepted

ABAP code for the TotalPrice action adding booking fee to total price and raising a message

Handler class lhc_YCDS_BOOKING and projection behavior definition for YCDS_TRAVEL_PROJECTION_7B

Projection behavior definitions and service definition YCDS_TRAVEL_SRV_7B exposing both projections

Generated behavior implementation class ZCL_CDS_TRAVEL2_7B open in the Eclipse editor

Select the highlighted service definition –> click –> publish

Service binding YCDS_TRAVEL_BIND_SRV_7B (OData V4 UI) with Preview button and travel entity highlighted

We can view the output as FIORI screen by selecting main entity projection and preview button

Output :

Fiori preview of the App for Travels list report in the browser with status logos

We can view the OData metadata, by using the service URL in the service binding.

Service binding YCDS_TRAVEL_BIND_SRV_7B with the Service URL highlighted

After clicking the service URL:

We can see the main entity and in case any activation error in the service binding, we can see that in the service URL.

Browser showing the OData V4 service document listing the travel and booking projections

https://6654aaf7-905f-48ea-b013-3811c03fcba8.abap-web.us10.hana.ondemand.com/sap/opu/odata4/sap/ycds_travel_bind_srv_7b/srvd/sap/ycds_travel_srv_7b/0001/$metadata –> we can see the full metadata on the page.

To insert data in the yimage_store_7b table and also the table for currency text ytext_curr_t_7b, we need to create a class –>

Table definition ytext_curr_t_7b for currency text and start of class ycl_image_storing_data_7B

ABAP class ycl_image_storing_data_7B main method filling currency text and status image values

pic_url = ‘https://raw.githubusercontent.com/SAP-samples/fiori-elements-opensap/main/week1/images/airlines/Green-Albatross-logo.png‘ )

( travel_status_id = ‘A’ travel_status_text = ‘Accepted’

pic_url = ‘https://raw.githubusercontent.com/SAP-samples/fiori-elements-opensap/main/week1/images/airlines/Fly-Africa-logo.png‘ )

( travel_status_id = ‘X’ travel_status_text = ‘Rejected’

pic_url = ‘https://raw.githubusercontent.com/SAP-samples/fiori-elements-opensap/main/week1/images/airlines/Green-Albatross-logo.png‘ )

)

ABAP code deleting and inserting records in yimage_store_7B and ytext_curr_t_7B

ABAP code reading ytext_curr_t_7B and writing a success message to the console

Once class is created, activate it and run as ABAP application(console), both the tables will be filled by the given values.

What are the annotations in the behavior definition works :

managed implementation in class zcl_cds_travel2_7B unique;
strict ( 2 ); //to check whether all syntax are up to date
with draft;
//strict ( 1 );
define behavior for YCDS_TRAVEL_7B
persistent table zfe_atrav_001001 //our base table
draft table zfe_dtrav_00107B //draft table which is going to save the changes while create or update any data // those changes will be updated to this draft table.

Object page in draft mode with editable fields, Draft updated status and Save and Discard Draft buttons

If we didn’t discard the draft, it will be stored in the draft table. We can use that if we need this.

Fiori list report with a travel record marked Draft

Behavior definition lines for lock, etag, read-only fields, TotalPrice action and create, update, delete

Fiori list report with Create and Delete buttons highlighted for a selected draft row

Object page for travel 2123 with Edit and Delete buttons highlighted

Commented behavior definition with draft actions, field mapping, validation and booking entity

Booking field mapping and Calculatebooking determination in the behavior definition

Handler class lhc_YCDS_TRAVEL method definitions with a comment on ValCurrencyCode

Commented-out ABAP code for validating the currency and raising an error message

ABAP GetCurrCode determination method with comments, updating the currency text

Eclipse data preview of YCDS_TRAVEL_PROJECTION_7B for travel 2123 with EUR currency text

Object page in draft with currency code EUR, then saved with currency code INR

After saving , ycds_travel_projection_7b will be saved currencytext as Indian currency.

Eclipse data preview of travel 2123 with currency INR and text Indian Currency

ABAP get_instance_features method enabling TotalPrice only for Accepted status

ABAP TotalPrice method updating the total price and appending an information message

Fiori list with Calculate Total Price enabled for a travel with Accepted status

For other overall status, that custom button will be disabled.

Fiori list with Calculate Total Price disabled for a travel with Open status

Calculation of total price in the popup message :

Fiori list filtered to Accepted with booking fee, total price and Calculate Total Price highlighted

Information popup reading Total Price 32.00 of Travel ID 00002123

ABAP handler class lhc_YCDS_BOOKING with the Calculatebooking determination method

Fiori list report with the Create button highlighted

After create –> press –> we can give the description and continue

Fiori Create dialog asking for a description, with Test data entered

You will be able to see this object page screen:

New travel Test data in draft with price, currency and a booking row, Create button highlighted

Saved Test data travel object page with USD currency and its Bookings tab

Output in the Projection view:

Eclipse data preview of the new travel record with USD currency text US Dollar

Some additions to the FIORI Object page:

To display Status as highlighted color in Object page:

Object page for Business Trip to USA with Open status highlighted and Calculate Total Price disabled

Add this in the metadata extension ycds_travel_meta_7b

Metadata extension header info and header facet annotations for YCDS_TRAVEL_PROJECTION_7B

Metadata extension facet annotations for General Information, General, Prices and Dates

Metadata extension annotations for the Bookings facet, TravelId and Calculate Total Price action

Metadata extension annotations for icon, agency, customer, date and booking fee fields

Metadata extension with criticality added to the StatusData dataPoint for OverallStatus

Refresh the service binding and see the FIORI output:

To display 2nd object page navigating from the bookings tab in the first object page:

Bookings tab for Business Trip to USA with the row navigation arrow highlighted

Booking object page for Business Trip to USA with connection, flight date and airline logo

Add some annotations in the metadata extensions (YCDS_BOOKING_META_7B)

Booking metadata extension with header info and facets added for the object page

Booking metadata extension facets and identification annotations added for the object page

Booking metadata extension annotations for connection ID, flight date and image URL

If you have an interest in viewing similar content, visit our blog, here.

View our LinkedIn, here.

Share