Fiori Elements List - Add and Implement Action Button
Fiori Elements List - Add and Implement Action Button
Technical Articles
Pawan Kesari
May 31, 2019
| 7 minute read
Follow 29 27 28,048
Looking at some SAP standard apps I finally figured out how to achieve this without
UI5 extension in Web-IDE.
For the purpose of this blog, I’ll use tried and tested flight data model. You should be
able to replicate the solution in your system using the code I’ve provided.
Introduction
In this blog I’ll show you how to add action button(s) on Fiori Element List Page
without making UI5 extension in Web-IDE or using BOPF.
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 1/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
flight and reverse the cancellation. In part 1 of the blog, we will see basic
implementation. To keep blog manageable (for me) I am going to keep additional
features like message handling, enable/disable action buttons in part 2 of the blog.
As a starting point, I have this Fiori Elements List App which is based on CDS View. I
have exposed CDS View via SEGW using Data Source Reference.
@AbapCatalog.sqlViewName: 'ZISPFLI01'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@ObjectModel.foreignKey.association: '_Airline'
@UI.lineItem: [{ position: 20 }]
@ObjectModel.foreignKey.association: '_CityTo'
@ObjectModel.foreignKey.association: '_AirportFrom'
@ObjectModel.foreignKey.association: '_CityTo'
@ObjectModel.foreignKey.association: '_AirportTo'
@UI.lineItem: [{ position: 90 }]
spfli.deptime as DepartureTime,
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 2/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
spfli.arrtime as ArrivalTime,
CancellationInfo.cancelledon,
CancellationInfo.cancelledby,
@UI.hidden:true
@UI.hidden:true
_Airline,
_AirportFrom,
_AirportTo,
_CityFrom,
_CityTo
SEGW: ZIFLTCON
Table: ZSPFLI_ACT
App
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 3/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
If you are struggling to get to this point I would recommend you check Fiori Elements
Wiki Page, section How to Guides for List Report. Make note that I have exposed CDS
via SEGW and not directly using OData.pubish annotation. This is important because
its DPC_EXT and MPC_EXT classes which we will be using to add actions and put
ABAP code to process these actions.
To add action button first we will have to add function import in OData service
following which we will add annotation in CDS View to display buttons and link it to
function import name.
* <SIGNATURE>--------------------------------------------------------
* | Instance Private Method ZCL_ZIFLTCON_MPC_EXT->ADD_ACTION
* +------------------------------------------------------------------
* | [--->] IV_ACTION_NAME TYPE /IWBEP/MED_EXTE
* +------------------------------------------------------------------
method add_action.
lo_action->set_return_entity_type( 'ZI_FlightConnectionsType' ) .
lo_action->set_return_entity_set( 'ZI_FlightConnections' ).
lo_action->set_http_method( 'PUT' ).
lo_action->set_return_multiplicity( /iwbep/if_mgw_med_odata_types=
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 4/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
data(lo_parameter) = lo_action->create_input_parameter(
iv_parameter_name = 'Airline'
iv_abap_fieldname = 'AIRLINE' ).
lo_parameter->/iwbep/if_mgw_odata_property~set_type_edm_string( )
lo_parameter->set_maxlength( iv_max_length = 3 ).
data(lo_parameter1) = lo_action->create_input_parameter(
iv_parameter_name = 'FlightConnectio
iv_abap_fieldname = 'FLIGHTCONNECTIO
lo_parameter1->/iwbep/if_mgw_odata_property~set_type_edm_string(
lo_parameter1->set_maxlength( iv_max_length = 4 ).
data(lo_annotation) = lo_action->/iwbep/if_mgw_odata_annotatabl~c
lo_annotation->add( iv_key = 'action-for' iv_value = 'ZI_FlightCo
lo_annotation = lo_action->/iwbep/if_mgw_odata_annotatabl~create_a
lo_annotation->add( iv_key = 'applicable-path' iv_value = lv_actio
endmethod.
Redefine DEFINE method in MPC_EXT class and make call to ADD_ACTION method
to add function imports.
method define.
super->define( ) .
endmethod.
Following above changes check OData service metadata have function import added
to it.
....
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 5/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
@ObjectModel.foreignKey.association: '_Airline'
....
After above changes and activation you should be able to see action buttons on the
list page.
method /iwbep/if_mgw_appl_srv_runtime~changeset_begin.
cv_defer_mode = abap_true .
endmethod.
method /iwbep/if_mgw_appl_srv_runtime~changeset_process.
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 6/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
lo_func_import_context ?= <lfs_changeset_request>-request_contex
data(lv_function_import_name) = lo_func_import_context->get_fun
"read parameters
lt_parameters = lo_func_import_context->get_parameters( ).
"set/reset values
case lv_function_import_name.
when 'CancelFlight'.
ls_flight_con_status-cancelledby = sy-uname .
ls_flight_con_status-cancelledon = sy-datum .
when 'KeepFlight'.
clear ls_flight_con_status-cancelledby .
clear ls_flight_con_status-cancelledon .
endcase .
"do you know - even if you haven't yet committed the changes,
"insert in CT_CHANGESET_RESPONSE
ls_changeset_response-operation_no = <lfs_changeset_request>-o
copy_data_to_ref(
exporting
is_data = ls_result
changing
cr_data = ls_changeset_response-entity_data ).
endloop .
endmethod.
https://blogs.sap.com/2019/05/31/fiori-elements-list-add-and-implement-action-button/ 7/26
31/10/2022 19:53 Fiori Elements List – Add and Implement Action Button | SAP Blogs
Result
After activation buttons should work
Conclusion
Action can be added to Fiori Element List Report using annotation, code in MPC_EXT
and DPC_EXT classes.
As I mentioned earlier I couldn’t find way to add action using BOPF in List Report. If
you have managed to do that then please share your experience.
What’s next:
Action to download file e.g. download sales confirmation output on list of sales order.
Alert Moderator
Assigned Tags
SAP Fiori
ABAP Development
OData
action button