Professional Documents
Culture Documents
Invoking Static BOPF Action From Custom Pop Up in Fiori Elements App
Invoking Static BOPF Action From Custom Pop Up in Fiori Elements App
Technical Articles
Bhavik Mehta
February 9, 2022
| 16 minute read
Follow 0 2 1,716
Introduction:
Like
Many times while working with Transactional List Report Apps developed using SAP
Fiori Elements we might have requirements to get dynamic input from the end user ,
RSS Feed like providing a popup where user makes selection and then we need to take actions
accordingly.
In this blog we will see how to invoke API Actions using ABAP Programming model
for Fiori
Scenario:
Let us consider an e.g., of Sales Order processing, where the end user after entering
Item details needs an option to select additional Charges.
The additional charges could be combination of one or more of the below charges.
1. Freight Charges
2. Miscellaneous charges
3. Other Charges
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 1/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
So below screen shot shows that the user can enter Additional Charges from the
popup by pressing the Additional charges Button and in the backend, we need to add
these charges to the Total of gross amount for the item selected and the value
should be reflected in the front-end Fiori App.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 2/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
Implementation Steps:
We create Custom Sales header Table ZSOH, where we use SoKey which is 16-digit
GUID and primary Key for table. The same will be used to generate Draft key in Draft
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 3/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
Table.
@AbapCatalog.enhancementCategory : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
@AbapCatalog.foreignKey.screenCheck : false
soid : snwd_so_id;
bpid : snwd_partner_id;
include /bobf/s_lib_admin_data;
Next we create Item table ZSOI where we use SOITMKEY as 16 digit GUID and we
include fields to get product id , Gross Amount , Currency and Additional Charges as
shown below.
@AbapCatalog.enhancementCategory : #EXTENSIBLE_ANY
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #ALLOWED
@AbapCatalog.foreignKey.screenCheck : false
@AbapCatalog.foreignKey.screenCheck : false
sokey : snwd_node_key
soitm : snwd_so_item_pos;
product : snwd_product_id;
@Semantics.amount.currencyCode : 'zsoi.currencycode'
grossamount : snwd_ttl_gross_amount;
currencycode : snwd_curr_code;
quantity : int4;
@Semantics.amount.currencyCode : 'zsoi.currencycode'
addcharge : snwd_ttl_gross_amount;
include /bobf/s_lib_admin_data;
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 4/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
Step 2: Create Interface View for Header and Item Tables , also generate the BOPF
object and Draft table using @ObjectModel Annotation.
We Create ZI_SOH interface view to generate BOPF object and we also mark the
Create, Update and Delete Enabled as true. We define ZSOH_DRAFT as Draft Table.
Below is the code for the same
@AbapCatalog.sqlViewName: 'ZISOH'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@ObjectModel: {
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
draftEnabled: true,
modelCategory:#BUSINESS_OBJECT ,
semanticKey: ['Soid'],
compositionRoot: true,
transactionalProcessingEnabled: true,
writeDraftPersistence: 'ZSOH_DRAFT',
writeActivePersistence: 'ZSOH',
entityChangeStateId: 'Lchg_Date_Time'
@ObjectModel.readOnly: true
@Search.defaultSearchElement: true
soh.soid as Soid,
@ObjectModel.foreignKey.association: '_bpa'
soh.bpid as Bpid,
@Semantics.systemDateTime.createdAt: true
soh.crea_date_time as Crea_Date_Time,
@Semantics.user.createdBy: true
soh.crea_uname as Crea_Uname,
@Semantics.systemDateTime.lastChangedAt: true
soh.lchg_date_time as Lchg_Date_Time,
@Semantics.user.lastChangedBy: true
soh.lchg_uname as Lchg_Uname,
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_itm
Similarly we create Item Interface view as shown below and use ZSOI_DRAFT as
draft table
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 5/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
@AbapCatalog.sqlViewName: 'ZISOI'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@ObjectModel: {
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
semanticKey: ['Sokey','Soitm'],
writeDraftPersistence: 'ZSOI_DRAFT',
writeActivePersistence: 'ZSOI'
soi.sokey as Sokey,
@ObjectModel.readOnly: true
soi.soitm as Soitm,
@ObjectModel.foreignKey.association: '_pd'
soi.product as Product,
@ObjectModel.readOnly: true
@Semantics.amount.currencyCode: 'Currencycode'
soi.grossamount as Grossamount,
@ObjectModel.foreignKey.association: '_curr'
@Semantics.currencyCode: true
soi.currencycode as Currencycode,
soi.quantity as Quantity,
@Semantics.amount.currencyCode: 'Currencycode'
@ObjectModel.readOnly: true
soi.addcharge as AddCharge,
@ObjectModel.association.type: [#TO_COMPOSITION_PARENT,#TO_COMPOSITION
_soh,
_pd,
_curr
We get the BOPF generated below is the screen shot for the same with Parent Child
Relationship.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 6/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
We Create 2 Consumption CDS view ZC_SOH and ZC_SOI and use UI annotations so
that it will create all the required controls in fiori elements app.
@AbapCatalog.sqlViewName: 'ZCSOH'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@ObjectModel: {
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
draftEnabled: true,
semanticKey: ['Soid'],
compositionRoot: true,
transactionalProcessingDelegated: true
@UI.headerInfo: {
title: {
type: #STANDARD,
value: 'Bpid'
},
description: {
type: #STANDARD,
value: 'Soid'
@VDM.viewType: #CONSUMPTION
@OData.publish: true
@UI.facet: [
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 7/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
id: 'Hdr',
purpose: #HEADER,
position: 10,
type: #FIELDGROUP_REFERENCE,
targetQualifier: 'HdrInfo'
},
id: 'SoHdr',
purpose: #STANDARD,
position: 10,
type: #IDENTIFICATION_REFERENCE
},
id: 'SoItm',
purpose: #STANDARD,
position: 20,
type: #LINEITEM_REFERENCE,
targetElement: '_itm'
}]
@UI.hidden: true
key Sokey,
@UI: {
identification:[ { position: 10 } ]
@ObjectModel.readOnly: true
Soid,
@UI: {
Bpid,
Crea_Date_Time,
Crea_Uname,
Lchg_Date_Time,
Lchg_Uname,
/* Associations */
@ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
_itm,
_bpa
@AbapCatalog.sqlViewName: 'ZCSOI'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 8/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
@AccessControl.authorizationCheck: #CHECK
@ObjectModel:
createEnabled: true,
updateEnabled: true,
deleteEnabled: true,
@UI: {
headerInfo: {
on $projection.Sokey = _soh.Sokey
on $projection.Product = _pd.Product
on $projection.Currencycode = _curr.Currency
@UI.facet: [{
id: 'Item',
purpose: #STANDARD,
position: 10,
type: #IDENTIFICATION_REFERENCE
},
id: 'IHdr',
purpose: #HEADER,
position: 10,
type: #FIELDGROUP_REFERENCE,
targetQualifier: 'IHdrItm'
}]
@UI.hidden: true
@UI.hidden: true
soi.Sokey as Sokey,
@UI.identification: [{position: 10 }]
@ObjectModel.readOnly: true
soi.Soitm as Soitm,
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 9/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
@ObjectModel.foreignKey.association: '_pd'
soi.Product as Product,
@ObjectModel.readOnly: true
@Semantics.amount.currencyCode: 'Currencycode'
soi.Grossamount as Grossamount,
@ObjectModel.foreignKey.association: '_curr'
@Semantics.currencyCode: true
soi.Currencycode as Currencycode,
soi.Quantity as Quantity,
soi.AddCharge,
/* Associations */
_curr,
_pd,
@ObjectModel.association.type: [#TO_COMPOSITION_PARENT,#TO_COMPOSITION
_soh
This Determination will generate Sales Order number for create Scenario. Below is
the code.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 10/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
public
final
create public .
public section.
methods /BOBF/IF_FRW_DETERMINATION~EXECUTE
redefinition .
protected section.
private section.
ENDCLASS.
method /BOBF/IF_FRW_DETERMINATION~EXECUTE.
EXPORTING
iv_node = is_ctx-node_key
it_key = it_key
IMPORTING
et_data = itab.
IF lr_tab->soid IS INITIAL.
EXPORTING
nr_range_nr = '01'
object = 'RV_BELEG'
IMPORTING
number = lr_tab->soid
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 7
OTHERS = 8.
IF sy-subrc <> 0.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 11/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
ENDIF.
EXPORTING
iv_node = is_ctx-node_key
iv_key = lr_tab->key
is_data = lr_tab
it_changed_fields =
VALUE #( ( ZIF_I_SOH_C=>sc_node_attribute-zi_soh-soid ) )
* CATCH /bobf/cx_frw_contrct_violation.
ENDIF.
ENDLOOP.
endmethod.
ENDCLASS.
We now implement code to generate item number and also, we implement code to
set the gross item = product price * Quantity entered by the user.
PUBLIC
FINAL
CREATE PUBLIC .
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 12/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
PUBLIC SECTION.
METHODS /bobf/if_frw_determination~execute
REDEFINITION .
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
METHOD /bobf/if_frw_determination~execute.
DATA:
EXPORTING
iv_node = is_ctx-node_key
it_key = it_key
IMPORTING
et_data = itab.
* Get the parent node to get the sales order number because Item does
IF sy-subrc = 0.
EXPORTING
iv_node = zif_i_soh_c=>sc_node-zi_soi
it_key = it_key
iv_association = zif_i_soh_c=>sc_association-zi_soi-to_
iv_fill_data = abap_true
IMPORTING
et_data = itab1
et_target_key = li_key .
SELECT SINGLE sokey FROM zsoh INTO @DATA(lv_sokey) WHERE soid = @lw_
IF sy-subrc <> 0.
SELECT SINGLE sokey FROM ZSOH_draft INTO lv_sokey WHERE soid = lw_
ENDIF.
UNION ALL
SELECT SINGLE
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 13/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
FROM +both
INTO @DATA(lv_max_salesorderitem).
IF lv_max_salesorderitem IS INITIAL.
lv_max_salesorderitem = '0000000000'.
ENDIF.
ENDIF.
IF lr_tab->soitm IS INITIAL.
ENDIF.
ENDIF.
EXPORTING
iv_node = is_ctx-node_key
iv_key = lr_tab->key
* iv_root_key =
is_data = lr_tab
it_changed_fields =
VALUE #( ( zif_i_soh_c=>sc_node_attribute-zi_soi-soitm )
( zif_i_soh_c=>sc_node_attribute-zi_soi-grossamount
( zif_i_soh_c=>sc_node_attribute-zi_soi-currencycode
* CATCH /bobf/cx_frw_contrct_violation.
ENDLOOP.
ENDMETHOD.
ENDCLASS.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 14/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
1. Open VS Code and use command pallet to create Fiori Elements App
2. View->Command Pallet ->Open Template Wizard
3. Select Fiori Elements List Report Floor plan, select your S/4 HANA system and
give the Service name and project Details.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 15/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
In the next step we will add Additional Charges Button to allow users to enter
additional charges. In order to achieve the same we will be using Extension and Fiori
Free Style coding.
In order to get additional charges from the user we will perform below steps
Create Additional Charges Button we will use Guided Development tool to add
Custom button.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 16/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
We give below Details in step 1 and click on Insert Snippet Button so that it creates
ObjectPageExt.controller
In Step 2 we give below Details and click on Insert Snippet , so that we get the details
updated in Manifest JSON.
Action ID idGetAddChrg
Step 7: Create Fragment which we will invoke it from the Extension Function.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 18/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
<Column width="12em">
</Column>
</Column>
</Column>
</columns>
<items>
<ColumnListItem vAlign="Middle">
<cells>
<Text text="{Charge>ChargeType}"/>
<Input value="{Charge>Amount}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</VBox>
</content>
<buttons>
</Dialog>
</core:FragmentDefinition>
onInit Method: In this method we define the JSON Model “Charge” which will have 2
fields Charge Type and Amount.Since we have 3 types of Charges we will define
Freight Charge, Miscellaneous Charge and Other Charge.Amount would be 0 we will
bind fill it from Popup Table. Below is the Code for the same
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 19/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
In the Pop up we had 2 Fragment we have 2 Buttons Copy and Cancel , when the user
clicks Cancel we should come out of the popup and do nothing so below is the code
to trigger
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 20/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
When the user clicks on Copy, we need to get the details of charges entered by the
user and then we need to invoke the BOPF Action from backend , we will come back
to this later once we finish the next step of creating Static Action.
We will create Static Action in BOPF to get the Additional Charges modify the
Additional charges amount. We will do below Steps. We create static action in the
Item node in BOPF as shown below
We then define the structure for ZADD_CHRG in SAP , this will have 2 parameters
Draft ID and Total Coming from Front end system.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 21/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
public
final
create public .
public section.
methods /BOBF/IF_FRW_ACTION~EXECUTE
redefinition .
protected section.
private section.
ENDCLASS.
method /BOBF/IF_FRW_ACTION~EXECUTE.
ls_key-key = ls_parameters-draftuuid.
EXPORTING
iv_node = ZIF_I_SOH_C=>sc_node-zi_soi
it_key = lt_key
IMPORTING
et_data = itab.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 22/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
EXPORTING
iv_node = ZIF_I_SOH_C=>sc_node-zi_soi
iv_key = lr_tab->key
is_data = lr_tab
it_changed_fields =
VALUE #( ( ZIF_I_SOH_C=>sc_node_attribute-zi_soi-grossamount
( ZIF_I_SOH_C=>sc_node_attribute-zi_soi-addcharge )
( ZIF_I_SOH_C=>sc_node_attribute-zi_soi-currencycode
ev_static_action_failed = abap_false.
ENDLOOP.
endmethod.
ENDCLASS.
We will now implement the final changes in fiori app to trigger the backend static
action ZC_SOISet_add_chrg for this we will use Invoke API.
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 23/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
sap.ui.controller("fe.so.fesaleorder.ext.controller.ObjectPageExt", {
onInit: function () {
"ExtraChrg": []
});
var oCharges = {
"ChargeType": "Freight",
"Amount": 0,
};
oExtraChrg.push(JSON.parse(JSON.stringify(oCharges)));
oExtraChrg.push(JSON.parse(JSON.stringify(oCharges)));
oExtraChrg.push(JSON.parse(JSON.stringify(oCharges)));
this.getOwnerComponent().setModel(oJson, "Charge");
this.getOwnerComponent().getModel("Charge").setProperty("/Ext
},
debugger;
this._oTable = this.getView().byId(oEvent.getSource().getPare
this._oDetails = this.getView().getModel().getProperty(this._o
var u = oEvent.getSource().getModel("ui").getData();
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 24/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
if (!this._DialogGenerate) {
this._DialogGenerate = sap.ui.xmlfragment("fe.so.fesa
this.getView().addDependent(this._DialogGenerate);
this._DialogGenerate.open();
} else {
// var i = this._oResourceBundle.getText('@copyInfo');
},
onActionCancel: function () {
this._DialogGenerate.close();
this._DialogGenerate.destroy();
this.getView().removeDependent(this._DialogGenerate);
this._DialogGenerate = null;
},
var oPromise;
"Draftuuid": this._oDetails.Soitmkey,
"Amount": oTot,
"Currency" : 'EUR'
};
oPromise = this.extensionAPI.invokeActions("ZC_SOH_CDS.ZC_SOH_
oParameter);
oPromise.then(function (r) {
});
oPromise.catch(function (r) {
var E = jQuery.parseJSON(r[0].error.response.responseText
sap.m.MessageBox.error(E.error.message.value);
});
this.onActionCancel();
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 25/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
});
We create item
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 26/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
Conclusion:
Annexure:
Please Refer to below link in order to understand ABAP Programming model for Fiori.
About ABAP Programming Model for SAP Fiori – SAP Help Portal
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 27/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
Navigating the BOPF: Part 3 – Working with the BOPF API | SAP Blogs
Navigating the BOPF: Part 4 – Advanced BOPF API Features | SAP Blogs
Please share your thoughts and views after trying the same.
Thanks!!
Alert Moderator
Assigned Tags
SAP Fiori
SAPUI5
#vscode
SAP Fiori tools is generally available. Increase the efficiency of developing SAP Fiori elements apps
By
Peter Spielvogel Jun 22, 2020
Related Questions
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 28/29
31/10/2022 19:57 Invoking Static BOPF Action From Custom Pop up in Fiori Elements App | SAP Blogs
Unable to Create Purchase Order with custom fields in Manage PO fiori s4hana
By
soumya r Aug 05, 2021
Find us on
Newsletter Support
https://blogs.sap.com/2022/02/09/invoking-static-bopf-action-from-custom-pop-up-in-fiori-elements-app/ 29/29