Employee Management With SAP RAP
Employee Management With SAP RAP
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.
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
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 {
Prepared by [email protected]
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zemployee_01_d {
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.
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') ).
ENDCLASS.
Prepared by [email protected]
Please find the below 4 records are added successfully into table.
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
}
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]
}
}
}]
@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;
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;
create;
update;
delete;
draft action Edit;
draft action Activate optimized;
draft action Discard;
draft action Resume;
draft determine action Prepare;
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.
Click ‘Finish’ button. Copy the below code and activate it.
projection;
strict ( 2 );
use draft;
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]