Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
deepika_chandrasekar
Active Contributor

Summary:

How to give data loss popup when navigating from custom component to other components or documents using Quick links or Navigation bar links when used in WEBUI

This document will be helpful when we are using custom component in WEBUI as standalone component

Step1:In custom component mainwindow IMPL class we have add one interface IF_BSP_WD_EVENT_HANDLER under interface

Step2:We have to create one method for data loss poupup and register it for data loss in methods

After this keep cursor on the method and click Detail View (highlighted) and give below details in the screenshot

Here we have to code for triggering the data loss popup. Put logic whether data entered or modified in the component and raise popup


IF gv_update EQ abap_true.

    data_loss_handler->set_save_handler( me ).
    data_loss_handler->set_revert_handler( me ).
    data_loss_handler->set_cancel_handler( me ).

    data_loss_handler->trigger_data_loss_handling( ).
  ENDIF.

Step3:Activate Data loss popup Event Handler

We have to activate data loss popup event in method DO_VIEW_INIT_ON_ACTIVATION

Here we have to put code to activate data loss popup event

CALL METHOD SUPER->DO_VIEW_INIT_ON_ACTIVATION.

* Enable Data Loss Popup

  SET HANDLER on_before_wa_content_change ACTIVATION abap_true.

Step4:Deactivating data loss popup event handler

Here in method DO_CLEANUP_CONTEXT

Here put code to deactivate event handler

CALL METHOD super->do_cleanup_context
    .

  SET HANDLER on_before_wa_content_change ACTIVATION abap_false.

Step5:Add attributes

Under Attributes add two attributes DATA_LOSS_TRIGGER_VIEW and DATA_LOSS_TRIGGER_EVENT

Step6:In WIndow IMPL class we will have method IF_BSP_WD_EVENT_HANDLER~HANDLE_EVENT under methods

Here we have to code for data loss popup buttons. Here you will have the user option whether save or cancel

When user clicked yes you have to put logic to update your custom table with the details entered in custom component view

CASE iv_event_name.
    WHEN if_bsp_wd_data_loss_handler=>save_event.
      rv_success = abap_true.

      lr_core ?= cl_crm_bol_core=>get_instance( ).
      lr_msg_srv ?= lr_core->get_global_message_cont( ).
      lr_coco ?= me->comp_controller.
      lr_col ?= lr_coco->typed_context->data->collection_wrapper.


      lr_entity ?= lr_col->get_first( ).

      WHILE lr_entity IS BOUND.

        CALL METHOD lr_entity->get_properties
          IMPORTING
            es_attributes = lwa_data.

          APPEND lwa_data TO li_data.
          CLEAR lwa_emp_org.
      
        lr_entity ?= lr_col->get_next( ).

      ENDWHILE.


      MODIFY Ztable FROM TABLE li_data.
      IF sy-subrc = 0.
        COMMIT WORK.
      ENDIF.
      CLEAR:gv_update.
      lr_msg_srv->add_message( iv_msg_id = 'ZCRM_MESS' iv_msg_type = 'S' iv_msg_number = '031' iv_show_only_once = 'X').
      CLEAR me->data_loss_trigger_view.
      CLEAR me->data_loss_trigger_event.
    WHEN if_bsp_wd_data_loss_handler=>revert_event.
      rv_success = abap_true.
      CLEAR me->data_loss_trigger_view.
      CLEAR me->data_loss_trigger_event.
    WHEN if_bsp_wd_data_loss_handler=>cancel_event.
      rv_success = abap_false.
**      RETURN.
      CLEAR me->data_loss_trigger_view.
      CLEAR me->data_loss_trigger_event.
    WHEN OTHERS.

  ENDCASE.


This Popup will be called when user navigates out of component without saving the data.

Regards,

Deepika.

1 Comment
Labels in this area