IntroductionÂ
 Making a field read-only or non-editable dependent on the value of another field is a frequent requirement. This blog post will explain how to use the RAP model to accomplish this.
The scenario we’ll cover is making the VBTYP field read-only based on the value of the AUARTÂ field.Â
Setting Up the RAP ApplicationÂ
Before implementing the dynamic behavior, we need a basic RAP application structure.Â
Database Table@EndUserText.label : ‘Data base Table for sales order’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zdemo_dt_so {
key vbeln : vbeln_va not null;
erdat : erdat;
ernam : ernam;
vbtyp : vbtypl;
auart : auart;
}
 2 . Interface View
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Interface view for sales order’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define root view entity ZDEMO_I_SO as select from zdemo_dt_so
{
key vbeln as Vbeln,
erdat as Erdat,
ernam as Ernam,
vbtyp as Vbtyp,
auart as Auart
}
 3 . Projection View
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Projection view for Sales order’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
@Metadata.allowExtensions: true
define root view entity ZDEMO_P_SO as projection on ZDEMO_I_SO
{
key Vbeln,
Erdat,
Ernam,
Vbtyp,
Auart
}
 4 . Behavior DefinitionÂ
managed implementation in class zbp_demo_i_so unique;
strict ( 2 );
define behavior for ZDEMO_I_SO //alias <alias_name>
persistent table zdemo_dt_so
lock master
authorization master ( instance )
//etag master <field_name>
{
field (features : instance ) Vbtyp ;
validation vbtyp_valid on save { field Auart , Vbtyp ; }
create;
update;
delete;
}projection;
strict ( 2 );
define behavior for ZDEMO_P_SO //alias <alias_name>
{
use create;
use update;
use delete;
}
 5 .Service Definition and Binding
@EndUserText.label: ‘Service def SO’
define service ZDEMO_P_SO {
expose ZDEMO_P_SO;
}
Once you click on preview you can see the application and create a record
Implementing Dynamic Feature ControlÂ
Our goal is to make the  ,VBTYP field read-only if the AUART field has a specific value, like ‘KA’.
For Achieving this scenario first we need to Define a Dynamic feature control for the field ‘VBTYP’Â
The logic for making the field read-only presents in the Â
get_instance_features method of your behavior implementation class. This method is automatically created by the RAP framework. Here’s the code you’ll need to write:Â
METHOD get_instance_features.
READ ENTITIES OF ZDEMO_I_SO IN LOCAL MODE
ENTITY zdemo_i_so FIELDS ( Vbeln Auart )
WITH CORRESPONDING #( keys )
RESULT data(lt_result).
LOOP AT lt_result INTO data(ls_result).
if ls_result-Auart = ‘KA’.
result = VALUE #(
(
%tky = ls_result-%tky
%features-%field-Vbtyp = if_abap_behv=>fc-f-read_only
) ).
ELSE.
result = VALUE #(
(
%tky = ls_result-%tky
%features-%field-Vbtyp = if_abap_behv=>fc-f-unrestricted
) ).
ENDIF.
ENDLOOP.
ENDMETHOD.
After implementing the logic, activate your behavior implementation class. Now, when you refresh your application, the changes will be applied Â
In your application, you can create a few records with different Â
AUART values, such as ‘KA’ and ‘OR’. When you try to edit the record where Â
AUART is ‘KA’, you will notice that the VBTYP field is grayed out and you are unable to change its value. However, if you edit a record whereÂ
AUART is ‘OR’, the VBTYP field will remain editable, allowing you to change its value freely.
This demonstrates how the field’s behavior is dynamically controlled.Â
Conclusion : Â
The blog post effectively demonstrates how to dynamically make a field read-only within the SAP RAP.  The core method involves using dynamic feature control.
Â
Â
Â
​ Introduction  Making a field read-only or non-editable dependent on the value of another field is a frequent requirement. This blog post will explain how to use the RAP model to accomplish this.The scenario we’ll cover is making the VBTYP field read-only based on the value of the AUART field. Setting Up the RAP Application Before implementing the dynamic behavior, we need a basic RAP application structure. Database Table@EndUserText.label : ‘Data base Table for sales order’
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zdemo_dt_so {
key vbeln : vbeln_va not null;
erdat : erdat;
ernam : ernam;
vbtyp : vbtypl;
auart : auart;
}Â 2 . Interface View@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Interface view for sales order’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define root view entity ZDEMO_I_SO as select from zdemo_dt_so
{
key vbeln as Vbeln,
erdat as Erdat,
ernam as Ernam,
vbtyp as Vbtyp,
auart as Auart
} 3 . Projection View@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘Projection view for Sales order’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
@Metadata.allowExtensions: true
define root view entity ZDEMO_P_SO as projection on ZDEMO_I_SO
{
key Vbeln,
Erdat,
Ernam,
Vbtyp,
Auart
} 4 . Behavior Definition managed implementation in class zbp_demo_i_so unique;
strict ( 2 );
define behavior for ZDEMO_I_SO //alias <alias_name>
persistent table zdemo_dt_so
lock master
authorization master ( instance )
//etag master <field_name>
{
field (features : instance ) Vbtyp ;
validation vbtyp_valid on save { field Auart , Vbtyp ; }
create;
update;
delete;
}projection;
strict ( 2 );
define behavior for ZDEMO_P_SO //alias <alias_name>
{
use create;
use update;
use delete;
}Â 5 .Service Definition and Binding@EndUserText.label: ‘Service def SO’
define service ZDEMO_P_SO {
expose ZDEMO_P_SO;
}Once you click on preview you can see the application and create a recordImplementing Dynamic Feature Control Our goal is to make the  ,VBTYP field read-only if the AUART field has a specific value, like ‘KA’.For Achieving this scenario first we need to Define a Dynamic feature control for the field ‘VBTYP’ The logic for making the field read-only presents in the  get_instance_features method of your behavior implementation class. This method is automatically created by the RAP framework. Here’s the code you’ll need to write: METHOD get_instance_features.
READ ENTITIES OF ZDEMO_I_SO IN LOCAL MODE
ENTITY zdemo_i_so FIELDS ( Vbeln Auart )
WITH CORRESPONDING #( keys )
RESULT data(lt_result).
LOOP AT lt_result INTO data(ls_result).
if ls_result-Auart = ‘KA’.
result = VALUE #(
(
%tky = ls_result-%tky
%features-%field-Vbtyp = if_abap_behv=>fc-f-read_only
) ).
ELSE.
result = VALUE #(
(
%tky = ls_result-%tky
%features-%field-Vbtyp = if_abap_behv=>fc-f-unrestricted
) ).
ENDIF.
ENDLOOP.
ENDMETHOD.After implementing the logic, activate your behavior implementation class. Now, when you refresh your application, the changes will be applied  In your application, you can create a few records with different  AUART values, such as ‘KA’ and ‘OR’. When you try to edit the record where  AUART is ‘KA’, you will notice that the VBTYP field is grayed out and you are unable to change its value. However, if you edit a record where AUART is ‘OR’, the VBTYP field will remain editable, allowing you to change its value freely.This demonstrates how the field’s behavior is dynamically controlled. Conclusion :  The blog post effectively demonstrates how to dynamically make a field read-only within the SAP RAP.  The core method involves using dynamic feature control.     Read More Technology Blog Posts by Members articlesÂ
#SAP
#SAPTechnologyblog