Welcome to the RAP Tutorial for Beginners! In this first part, you’ll build a complete SAP Fiori App in 30 minutes - from database table to UI. No prior knowledge required!
What You Will Build
A Book Management App with:
- List of all books
- Create new books
- Edit/Delete books
- Search and filter functionality
- Automatically generated Fiori Elements UI
Result: Fully functional Fiori App without writing a single line of UI code!
Prerequisites
System
- SAP BTP ABAP Environment Trial (free, 365 days)
- Guide: Create SAP BTP Trial
- Guide: Activate ABAP Trial
Or:
- SAP S/4HANA 2022 or higher (On-Premise/Cloud)
Tools
- ABAP Development Tools (ADT) for Eclipse
- Download: tools.hana.ondemand.com
- Version: Latest (2024 or higher)
Knowledge
- Basic ABAP knowledge helpful, but not required
- No RAP, CDS, or Fiori knowledge needed
Estimated time: 30-45 minutes
RAP Architecture Overview
Before we start, let’s briefly look at the structure:
+-------------------------------------+| Fiori Elements UI | <- Automatically generated!+-------------------------------------+| OData Service | <- Service Binding+-------------------------------------+| Service Definition | <- Which entities to expose?+-------------------------------------+| Projection Layer (C_*) | <- UI-specific view| + Behavior Definition |+-------------------------------------+| Business Object Layer (I_*) | <- Data model (CDS View)| + Behavior Definition (BDEF) | <- CRUD logic| + Behavior Implementation (BIL) |+-------------------------------------+| Database Table | <- Store data+-------------------------------------+Don’t worry! Sounds complex, but it’s not. We’ll go through it step by step.
Step 1: Create Package
We need a package for all objects.
In ADT:
- Right-click on
ZLOCAL(or your package) ->New->ABAP Package - Name:
ZBOOK_RAP_TUTORIAL - Description:
RAP Tutorial - Book Management - Package Type:
Development - Finish
Result: Package ZBOOK_RAP_TUTORIAL is created.
Step 2: Create Database Table
2.1 Create New Table
- Right-click on Package ->
New->Other ABAP Repository Object - Search:
Database Table - Name:
ZBOOK_TAB - Description:
Books Table - Next -> Finish
2.2 Define Table Structure
Replace the generated code with:
@EndUserText.label : 'Books Table'@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE@AbapCatalog.tableCategory : #TRANSPARENT@AbapCatalog.deliveryClass : #A@AbapCatalog.dataMaintenance : #RESTRICTEDdefine table zbook_tab { key client : abap.clnt not null; key book_id : abap.char(10) not null; title : abap.char(100); author : abap.char(50); publisher : abap.char(50); isbn : abap.char(13); @Semantics.amount.currencyCode : 'zbook_tab.currency_code' price : abap.curr(16,2); currency_code : abap.cuky; pages : abap.int4; publication_year: abap.numc(4); language : abap.char(2);
@Semantics.user.createdBy : true created_by : abap.char(12); @Semantics.systemDateTime.createdAt : true created_at : timestampl; @Semantics.user.lastChangedBy : true last_changed_by : abap.char(12); @Semantics.systemDateTime.lastChangedAt : true last_changed_at : timestampl;}2.3 Save & Activate
- Save:
Ctrl+S - Activate:
Ctrl+F3
Result: Table ZBOOK_TAB exists in the database.
Step 3: Create CDS Interface View (I_*)
The Interface View is the data model of our Business Object.
3.1 Create New CDS View
- Right-click on Package ->
New->Other ABAP Repository Object - Search:
Data Definition - Name:
ZI_BOOK - Description:
Book - Interface View - Referenced Object:
ZBOOK_TAB - Next -> Finish
3.2 Define CDS View
Replace the code with:
@AccessControl.authorizationCheck: #NOT_REQUIRED@EndUserText.label: 'Book - Interface View'
define root view entity ZI_BOOK as select from zbook_tab{ key book_id as BookId, title as Title, author as Author, publisher as Publisher, isbn as Isbn,
@Semantics.amount.currencyCode: 'CurrencyCode' price as Price,
@Semantics.currencyCode: true currency_code as CurrencyCode,
pages as Pages, publication_year as PublicationYear, language as Language,
@Semantics.user.createdBy: true created_by as CreatedBy,
@Semantics.systemDateTime.createdAt: true created_at as CreatedAt,
@Semantics.user.lastChangedBy: true last_changed_by as LastChangedBy,
@Semantics.systemDateTime.lastChangedAt: true last_changed_at as LastChangedAt}Important: define root view entity - “root” means this is the main Business Object.
3.3 Activate
Ctrl+F3
Result: CDS View ZI_BOOK is activated.
Step 4: Create Behavior Definition (BDEF)
The Behavior Definition defines what can be done with the Business Object (Create, Update, Delete, etc.).
4.1 Create BDEF
- Right-click on
ZI_BOOK->New Behavior Definition - Implementation Type:
Managed - Next -> Finish
4.2 Define BDEF
Replace the code with:
managed implementation in class zbp_i_book unique;strict ( 2 );
define behavior for ZI_BOOK alias Bookpersistent table zbook_tablock masterauthorization master ( instance )etag master LastChangedAt{ // Standard CRUD operations create; update; delete;
// Fields that are readonly field ( readonly ) BookId; field ( readonly ) CreatedBy, CreatedAt, LastChangedBy, LastChangedAt;
// Automatic number assignment for BookId field ( numbering : managed ) BookId;
// Mapping: CDS field -> Table field mapping for zbook_tab { BookId = book_id; Title = title; Author = author; Publisher = publisher; Isbn = isbn; Price = price; CurrencyCode = currency_code; Pages = pages; PublicationYear = publication_year; Language = language; CreatedBy = created_by; CreatedAt = created_at; LastChangedBy = last_changed_by; LastChangedAt = last_changed_at; }}Explanation:
managed: Framework handles CRUD operations automaticallystrict ( 2 ): Best practice modecreate; update; delete;: These operations are allowedfield ( numbering : managed ): BookId is assigned automatically
4.3 Activate
Ctrl+F3
Result: Behavior Definition ZI_BOOK is activated. ADT automatically generates the Behavior Implementation Class ZBP_I_BOOK.
Step 5: Create CDS Projection View (C_*)
The Projection View is the UI-specific view of the Business Object.
5.1 Create Projection View
- Right-click on Package ->
New->Other ABAP Repository Object - Search:
Data Definition - Name:
ZC_BOOK - Description:
Book - Projection View - Next -> Finish
5.2 Define Projection View
@EndUserText.label: 'Book - Projection View'@AccessControl.authorizationCheck: #NOT_REQUIRED
@Metadata.allowExtensions: true@Search.searchable: true
define root view entity ZC_BOOK provider contract transactional_query as projection on ZI_BOOK{ key BookId,
@Search.defaultSearchElement: true @Search.fuzzinessThreshold: 0.8 Title,
@Search.defaultSearchElement: true Author,
Publisher, Isbn,
@Semantics.amount.currencyCode: 'CurrencyCode' Price,
@Semantics.currencyCode: true CurrencyCode,
Pages, PublicationYear, Language,
CreatedBy, CreatedAt, LastChangedBy, LastChangedAt}New:
@Search.searchable: true: Enables search@Search.defaultSearchElement: true: Title & Author are searchable
5.3 Activate
Ctrl+F3
Step 6: Projection Behavior Definition
6.1 Create BDEF for Projection
- Right-click on
ZC_BOOK->New Behavior Definition - Implementation Type:
Projection - Next -> Finish
6.2 Define Projection BDEF
projection;strict ( 2 );
define behavior for ZC_BOOK alias Book{ use create; use update; use delete;}Short and simple: We “use” the CRUD operations from the Interface Layer.
6.3 Activate
Ctrl+F3
Step 7: Metadata Extensions (UI Annotations)
Here we define how the UI should look.
7.1 Create Metadata Extension
- Right-click on
ZC_BOOK->New Metadata Extension - Name:
ZC_BOOK(same name as View) - Next -> Finish
7.2 Define UI Annotations
@Metadata.layer: #CORE
annotate view ZC_BOOK with{ // Header area of the Fiori App @UI.headerInfo: { typeName: 'Book', typeNamePlural: 'Books', title: { value: 'Title' }, description: { value: 'Author' } }
// Facets (sections in object detail) @UI.facet: [ { id: 'BookDetails', purpose: #STANDARD, type: #IDENTIFICATION_REFERENCE, label: 'Book Details', position: 10 } ]
// Fields in the list @UI: { lineItem: [{ position: 10, importance: #HIGH }], identification: [{ position: 10 }], selectionField: [{ position: 10 }] } BookId;
@UI: { lineItem: [{ position: 20, importance: #HIGH }], identification: [{ position: 20 }], selectionField: [{ position: 20 }] } Title;
@UI: { lineItem: [{ position: 30, importance: #HIGH }], identification: [{ position: 30 }], selectionField: [{ position: 30 }] } Author;
@UI: { lineItem: [{ position: 40 }], identification: [{ position: 40 }] } Publisher;
@UI: { identification: [{ position: 50 }] } Isbn;
@UI: { lineItem: [{ position: 50 }], identification: [{ position: 60 }] } Price;
@UI: { identification: [{ position: 70 }] } Pages;
@UI: { lineItem: [{ position: 60 }], identification: [{ position: 80 }] } PublicationYear;
@UI: { identification: [{ position: 90 }] } Language;}Explanation:
@UI.lineItem: Columns in the list@UI.identification: Fields in the detail screen@UI.selectionField: Filter fields at the topposition: Orderimportance: HIGH = always visible
7.3 Activate
Ctrl+F3
Step 8: Service Definition
8.1 Create Service Definition
- Right-click on Package ->
New->Other ABAP Repository Object - Search:
Service Definition - Name:
ZUI_BOOK_O4 - Description:
Book Service Definition - Next -> Finish
8.2 Define Service
@EndUserText.label: 'Book Service Definition'define service ZUI_BOOK_O4 { expose ZC_BOOK as Book;}Super simple: We only “expose” our Projection View.
8.3 Activate
Ctrl+F3
Step 9: Service Binding (OData Service)
Almost done! Now we turn the service into a real OData API.
9.1 Create Service Binding
- Right-click on Package ->
New->Other ABAP Repository Object - Search:
Service Binding - Name:
ZUI_BOOK_O4 - Description:
Book Service Binding - Binding Type:
OData V4 - UI - Service Definition:
ZUI_BOOK_O4 - Next -> Finish
9.2 Activate & Publish Service Binding
- Save:
Ctrl+S - Activate:
Ctrl+F3 - Click Publish (button in the upper right of the editor)
Result: OData Service is active!
Step 10: Open Fiori App
10.1 Start Preview
- In the Service Binding (still open):
- Select entity
Book - Click Preview (right side)
- Browser opens with your Fiori App!
10.2 Create Test Data
The list is still empty. Let’s create some books:
- Click Create
- Fill in fields:
- Title:
Harry Potter and the Philosopher's Stone - Author:
J.K. Rowling - Publisher:
Bloomsbury - Price:
20.00 - Currency:
EUR - Pages:
335 - Publication Year:
1998 - Language:
EN
- Title:
- Click Create
Congratulations! Your first book is created!
10.3 Test Features
- Search: Enter “Harry” in search field -> finds the book
- Filter: Click Filter -> Filter by Author
- Edit: Click on book -> Edit -> Change price -> Save
- Delete: Select book -> Delete
Everything works - without writing a single line of UI code!
What Have We Learned?
Objects Created:
- Database Table (
ZBOOK_TAB) - CDS Interface View (
ZI_BOOK) - Behavior Definition Interface (BDEF)
- CDS Projection View (
ZC_BOOK) - Behavior Definition Projection
- Metadata Extension (UI Annotations)
- Service Definition (
ZUI_BOOK_O4) - Service Binding (OData V4)
RAP Principles:
- Managed Scenario: Framework handles CRUD
- Interface vs. Projection: Separation of Business Logic / UI
- Behavior Definition: What can be done with data?
- Fiori Elements: UI is generated from annotations
Next Steps
In Part 2: Advanced Features you’ll learn:
- Add Actions (e.g., “Mark as read”)
- Validations (e.g., ISBN check)
- Determinations (set automatic values)
- Value Helps (dropdown lists)
In Part 3: Best Practices:
- Performance optimization
- Error handling
- Testing
- Avoiding common mistakes
Additional Resources
On abapcloud.com:
- RAP Basics
- CDS Views
- ABAP Cloud Cheat Sheet
SAP Tutorials:
Questions?
- Did everything work?
- Where did you get stuck?
- What should be covered in depth in Part 2?
Let us know in the comments!
Continue with Part 2: Advanced Features ->