Home - Cloud ERP Extensibility
After having added a field we will add an action to the base RAP BO.
⚠ Please note:
Actions can only be added using extensibility to fields that have been added via extensibility themselves. This is why we have added this exercise as the fourth exercise after a field for adding feedback has been added to our Shop RAP business object.
This action will be used to create/ update comments. We will thus make the new field that has been added to enter a comment read-only and add the required extensions to the
- BDEF (add the action)
- Projection BDEF (add a use statement)
- Projection view (add UI annotations to make the button of the action visible)
We want to provide the feedback for an order as a parameter of an action that will be added as an extenstion. Parameters are passed to the action using abstract entites.
-
Right click on the folder Data Definition in your package
ZRAP630_###_EXT
-
Choose New data defintion from the context menu
- Package:
ZRAP630_###_EXT
- Name:
ZRAP630_A_Feedback_###
- Description:
Pass feedback as a parameter
and press Next
- Package:
-
Select a transport
-
Expand the folder Abstract Entity(creation)
-
Select the template Define abstract entity with parameters and press Finish
-
Enter the following coding
@EndUserText.label: 'Pass feedback as a parameter' define abstract entity ZRAP630_A_Feedback_### { feedback : abap.char(100); }
-
Activate your changes
Now we can define the action with the parameter that has just been created.
-
Open the behavior extension
ZRAP630R_EXT_SHOPTP_###
-
Add the following code snippet in your behavior extension
ZRAP630R_EXT_SHOPTP_###
field(readonly) zzfeedbackzaa; action(authorization : global, features : instance ) ZZ_ProvideFeedback parameter ZRAP630_A_Feedback_### result[1] $self;
so that your code now reads
extension using interface zrap630i_shoptp_### implementation in class zbp_rap630r_ext_shoptp_### unique; extend behavior for Shop { validation zz_validateDeliverydate on save { create; field DeliveryDate; } extend draft determine action Prepare { validation zz_validateDeliveryDate; } determination ZZ_setOverallStatus on modify { field OrderedItem; } side effects { field OrderedItem affects field OrderItemPrice , field CurrencyCode ; } field(readonly) zzfeedbackzaa; action(authorization : global, features : instance ) ZZ_ProvideFeedback parameter ZRAP630_A_Feedback_### result[1] $self; }
-
Activate your changes.
-
Use the code assist (Press Ctrl+1) on the Shop entity and let the framework generate the missing artefacts.
-
Open the local class of the behavior implementation class.
-
Implement the method zz_providefeedback and activate your changes
METHOD ZZ_ProvideFeedback. MODIFY ENTITIES OF ZRAP630I_ShopTP_### IN LOCAL MODE ENTITY Shop UPDATE FIELDS ( zzfeedbackzaa ) WITH VALUE #( FOR key IN keys ( %tky = key-%tky zzfeedbackzaa = key-%param-feedback ) ). "Read the changed data for action result READ ENTITIES OF ZRAP630I_ShopTP_### IN LOCAL MODE ENTITY Shop ALL FIELDS WITH CORRESPONDING #( keys ) RESULT DATA(result_read). "return result entities result = VALUE #( FOR order_2 IN result_read ( %tky = order_2-%tky %param = order_2 ) ). ENDMETHOD.
In order to make the action visible an appropriate use action
statement has to added to the projection level of the BDEF of the extensible root BO.
-
Right click on the projection behavior definition
ZRAP630C_ShopTP_###
within the packageZRAP630_###
and select New Behavior Extension -
Fill in the data for the projection behavior extension
- Package:
ZRAP630_###_EXT
- Name:
ZRAP630C_Ext_SHOPTP_###
- Description: Behavior extension for projection bdef
- Package:
-
Select a transport and press Finish
-
Enter a use statement for your action so that the code looks like
extension for projection; extend behavior for Shop { use action ZZ_ProvideFeedback; }
UI annotations have to be added to make the action button visible. This is done in the C-View Extension ZRAP630C_EXT_SHOPTP_###
.
For this you have to add the following code snippet to the UI.identification
and UI.lineitem
annotations.
, { type: #FOR_ACTION, dataAction: 'ZZ_ProvideFeedback', label: 'Update feedback' }
so that the code of ZX_ZRAP630C_SHOPTP_###
now reads
extend view entity ZRAP630C_ShopTP_### with
{
@EndUserText.label: 'Feedback'
@UI.dataFieldDefault: [{hidden: false}]
@UI.identification: [{hidden: false},
{type: #FOR_ACTION, dataAction: 'ZZ_ProvideFeedback', label: 'Update feedback' } ]
@UI.lineItem: [{hidden: false},
{type: #FOR_ACTION, dataAction: 'ZZ_ProvideFeedback', label: 'Update feedback' } ]
Shop.ZZFEEDBACKZAA as ZZFEEDBACKZAA
}
You should now see an action button that allows you to enter feedback.
You've now finished.