Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
2,617

Introduction:

In the world of SAP development, the RESTful Application Programming (RAP) model offers a modern and efficient approach for building scalable, data-driven applications. This blog explores the process of creating a deep entity within the RAP framework, specifically focusing on the structure of header and item tables and their associated projection views. We'll break down the core concepts of root and item entities, along with service and behavior definitions, to demonstrate how these components come together to manage employee data effectively.

Whether you're a seasoned SAP developer or just beginning to explore RAP, this guide will provide step-by-step instructions for creating and editing entries in the system, helping you streamline your development process. You'll also find helpful links to further resources and the author's professional profiles, enabling you to expand your knowledge and connect with the broader SAP community.

Solution Overview:
This blog outlines the creation of a deep entity using the RAP (RESTful Application Programming) model, detailing the structure of header and item tables, as well as their associated projection views. It includes definitions for root and item entities, service definitions, and behavior definitions for managing employee data. Additionally, it provides instructions for creating and editing entries in the system, with links to the author's professional profiles and resources.

HEADER TABLE:

@EndUserText.label : 'Employee table'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED

define table zemptable {

key client : abap.clnt not null;
key empid : zv_id not null;
firstname : abap.char(50);
lastname : abap.char(50);
dateofbirth : abap.dats;
gender : zgendar;
department : abap.char(30);
@Semantics.amount.currencyCode : 'zemptable.currency'
salary : abap.curr(13,2);
currency : abap.cuky;
email : abap.char(100);
phone_number : abap.char(20);

}

 

ITEM TABLE:

@EndUserText.label : 'emp item table'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED

define table zemp_itemtable {

key client : abap.clnt not null;
@AbapCatalog.foreignKey.screenCheck : false
key emp_id : zv_id not null
with foreign key [1..1] zemptable
where empid = zemp_itemtable.emp_id;

key item_id : abap.int8 not null;
item_type : abap.char(30);
item_desc : abap.char(100);
assign_date : abap.dats;
return_date : abap.dats;
status : abap.char(10);
remarks : abap.char(255);
created_by : abap.char(12);
created_on : abap.dats;
changed_by : abap.char(12);
changed_on : abap.dats;

}

 

ROOT ENTITY:

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label : 'Root entity for header'
@Metadata.ignorePropagatedAnnotations: true

define root view entity ZRS_EMP_HDR as select from zemptable
composition [0..*] of Zcom_emptable as _child
{
key empid,
firstname,
lastname,
department,
gender,
_child
}

 

ITEM ENTITY:

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'EMPLOY ITEM'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType: {
serviceQuality: #X,
sizeCategory: #XS,
dataClass: #MIXED
}

define view entity Zcom_emptable as select from zemp_itemtable
association to parent ZRS_EMP_HDR as _parent on $projection.empid = _parent.empid
{
key emp_id as empid,
key item_id as itemid,
item_type as itemtype,
item_desc as itemdesc,
status as status,
remarks as remarks,
_parent
}

 

