Updating records using Dialog Box in RAP

Estimated read time 11 min read

Description : In this blog, we implement a RAP-based solution to update existing records using a Dialog Box (popup) instead of navigating to a separate page. 

In this  scenario user  need to update the records in list page itself instead of going of going to object page using a dialog box in RAP application

Step 1 : Create a Data base table  

@EndUserText.label : ‘DB table for Numbering’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zfa_dt_num {
key managed_num : sysuuid_x16 not null;
key unmanged_id : char10 not null;
name : char10;
age : char2;
attendance_status : char10;
lastchangedat : abp_locinst_lastchange_tstmpl;
}

 

Step2 : create a interface view and projection view upon data base  

Interface View

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘interface view for numbering’
@Metadata.ignorePropagatedAnnotations: true
define root view entity zi_zfa_num as select from zfa_dt_num
{
key managed_num as ManagedNum,
key unmanged_id as UnmangedId,
name as Name,
age as Age,
attendance_status as AttendanceStatus,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
lastchangedat as LastChangeAt
}

Projection View

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Projection view num’
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
define root view entity zc_zfa_num
as projection on zi_zfa_num
{
key ManagedNum,
key UnmangedId,
Name,
Age,
AttendanceStatus,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
LastChangeAt

Step3 : create a behavior definition for both interface view and projection view  

Interface View Behavior definition 

managed implementation in class zbp_i_zfa_num unique;
strict ( 2 );
define behavior for zi_zfa_num //alias <alias_name>
persistent table zfa_dt_num
lock master
authorization master ( instance )
etag master LastChangeAt
late numbering
{
action Updateatt parameter za_zfa_num result[1] $self;
create ( authorization : global );
update;
delete;
field ( readonly ) ManagedNum , UnmangedId;
mapping for zfa_dt_num{
ManagedNum = managed_num;
UnmangedId = unmanged_id;
Name = name;
Age = age;
AttendanceStatus = attendance_status;
LastChangeAt = lastchangedat;
}
}

Projection view Behavior defination

projection;
strict ( 2 );
define behavior for zc_zfa_num //alias <alias_name>
use etag
{
use create;
use delete;
use action Updateatt;
}

Step4 : implement the behavior pool class  

CLASS lhc_zi_zfa_num DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.

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

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

METHODS updateatt FOR MODIFY
IMPORTING keys FOR ACTION zi_zfa_num~updateatt RESULT result.

ENDCLASS.

CLASS lhc_zi_zfa_num IMPLEMENTATION.

METHOD get_instance_authorizations.
ENDMETHOD.

METHOD get_global_authorizations.
ENDMETHOD.

METHOD Updateatt.

data(lt_keys) = keys.
read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
fiELDS ( AttendanceStatus Name Age ) wiTH corRESPONDING #( keys )
reSULT data(lt_res).
data(lv_new_status) = lt_keys[ 1 ]-%param-attendance_status.
data(lv_new_Name) = lt_keys[ 1 ]-%param-name.
data(lv_new_age) = lt_keys[ 1 ]-%param-age.
modIFY enTITIES OF zi_zfa_num in LOCAL MODE
entity zi_zfa_num
uPDATE fiELDS ( AttendanceStatus Name Age )
wITH vaLUE #( (
%tky = lt_res[ 1 ]-%tky
AttendanceStatus = lv_new_status
Name = lv_new_name
age = lv_new_age
) ).

read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
all fiELDS wiTH corRESPONDING #( keys )
reSULT data(lt_res1).
result = value #(
for <lfs_num> in lt_res1 (
%tky = <lfs_num>-%tky
%param = <lfs_num>
)
).

ENDMETHOD.

ENDCLASS.

CLASS lsc_ZI_ZFA_NUM DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.

METHODS adjust_numbers REDEFINITION.

METHODS cleanup_finalize REDEFINITION.

ENDCLASS.

CLASS lsc_ZI_ZFA_NUM IMPLEMENTATION.

METHOD adjust_numbers.
DATA(lt_managedid) = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
SELECT MAX( unmanged_id ) FROM zfa_dt_num INTO (lv_num).
IF sy-subrc = 0.
lv_num += 1 .
ELSE.
lv_num = 000000001 .
ENDIF.
LOOP AT mapped-zi_zfa_num REFERENCE INTO DATA(ls_num).
ls_num->ManagedNum = lt_managedid.
ls_num->UnmangedId = lv_num.
ENDLOOP.

ENDMETHOD.

METHOD cleanup_finalize.

ENDMETHOD.

ENDCLASS.

Step 5 : For achieving the Dialog box we have to make use of a abstract entity ,  in this abstract entity declare the fields which you have to update  

