ABAP Programming Model for SAP Fiori – 15 : Automatic Popup Confirmation for Custom Actions using ABAP Programming Model in S/4HANA

0
5160
ABAP Programming Model for S/4HANA

In various business scenarios, we would need to create a custom button in the action toolbar in the list report FIORI apps. There would be different business cases for use of these custom actions. In this article, I would explain the technical steps involved in BOPF, CDS annotations and annotation model in the generated Fiori apps to achieve automatic pop-up confirmation box without any App extension.

Prerequisites:

  • Good knowledge of ABAP Programming Model
  • Good and hand-on knowledge in ABAP OOPS.
  • BOPF and basic understanding of SAPUI5 Annotation Model

Business Scenario:

  • With custom actions “Set Active” and “Set Inactive”, there should be a pop-up confirmation if user really wants to change the status to active or inactive respectively.

Expected Output:

A pop-up confirmation when user wants to change the status to “Inactive” of the selected context.

Implementation Steps:

Step 1. Create a new custom action in relevant business Object

Step 2. Implement execute method in action implementing class ZCL_I_A_INACTIVE_PROCEDURE as:

METHOD /bobf/if_frw_action~execute.

    " Typed with node's combined table type
    DATA(lt_context_data) = VALUE ztifscm_dunn_proc( ).

    " READING BO data ----------------------------------------------

    " Retrieve the data of the requested node instance
    io_read->retrieve(
      EXPORTING
        iv_node         = is_ctx-node_key
        it_key          = it_key
      IMPORTING
        et_data         = lt_context_data
    ).

    " WRITING BO data ---------------------------------------------

    LOOP AT lt_context_data ASSIGNING FIELD-SYMBOL().

      " Set the status as Inactive if its Active
      IF -x_active IS NOT INITIAL.
        -x_active = ' '.  " Inactive Dunning Procedure


        " Update the changed data  of the node instance
        io_modify->update(
          EXPORTING
            iv_node               = is_ctx-node_key
            iv_key                = -key
            iv_root_key           = -root_key
            is_data               = REF #( -node_data )
            it_changed_fields     = VALUE #(
              ( zif_i_fscm_dunn_proc_c=>sc_node_attribute-zi_fscm_dunn_proc-x_active )
            )
          ).
      ENDIF.
    ENDLOOP.

  ENDMETHOD.

Step 3. Add this action in LineItem annotation in CDS view as :

  @UI:{
     lineItem: [{position: 20,importance: #HIGH },
                        { type: #FOR_ACTION, dataAction: 'BOPF:ACTIVE_PROCEDURE', label: 'Set Active', position: 1 },
                        { type: #FOR_ACTION, dataAction: 'BOPF:INACTIVE_PROCEDURE', label: 'Set Inactive', position: 2 },
                        { type: #FOR_ACTION, dataAction: 'BOPF:SENDER_ID', label: 'Sender ID', position: 3 }                        
     ]

Step 4. Now all back-end changes have been done and we can use this action in the FIORI app. To add an automatic pop-up confirmation, please go to web IDE , Open the annotation.xml file of the generated fiori app and add the following xml code:

It’s called Critical Action annotation. Let’s understand the above annotation.

The target property of this OData annotation points to the function import which is the OData representation of the BOPF action. The target is divided into three parts which contain the service name, the entity container separated with a dot and the function import name separated with a slash.

Normally, Entity container is always build as {OData Service}_Entities and Function Import name would be {EntitySet}{BOPF action} but we can also find these objects from “Annotation Modeler” option in Annotation file as:

We can select the Entity containers/Function Imports/Entity Sets etc from the target selection

Please note that Function Import, Entity Containers and Entity Sets are always case sensitive so It’s better to check from target.

Now, all the required changes have been done and once we test the Fiori app, system would generate a pop-up confirmation with a pre-filled text: “Do you really want to execute the action Set Inactive?”

Please follow our LinkedIn Page, LinkedIn Group, Facebook Page, Twitter and Instagram.

Save our number +1-646-727-9273 and send us a Whatsapp message ‘LEARN’ to be part of our Learning Community.

Also, Check ABAP Programming for SAP Fiori Tutorials

LEAVE A REPLY

Please enter your comment!
Please enter your name here