0% found this document useful (0 votes)
266 views17 pages

Employee Management With SAP RAP

The document provides steps to create an employee management application using SAP RAP including creating tables, inserting records, developing Core Data Services and Projection views, adding Metadata Extensions and UI annotations, and defining business object behavior.

Uploaded by

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

Employee Management With SAP RAP

The document provides steps to create an employee management application using SAP RAP including creating tables, inserting records, developing Core Data Services and Projection views, adding Metadata Extensions and UI annotations, and defining business object behavior.

Uploaded by

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

Developing an Employee Management App with SAP RAP: A Step-by-Step Guide

In a rapidly evolving business landscape, the creation of an effective employee management system
using ABAP on Cloud is vital. This approach involves building a streamlined application centered
around an employee table. Key steps include establishing both Employee and Draft tables, inserting
records efficiently, and developing Core Data Services and Projection views. The process is further
enhanced by incorporating Metadata Extensions with UI annotations and defining the behavior of
Business Objects.

Employee Management Transactional App

Creating a complete transactional application with CRUD operations in ABAP on Cloud for a simple
Employee table involves several key components:
1) Create Employee Table
2) Create Draft Table
3) Insert the records into Employee Table
4) Create Employee CDS (Core Data Services) View
5) Create Employee Projection view
6) Create Metadata Extension with UI annotation.
7) Define Behavior of Business Object
8) Create Behavior Projection for Business Object
9) Service Definitions and Bindings

Create Employee Table


Locate Dictionary and right-click on “New Database Table” to create a new table.