@EndUserText.label: ‘Abstract entity for numbering’
@Metadata.allowExtensions: true
define abstract entity za_zfa_num
// with parameters parameter_name : parameter_type
{
name : char10;
age : char2;
attendance_status : char10;
}

Step 6 : create a metadata for this abstract entity

@Metadata.layer: #CORE
annotate entity za_zfa_num with
{
@EndUserText.label: ‘ Update Name’
name;
@EndUserText.label: ‘ Update Age’
age;
@EndUserText.label: ‘Set Student Status’
attendance_status;
}

Step7 : now for displaying the popup we have to make use of custom actions ,  declare a actions with parameters , in parameter give the abstract entity name  

Step8 : now implement the logic for updating the records in action method  

METHOD Updateatt.

data(lt_keys) = keys.

read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
fiELDS ( AttendanceStatus Name Age ) wiTH corRESPONDING #( keys )
reSULT data(lt_res).
data(lv_new_status) = lt_keys[ 1 ]-%param-attendance_status.
data(lv_new_Name) = lt_keys[ 1 ]-%param-name.
data(lv_new_age) = lt_keys[ 1 ]-%param-age.

modIFY enTITIES OF zi_zfa_num in LOCAL MODE
entity zi_zfa_num
uPDATE fiELDS ( AttendanceStatus Name Age )
wITH vaLUE #( (
%tky = lt_res[ 1 ]-%tky
AttendanceStatus = lv_new_status
Name = lv_new_name
age = lv_new_age
) ).

read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
all fiELDS wiTH corRESPONDING #( keys )
reSULT data(lt_res1).
result = value #(
for <lfs_num> in lt_res1 (
%tky = <lfs_num>-%tky
%param = <lfs_num>
)
).

ENDMETHOD.

Step9 : Create a service definition and service binding for the projection view and expose it

Here we can see we have 2 records and a button is visible UPDATE RECORDS  

Select the button and click on the update record action  

Edit the records  

Here you can see the records have been updated  

Conclusion :  Using a Dialog Box in RAP makes record updates faster and more user-friendly by keeping the user on the same screen while still following RAP’s behavior, validations, and transactional processing 

 

 

 

​ Description : In this blog, we implement a RAP-based solution to update existing records using a Dialog Box (popup) instead of navigating to a separate page. In this  scenario user  need to update the records in list page itself instead of going of going to object page using a dialog box in RAP applicationStep 1 : Create a Data base table  @EndUserText.label : ‘DB table for Numbering’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zfa_dt_num {
key managed_num : sysuuid_x16 not null;
key unmanged_id : char10 not null;
name : char10;
age : char2;
attendance_status : char10;
lastchangedat : abp_locinst_lastchange_tstmpl;
}  Step2 : create a interface view and projection view upon data base  Interface View@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘interface view for numbering’
@Metadata.ignorePropagatedAnnotations: true
define root view entity zi_zfa_num as select from zfa_dt_num
{
key managed_num as ManagedNum,
key unmanged_id as UnmangedId,
name as Name,
age as Age,
attendance_status as AttendanceStatus,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
lastchangedat as LastChangeAt
} Projection View@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Projection view num’
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
define root view entity zc_zfa_num
as projection on zi_zfa_num
{
key ManagedNum,
key UnmangedId,
Name,
Age,
AttendanceStatus,
@Semantics.systemDateTime.localInstanceLastChangedAt: true
LastChangeAt Step3 : create a behavior definition for both interface view and projection view  Interface View Behavior definition managed implementation in class zbp_i_zfa_num unique;
strict ( 2 );
define behavior for zi_zfa_num //alias <alias_name>
persistent table zfa_dt_num
lock master
authorization master ( instance )
etag master LastChangeAt
late numbering
{
action Updateatt parameter za_zfa_num result[1] $self;
create ( authorization : global );
update;
delete;
field ( readonly ) ManagedNum , UnmangedId;
mapping for zfa_dt_num{
ManagedNum = managed_num;
UnmangedId = unmanged_id;
Name = name;
Age = age;
AttendanceStatus = attendance_status;
LastChangeAt = lastchangedat;
}
} Projection view Behavior definationprojection;
strict ( 2 );
define behavior for zc_zfa_num //alias <alias_name>
use etag
{
use create;
use delete;
use action Updateatt;
} Step4 : implement the behavior pool class  CLASS lhc_zi_zfa_num DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.

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

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

METHODS updateatt FOR MODIFY
IMPORTING keys FOR ACTION zi_zfa_num~updateatt RESULT result.

ENDCLASS.

CLASS lhc_zi_zfa_num IMPLEMENTATION.

METHOD get_instance_authorizations.
ENDMETHOD.

METHOD get_global_authorizations.
ENDMETHOD.

METHOD Updateatt.

data(lt_keys) = keys.
read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
fiELDS ( AttendanceStatus Name Age ) wiTH corRESPONDING #( keys )
reSULT data(lt_res).
data(lv_new_status) = lt_keys[ 1 ]-%param-attendance_status.
data(lv_new_Name) = lt_keys[ 1 ]-%param-name.
data(lv_new_age) = lt_keys[ 1 ]-%param-age.
modIFY enTITIES OF zi_zfa_num in LOCAL MODE
entity zi_zfa_num
uPDATE fiELDS ( AttendanceStatus Name Age )
wITH vaLUE #( (
%tky = lt_res[ 1 ]-%tky
AttendanceStatus = lv_new_status
Name = lv_new_name
age = lv_new_age
) ).