HEADER PROJECTION VIEW :

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Projection view for HDR'
define root view entity ZPU_roothdr as projection on ZRS_EMP_HDR
{
UI.facet: [{
type: #COLLECTION,
id: 'emptable',
label: 'emptable',
purpose: #STANDARD }
],
UI.lineItem: [{
type: #STANDARD,
targetElement: 'details',
label: 'Employee Full Details'}
],
UI.identification: [{
type: #IDENTIFICATION_REFERENCE,
targetElement: 'emptable',
position: 10,
label: 'Employee Information'}
],

@UI.lineItem ( [label: 'EmpId', position: 10 ] )
empid,
@UI.lineItem ( [label: 'Firstname', position: 20 ] )
firstname,
@UI.lineItem ( [label: 'Lastname', position: 30 ] )
lastname,
@UI.lineItem ( [label: 'Age', position: 40 ] )
age,
@UI.lineItem ( [label: 'Department', position: 50 ] )
department,
@UI.lineItem ( [label: 'Gender', position: 60 ] )
gender,
identification,

/* Associations */
_child : redirected to composition child ZRS_empitem
}

 

ITEM PROJECTION VIEW :

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'employ item table'
@Metadata.ignorePropagatedAnnotations: true
define view entity ZRS_empitem as projection on Zcom_emptable
{
@UI.facet: [{
purpose: #STANDARD,
type: #IDENTIFICATION_REFERENCE,
position: 10,
label: 'EmpId'
}]
@UI.lineItem: [{ label: 'empid', position: 10 }]
@UI.identification: [{ label: 'empid', position: 10 }]
key empid,

@UI.lineItem: [{ label: 'itemid', position: 20 }]
@UI.identification: [{ label: 'itemid', position: 20 }]
key itemid,

@UI.lineItem: [{ label: 'itemtype', position: 30 }]
@UI.identification: [{ label: 'itemtype', position: 30 }]
itemtype,

@UI.lineItem: [{ label: 'itemdesc', position: 40 }]
@UI.identification: [{ label: 'itemdesc', position: 40 }]
itemdesc,

@UI.lineItem: [{ label: 'status', position: 50 }]
@UI.identification: [{ label: 'status', position: 50 }]
status,

@UI.lineItem: [{ label: 'remarks', position: 60 }]
@UI.identification: [{ label: 'remarks', position: 60 }]
remarks,

/* Associations */
_parent : redirected to parent ZPV_roothdr
}

 

BEHAVIOUR DEFINITION FOR ROOT ENTITY :

managed implementation in class zbp_rs_emp_hdr unique;
strict ( 2 );

define behavior for ZRS_EMP_HDR alias emp
persistent table zemptable
lock master
authorization master ( instance );

create ( authorization : global );
update;
delete;
field ( readonly ) empid;
association _child { create; };

mapping for zemptable
{
empid = empid;
firstname = firstname;
lastname = lastname;
department = department;
gender = gender;
}

define behavior for Zcom_emptable //alias <alias_name>
persistent table zemp_temptable
lock dependent by _parent
authorization dependent by _parent
//etag master <field_name>

update;
delete;
field ( readonly ) empid, itemid;
association _parent;

mapping for zemp_temptable{
empid = emp_id;
itemdesc = item_desc;
itemid = item_id;
itemtype = item_type;
remarks = remarks;
status = status;
}

 

ACTIVATE THE CLASS USING  QUICK FIX(CTRL + 1)  ON BEHAVIOUR DEFINTION :

CLASS lhc_ZRS_EMP_HDR DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.

METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR zrs_emp_hdr RESULT result.

METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION
IMPORTING REQUEST requested_authorizations FOR zrs_emp_hdr RESULT result.

ENDCLASS.

CLASS lhc_ZRS_EMP_HDR IMPLEMENTATION.

METHOD get_instance_authorizations.
ENDMETHOD.

METHOD get_global_authorizations.
ENDMETHOD.

ENDCLASS.

BEHAVIOUR DEFINITION FOR PROJECTION VIEW  :

projection;
strict ( 2 );

define behavior for ZPV_roothdr //alias <alias_name>
{
use create;
use update;
use delete;

use association _child { create; }
}

define behavior for ZRS_empitem //alias <alias_name>
{
use update;
use delete;

use association _parent;
}

SERVICE DEFINITION :

@EndUserText.label: 'Service definition for emp hdr'
define service ZSD_emp_hdr {
expose ZPV_roothdr;
expose ZRS_empitem;
}

SERVICE BINDING

reddysekharapathipati_10-1758087947005.png

PREVIEW

HEADER DATA

reddysekharapathipati_11-1758088065628.png

ITEM DATA

reddysekharapathipati_1-1758101505814.png

HEADER AND ITEM DATA.

reddysekharapathipati_2-1758101562110.png

GO BACK AND CLICK ON CREATE BUTTON.

 

reddysekharapathipati_4-1758101782597.png

ONCE WE CREATE HEADER WE  ALLOWED  TO CREATE ITEMS AS WE SHOWN IN ABOVE IMAGE.

ITEM.

reddysekharapathipati_5-1758101863001.png

EMPLOYE ID WILL BE AUTO POPULATED , EMPID WILL BE TAKEN FROM HEADER WHICH BE CREATED.

reddysekharapathipati_6-1758102343396.png

 

IF I WANT CHANGE HEADER AND ITEM ONCE CLICK ON EDIT.

reddysekharapathipati_0-1758101437092.png

Conclusion:
Building deep entities using the RAP model empowers developers to design structured, scalable, and future-ready SAP applications. By defining clear header–item relationships, implementing projection views, and leveraging robust service and behavior definitions, we can streamline data handling and deliver a seamless user experience. This blog walked through the essential steps for creating and editing entries within the RAP framework, providing both conceptual clarity and practical guidance.

As you continue to explore RAP, the provided resources and profile links offer opportunities to deepen your knowledge and stay connected with the SAP community. With these foundations in place, you are well-equipped to extend your application further and adopt more advanced RAP features in your development journey.


Thanks For Reading, Best Wishes
SAP BTP ABAP environment  ABAP Development  

 

 

2 Comments