Prepared by [email protected]
@EndUserText.label : 'Employee Table'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zemployee_01 {

key client : abap.clnt not null;


key employee_number : abap.char(8) not null;
last_name : abap.char(40);
first_name : abap.char(40);
department : abap.int1;
created_by : syuname;
created_at : timestampl;
last_changed_by : syuname;
local_last_changed_by : abp_locinst_lastchange_user;
local_last_changed_at : abp_locinst_lastchange_tstmpl;
last_changed_at : abp_lastchange_tstmpl;

Activate the employee table.

Create Draft table for Employee


In accordance with proceding steps,create a suppliemental table for employees that will serve as draft
table.

@EndUserText.label : 'Employee Draft Table'


@AbapCatalog.enhancement.category : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A

Prepared by [email protected]
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zemployee_01_d {

key client : abap.clnt not null;


key employee_number : abap.char(8) not null;
last_name : abap.char(40);
first_name : abap.char(40);
department : abap.int1;
created_by : syuname;
created_at : timestampl;
last_changed_by : syuname;
local_last_changed_by : abp_locinst_lastchange_user;
local_last_changed_at : abp_locinst_lastchange_tstmpl;
last_changed_at : abp_lastchange_tstmpl;
"%admin" : include sych_bdl_draft_admin_inc;

Activate the employee draft table.


Insert the records into Employee table

To effectively insert records into the employee table,consider creating dedicated class for this purpose.

Prepared by [email protected]
Please copy the below code and activate it
CLASS zcl_populate_employee DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
INTERFACES:if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS:load_employee_records RETURNING VALUE(rv_run_status) TYPE char1.
ENDCLASS.

CLASS zcl_populate_employee IMPLEMENTATION.


METHOD if_oo_adt_classrun~main.
DATA(lv_run_status) = load_employee_records( ).
IF lv_run_status = 'X'.
out->write( |Records are inserted successfully| ).
ENDIF.
ENDMETHOD.

METHOD load_employee_records.
TYPES:tt_employee TYPE STANDARD TABLE OF zemployee_01 WITH EMPTY KEY.
DATA(lt_employee) = VALUE tt_employee(
( employee_number = '0001'
first_name = 'FirstName1'
last_name = 'LastName1'
department = '001')
( employee_number = '0002'

Prepared by [email protected]
first_name = 'FirstName2'
last_name = 'LastName2'
department = '002')
( employee_number = '0003'
first_name = 'FirstName3'
last_name = 'LastName3'
department = '001')
( employee_number = '0004'
first_name = 'FirstName4'
last_name = 'LastName4'
department = '002') ).

DELETE FROM zemployee_01.


INSERT zemployee_01 FROM TABLE @lt_employee.
rv_run_status = COND #( WHEN sy-subrc EQ 0 THEN 'X' ELSE '' ).
ENDMETHOD.

ENDCLASS.

Run the console Application.

Now preview the data records

Prepared by [email protected]
Please find the below 4 records are added successfully into table.

Now Let’s create CDS View


Create Employee CDS view
To access the Data Definition window for the Core Data Service ,right-click on the “New” and select
“Data Definition” from context menu.

Prepared by [email protected]
Please copy the below code to create Employee TransApp CDS
[email protected]: #CHECK
@EndUserText.label: 'Employee Transactional App'
define root view entity ZI_Employee_TransApp
as select from zemployee_01 as emptrans
{
key employee_number,
last_name,
first_name,
department,
@Semantics.user.createdBy: true
created_by,
@Semantics.systemDateTime.createdAt: true
created_at,
@Semantics.user.localInstanceLastChangedBy: true
local_last_changed_by,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
local_last_changed_at,
@Semantics.systemDateTime.lastChangedAt: true
last_changed_at
}

Activate the CDS view and Preview the employee records

Prepared by [email protected]
Create Employee Projection view
Please replicate the following code to establish an additional CDS Projection view .

@AccessControl.authorizationCheck: #CHECK
@Metadata.allowExtensions: true
@EndUserText.label: 'Projection View for ZI_Employee_TransApp'
@ObjectModel.semanticKey: [ 'employee_number' ]
Prepared by [email protected]
define root view entity ZC_Employee_TransApp
provider contract transactional_query
as projection on ZI_Employee_TransApp
{
key employee_number,
last_name,
first_name,
department,
created_by,
created_at,
local_last_changed_by,
local_last_changed_at,
last_changed_at
}
Create Metadata Extension with UI annotation
Select Metadata Extension and Choose ‘New Metadata Extension’ and copy the given code

@Metadata.layer: #CORE
@UI: {
headerInfo: {
typeName: 'Employee',
typeNamePlural: 'Employees'
Prepared by [email protected]
}
}

annotate view ZC_Employee_TransApp


with
{
@UI.facet: [ {
id: 'idIdentification',
type: #IDENTIFICATION_REFERENCE,
label: 'Travel',
position: 10
}]
@UI.lineItem: [ {
position: 10 ,
importance: #MEDIUM
}]
@UI.identification: [ {
position: 10 ,
label: 'Employee Number'
}]
employee_number;
@UI.lineItem: [ {
position: 20 ,
importance: #MEDIUM,
label: 'Last Name'

}]
@UI.identification: [ {
position: 20,
label: 'Last Name'
}]
last_name;
@UI.lineItem: [ {
position: 30 ,
importance: #MEDIUM,
label: 'First Name'
}]
@UI.identification: [ {
position: 30 ,
label: 'First Name'
}]
first_name;
@UI.lineItem: [ {
position: 40 ,
importance: #MEDIUM,
label: 'Department'
}]
@UI.identification: [ {
position: 40 ,
label: 'Department'
}]
department;
@UI.hidden: true
Prepared by [email protected]
locallastchangedat;

Create Managed implementation on CUD(Create,Update,Delete) operations

 This behavior definition is crucial for the functioning of the SAP Fiori application as it dictates
how the application behaves in response to user actions and data changes.
 It encapsulates business logic, validation, and authorization checks, making sure that the
application adheres to business rules and data integrity.

Create the behavior definition by selecting below options and copy the given code. Activate the
code.

click ‘Finish’.

Prepared by [email protected]
managed implementation in class zbp_i_employee_transapp unique;
strict ( 2 );
with draft;
define behavior for ZI_Employee_TransApp alias emptrans
persistent table zemployee_01
draft table zemployee_01_d
etag master local_last_changed_at
lock master total etag last_changed_at
authorization master ( instance )

{
field ( mandatory : create )
employee_number;

field ( readonly )
Created_At,
Created_By,
Last_Changed_At,
Local_Last_Changed_At,
Local_Last_Changed_By;

field ( readonly : update )


employee_number;

create;
update;
delete;
draft action Edit;
draft action Activate optimized;
draft action Discard;
draft action Resume;
draft determine action Prepare;

mapping for zemployee_01


{
employee_number = employee_number;
last_name = last_name;
first_name = first_name;
department = department;
Created_By = created_by;
Created_At = created_at;
Local_Last_Changed_By = local_last_changed_by;
Local_Last_Changed_At = local_last_changed_at;
Last_Changed_At = last_changed_at;
}
}
And implement the class “zbp_i_employee_transapp”.

You can find below auto generated the code and please refrain from making any modification to the
code for this scenario.

Prepared by [email protected]
Local Types:

Important keywords:

 Managed means that some standard behaviors like create, update, and delete are
automatically handled by the SAP framework,.
 With Draft: This enables draft handling for the business object, which allows users to save
their work as a draft before it is officially committed to the database.
 Persistent Table and Draft Table: These specify the names of the database tables that store
the business object data (zemployee_01) and its draft data (zemployee_01_d).
 ETag Master: ETags (Entity Tags) are used for concurrency control. The
local_last_changed_at field is used to determine if the data has been modified since it was last
read, which helps in managing simultaneous access to data entries.
 Lock Master: This indicates the locking strategy used when multiple users attempt to access
the data. It uses total etag last_changed_at to manage these locks.
 Authorization Master: Specifies that authorization checks are instance-specific, meaning that
permissions can be different for each instance of the business object.

Prepared by [email protected]
 Mapping: Defines how the fields in the persistent and draft tables map to each other.

Create Behavior Projection for Business Object

Create behavior projection akin to the previous step.

 ZC_Employee_TransApp. A behavior projection is a way to expose a subset of behaviors from


a business object's implementation to its service consumption layer, typically for an OData
service in SAP Fiori apps.

Click ‘Finish’ button. Copy the below code and activate it.

projection;
strict ( 2 );
use draft;

define behavior for ZC_Employee_TransApp alias emptrans


use etag
{
use create;
use update;
use delete;

use action Edit;


use action Activate;
use action Discard;
use action Resume;
use action Prepare;
}

Prepared by [email protected]
Provide a service definition name and description. Once you have done this, click the "Finish" button.

You will find the below code and please activate the service definition.

Now create the service Bindings. Provide the Service Binding Name.

Prepared by [email protected]
Publish the service binding, activate the preview, and observe the activation of the Create, Delete, and
Edit buttons within the generated output.

Now the "Create" button is active in the output. Click this button to create new entries, save entries,
and delete unwanted entries.

Prepared by [email protected]
Prepared by [email protected]

You might also like