read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
all fiELDS wiTH corRESPONDING #( keys )
reSULT data(lt_res1).
result = value #(
for <lfs_num> in lt_res1 (
%tky = <lfs_num>-%tky
%param = <lfs_num>
)
).

ENDMETHOD.

ENDCLASS.

CLASS lsc_ZI_ZFA_NUM DEFINITION INHERITING FROM cl_abap_behavior_saver.
PROTECTED SECTION.

METHODS adjust_numbers REDEFINITION.

METHODS cleanup_finalize REDEFINITION.

ENDCLASS.

CLASS lsc_ZI_ZFA_NUM IMPLEMENTATION.

METHOD adjust_numbers.
DATA(lt_managedid) = cl_uuid_factory=>create_system_uuid( )->create_uuid_x16( ).
SELECT MAX( unmanged_id ) FROM zfa_dt_num INTO (lv_num).
IF sy-subrc = 0.
lv_num += 1 .
ELSE.
lv_num = 000000001 .
ENDIF.
LOOP AT mapped-zi_zfa_num REFERENCE INTO DATA(ls_num).
ls_num->ManagedNum = lt_managedid.
ls_num->UnmangedId = lv_num.
ENDLOOP.

ENDMETHOD.

METHOD cleanup_finalize.

ENDMETHOD.

ENDCLASS. Step 5 : For achieving the Dialog box we have to make use of a abstract entity ,  in this abstract entity declare the fields which you have to update  @EndUserText.label: ‘Abstract entity for numbering’
@Metadata.allowExtensions: true
define abstract entity za_zfa_num
// with parameters parameter_name : parameter_type
{
name : char10;
age : char2;
attendance_status : char10;
} Step 6 : create a metadata for this abstract entity@Metadata.layer: #CORE
annotate entity za_zfa_num with
{
@EndUserText.label: ‘ Update Name’
name;
@EndUserText.label: ‘ Update Age’
age;
@EndUserText.label: ‘Set Student Status’
attendance_status;
} Step7 : now for displaying the popup we have to make use of custom actions ,  declare a actions with parameters , in parameter give the abstract entity name  Step8 : now implement the logic for updating the records in action method  METHOD Updateatt.

data(lt_keys) = keys.

read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
fiELDS ( AttendanceStatus Name Age ) wiTH corRESPONDING #( keys )
reSULT data(lt_res).
data(lv_new_status) = lt_keys[ 1 ]-%param-attendance_status.
data(lv_new_Name) = lt_keys[ 1 ]-%param-name.
data(lv_new_age) = lt_keys[ 1 ]-%param-age.

modIFY enTITIES OF zi_zfa_num in LOCAL MODE
entity zi_zfa_num
uPDATE fiELDS ( AttendanceStatus Name Age )
wITH vaLUE #( (
%tky = lt_res[ 1 ]-%tky
AttendanceStatus = lv_new_status
Name = lv_new_name
age = lv_new_age
) ).

read eNTITIES OF zi_zfa_num in LOCAL MODE
ENTITY zi_zfa_num
all fiELDS wiTH corRESPONDING #( keys )
reSULT data(lt_res1).
result = value #(
for <lfs_num> in lt_res1 (
%tky = <lfs_num>-%tky
%param = <lfs_num>
)
).

ENDMETHOD. Step9 : Create a service definition and service binding for the projection view and expose itHere we can see we have 2 records and a button is visible UPDATE RECORDS  Select the button and click on the update record action  Edit the records  Here you can see the records have been updated  Conclusion :  Using a Dialog Box in RAP makes record updates faster and more user-friendly by keeping the user on the same screen while still following RAP’s behavior, validations, and transactional processing      Read More Technology Blog Posts by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author