ABAP RESTful Application Programming Model – Enable Change Set processing in Multi select Fiori Applications
I hope you had a pleasant start to 2022 😊
I would again like to share my learning from a challenge which I recently encountered while implementing a RAP based SAP Fiori Elements application for our customer, and the respective solution, using which I could overcome the challenge.
We wanted to create a RAP based SAP Fiori Elements List Report application. Customer wanted to have multiple selections enabled in the List Report page for this Fiori Application. It was required to have certain custom actions in the application called ‘Group’.
So basically, the application user can select multiple entries from the list and click on Custom action to group all the selected entries together and assign a common grouping ID to it. However, there were also multiple validations required like we should not allow grouping of all the selected entries if one or more of the selected entries are already grouped.
To achieve the above requirement, we created a RAP based managed service and added custom action called Group to our app, exposed it to UI, enabled multi select in UI by modifying manifest.json (each step explained in detail in next section), and added action implementation in Behavior Pool class to assign Grouping ID to all the selected entries by generating a unique ID using number range object. However, after implementing these steps, when we tested the application, we got to know that only a single record per backend call was being sent from UI to backend. This means, if the user selected 3 entries and clicked on Group, the action implementation would be called 3 times, with a single ‘key’ value in each call, hence, at a given point of time, we didn’t know how many records were selected, and if some of the records selected were already grouped previously. Hence, the validation of the grouping couldn’t be achieved due to this challenge.
To overcome the challenge, we had to explicitly turn on the Changeset using invocation grouping. This can be simply activated by adding parameter ‘invocationGrouping’ in the UI annotation where you are exposing your action and set its value to #CHANGE_SET as highlighted below.
As soon as invocation grouping is added, we were then able to receive all the selected entries in a single backend call, and apart from implementing Grouping, we were also able to implement all the validations, as we now know all the selected entries together.
To demonstrate, I am using ABAP cloud trial to develop the service using a Travel entity and adding a custom action ”Group” to it and exposing it to UI using Business Application Studio.
1. Create a root Travel view entity:
2. Create Behavior Definition and add action called ‘group’.
3. Create Behavior Pool class and implement logic in action implementation method.
4. Create Projection View.
5. Create Behavior Definition Projection.
6. Create Service Definition:
7. Create Service Binding:
8. Expose the oData service to UI using BAS:
Create a new project from Template in Business Application Studio/WebIDE to generate a Fiori Elements app for the generated oData service. Below is the project I generated in BAS:
9. Edit manifest.json file to enable multi select
Test the Fiori App in BAS to see multi-select enablement:
Select some records and hit ‘Group’ button:
Effect of Invocation Grouping:
The below steps explain effect of invocation grouping:
1. Expose ‘Group’ action without invocation Grouping
Add a break-point in action implementation
Select multiple records in UI and hit ‘Group’:
Debugger would stop at action implementation. Check ‘keys’. Only a single value in first backend call. Method is triggered twice since 2 records are selected
2. Expose Group action with invocation grouping
Again, add select multiple records in UI and hit ‘Group’
Check no of values in ‘keys’ in debugging. This time, since we have invocation grouping activated, we receive all the selected entries in a single backend call. That’s the effect invocation grouping brings.
This way, I was able to add all the validations as well.
Please feel free to share your thoughts and feedback 🙂