In the previous exercise, you've defined and implemented different instance-bound actions for the BO entity Travel (see Exercise 6).
In the present exercise, you will implement the dynamic instance feature control for some of the standard and non-standard operations of the Travel entity.
- 7.1 - Define the Dynamic Instance Feature Control
- 7.2 - Implement the Dynamic Instance Feature Control
- 7.3 - Preview and Test the Enhanced App
- Summary
Reminder: Do not forget to replace the suffix placeholder
###
with your choosen or assigned group ID in the exercise steps below.
As an application developer you may want to determine based on certain attributes of your business object entity, which fields should be read-only or mandatory or which functionality like update or actions are allowed. As this property is related to an instance of this business object it is called Dynamic Feature Control.
ℹ Further reading: Adding Static and Dynamic Feature Control
Define the dynamic instance feature control for the standard operations
update
anddelete
, the draft actionEdit
, and the instance actiondeductDiscount
.⚠ If implemented in the previous exercise (see Exercise 6.3 - Actions), you'll also define the dynamic instance feature control for the optional instance actions
acceptTravel
andrejectTravel
.
🔵 Click to expand!
-
Open your behavior definition
ZRAP100_R_TRAVELTP_###
and add the addition( features : instance )
to the following operations as shown on following code snippet and the screenshot below:-
Standard operations
update
anddelete
-
Draft action
Edit
-
Instance action
deductDiscount
... create; update ( features : instance ) ; delete ( features : instance ) ; ... action ( features : instance ) deductDiscount parameter /dmo/a_travel_discount result [1] $self; ... draft action ( features : instance ) Edit;
⚠Attention⚠:
In case you've defined and implemented the instance actionsacceptTravel
andrejectTravel
in the previous exercise (see Exercise 6.3 - Actions), then also add the code snippet provided below as shown on the screenshot.action ( features : instance ) acceptTravel result [1] $self; action ( features : instance ) rejectTravel result [1] $self;
Your souce code will look like this:
-
-
At the top of the behavior definition, set the cursor on BO entity name
ZRAP100_R_TRAVELTP_###
and press Ctrl+1 to open the Quick Assist view.Select the entry
Add method for operation instance_features of entity zrap100_r_traveltp_### ...
to add the required methods to the local handler classlcl_handler
of your behavior poolZRAP100_BP_TRAVELTP_###
.The result should look like this:
-
Check the interface of the method
get_instance_features
in the declaration part of the local handler class in the behavior poolZRAP100_BP_TRAVEL_###
.Set the cursor on one of the method name, press F2 to open the ABAP Element Info view, and examine the full method interface.
Short explanation:
- The addition
FOR INSTANCE FEATURES
after the method name indicates that this method provides the implementation of an instance-based dynamic feature control. - Method signature of the instance method
get_instance_features
:IMPORTING
parameterkeys
- a table containing the keys of the instances on which the feature control must be executed.- Implicit
IMPORTING
parameterrequested_features
- structure reflecting which elements (fields, standard operations, and actions) of the entity are requested for dynamic feature control by the consumer. - Implicit
CHANGING
parameters (aka implicit response parameters):result
- used to store the result of the performed feature control calculation.failed
- table with information for identifying the data set where an error occurred.reported
- table with data for instance-specific messages.
Go ahead with the implementation.
- The addition
Implement the dynamic instance feature control for the standard operations
update
anddelete
, the draft actionEdit
, and the instance actiondeductDiscount
.⚠ If defined in the previous exercise steps, you'll also implement the dynamic instance feature control for the the instance actions
acceptTravel
andrejectTravel
.Following dynamic behavior will be implemented in the backend - and shown on the Fiori UI:
- If a travel instance has the overall status
Accepted
(A
), then the standard operationsupdate
anddelete
, and the actionsEdit
anddeductDiscount
must be disabled for the given instance.- In addition, following toggle behavior (enable/disable) should be implemented:
- If the overall status is
Accepted
(A
), then the actionacceptTravel
must be disabled.- If the overall status is
Rejected
(X
), then the actionrejectTravel
must be disabled.
🔵 Click to expand!
-
Implement the instance feature control method
get_instance_features
in the implementation part of the local handler class.The logic consists of the following steps:
- Read the relevant data of the transferred travel instances.
Only the fields
TravelID
andOverallStatus
are needed to determine the operation state in the present scenario. - Evaluate the conditions and determine the state of the different operations.
The
COND
operator is used inline in the present scenario for the purpose. - Set the result set appropriately.
For that, replace the current method implementation with the code snippet provided below and replace all occurrences of the placeholder
###
with your group ID.⚠Attention⚠:
In case you've defined and implemented the instance actionsacceptTravel
andrejectTravel
in the previous exercise (see Exercise 6 - Actions), then uncomment the appropriate four (4) code lines in the inserted source code.You can make use of the F1 Help for more information about the EML statements and other ABAP constructs.
************************************************************************** * Instance-based dynamic feature control ************************************************************************** METHOD get_instance_features. " read relevant travel instance data READ ENTITIES OF ZRAP100_R_TravelTP_### IN LOCAL MODE ENTITY travel FIELDS ( TravelID OverallStatus ) WITH CORRESPONDING #( keys ) RESULT DATA(travels) FAILED failed. " evaluate the conditions, set the operation state, and set result parameter result = VALUE #( FOR travel IN travels ( %tky = travel-%tky %features-%update = COND #( WHEN travel-OverallStatus = travel_status-accepted THEN if_abap_behv=>fc-o-disabled ELSE if_abap_behv=>fc-o-enabled ) %features-%delete = COND #( WHEN travel-OverallStatus = travel_status-open THEN if_abap_behv=>fc-o-enabled ELSE if_abap_behv=>fc-o-disabled ) * %action-Edit = COND #( WHEN travel-OverallStatus = travel_status-accepted * THEN if_abap_behv=>fc-o-disabled ELSE if_abap_behv=>fc-o-enabled ) * %action-acceptTravel = COND #( WHEN travel-OverallStatus = travel_status-accepted * THEN if_abap_behv=>fc-o-disabled ELSE if_abap_behv=>fc-o-enabled ) * %action-rejectTravel = COND #( WHEN travel-OverallStatus = travel_status-rejected * THEN if_abap_behv=>fc-o-disabled ELSE if_abap_behv=>fc-o-enabled ) * %action-deductDiscount = COND #( WHEN travel-OverallStatus = travel_status-open * THEN if_abap_behv=>fc-o-enabled ELSE if_abap_behv=>fc-o-disabled ) ) ). ENDMETHOD.
Your source code should look like this:
- Read the relevant data of the transferred travel instances.
Only the fields
You're through with the implementation.
Now the SAP Fiori elements app can be tested.
🔵 Click to expand!
You can either refresh your application in the browser using F5 if the browser is still open - or go to your service binding ZRAP100_UI_TRAVEL_O4_###
and start the Fiori elements App preview for the Travel
entity set.
You can go ahead and test the logic of the dynamic feature control implemented in the backend.
For example, select a travel instance that has the overall status Accepted, and check the state of the Accepted, the Edit, and the Delete buttons. They all shall be disable.
Remember the implemented dynamic BO behavior expected on the UI:
- If a travel instance has the overall status Accepted (
A
) or Rejected (X
), then the button Edit and Delete must be disabled for the given instance.- In addition, following toggle behavior (enable/disable) should be displayed for both instance actions:
- If the overall status Accepted (
A
), then the action Accept Travel must be disabled.- If the overall status Rejected (
X
), then the action Reject Travel must be disabled
Now that you've...
- defined the dynamic instance feature control for standard and non-standard operations in the behavior definition,
- implemented it in the behavior pool, and
- preview and test the enhanced Fiori elements Travel app,
you can continue with the next exercise – [Optional] Exercise 8: Write an ABAP Unit Test for the RAP BO