CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Applies to: SAP CRM 7.0

Author: Shikha Gupta

Company: Accenture Services Pvt. Ltd.

Created on: 29th October 2013

Author Bio: Shikha is a Software Engineer Analyst in Accenture Services Private Limited. She has been involved in SAP CRM-ABAP and SAP ABAP Projects.

Business Scenario:
Business Design for comments assignment block using transactions to maintain comments for memberships and members. This enhancement deals with creation and deletion of comments on members. As per the requirement when the comments are created for member through supervisor approval or directly to member, the system should create a Business transaction Z004 – Comment: Member or business activity and it should get updated in the note type.
In a similar way for membership: Transaction type Z001: Comment Membership should be created and the comment should get updated in the note type.
There is also a requirement to implement toggle functionality to “Display Deleted comments” and “Hide deleted Comments”.
Overview:
Create a Z-Component ZCCRMLOY_COMENT for displaying comments in custom assignment block- Comments assignment block

Addition of a new comment
On clicking on “New” below code is done on an event handler EH_ONNEW which opens a pop up to add a new comment.
method EH_ONNEW.

  DATA: LR_CUCO TYPE REF TO ZL_ZCCRMLOY_COMMENTCUCO_IMPL ,
        lo_msg_srv     TYPE REF TO cl_bsp_wd_message_service,
        lw_warehouse  TYPE zscrmloy_warehouse_details,
        lv_enable        TYPE ze_enable.

  CONSTANTS: lc_msg_id          TYPE symsgid              VALUE                 'ZCRM_LOYMGMT',
             lc_error           TYPE c                    VALUE 'E'.

  lo_msg_srv = me->view_manager->get_message_service( ).
  zcl_crm_loy_utilities=>get_warehouse_details( EXPORTING i_user = sy-uname
                                             IMPORTING e_warehouse_detail = lw_warehouse ).
* Throw error if warehouse is not maintained.
  IF lw_warehouse-warehouse_no IS INITIAL.
    me->gv_warehouse = abap_false.
    lo_msg_srv->add_message(
    iv_msg_type   = lc_error
    iv_msg_id     = lc_msg_id
    iv_msg_number = '120'
    ).
    RETURN.
  ENDIF.
  CLEAR zl_zccrmloy_zmuladdr_impl=>gv_flg.

  lr_cuco ?= get_custom_controller( 'GLOBAL.ZCCRMLOY_COMENT/CommentCuCo' ).
  lr_cuco->GV_BUTTON_NEW = ABAP_TRUE.

  GO_POP_UP  = comp_controller->window_manager->create_popup(
                               iv_interface_view_name = 'ZCCRMLOY_COMENT/EditWindow'
                               iv_usage_name = 'ZCU_EDITWIND'
                               iv_title =   'Comments' ).
*Open the pop up
  GO_POP_UP->set_on_close_event( iv_event_name = 'POPUP_CLOSED' iv_view = me ).

  GO_POP_UP->set_window_height( '250' ).
  go_pop_up->set_display_mode( if_bsp_wd_popup=>c_display_mode_surrounded ).
  GO_POP_UP->open( ).

endmethod.


On closing the pop up, “Close” event is triggered which creates a business activity for this transaction and update the standard note type with the relevant text and at the same time also update the change history with the created entry.
METHOD eh_onpopup_closed.

  TYPES: BEGIN        OF ty_partner_det,
         partner      TYPE bu_partner,
         type         TYPE bu_type,
         name_org1    TYPE bu_nameor1,
         name_org2    TYPE bu_nameor2,
         name_last    TYPE bu_namep_l,
         name_first   TYPE bu_namep_f,
         partner_guid TYPE bu_partner_guid,
         END          OF ty_partner_det.

  DATA: lo_entity_save      TYPE REF TO if_bol_bo_property_access,
        lo_cuco             TYPE REF TO zl_zccrmloy_commentcuco_impl,
        lv_bp               TYPE bu_partner,
        lv_description      TYPE string,
        lo_cuco_bp_head     TYPE REF TO zl_zbp_head_zcomments_impl ,
        lv_comments         TYPE string,
        lv_name             TYPE char80,
        lw_warehouse_detail TYPE zscrmloy_warehouse_details,
        lw_comments         TYPE ztcrmloy_coment,
        lw_partner_det      TYPE ty_partner_det,
        lo_comment_col      TYPE REF TO if_bol_bo_col,
        lo_val_node         TYPE REF TO cl_bsp_wd_value_node,
        lv_struct_ref       TYPE REF TO ztcrmloy_coment,
        lw_comment          TYPE ztcrmloy_coment,
        lv_objid            TYPE cdhdr-objectid,
        lt_text             TYPE STANDARD TABLE OF cdtxt.

  CONSTANTS: lc_comp        TYPE char10 VALUE 'COMPLETED',
             lc_space       TYPE char1  VALUE ' ',
             lc_one         TYPE char1  VALUE '1',
             lc_two         TYPE char1  VALUE '2',
             lc_chn_his     TYPE char1  VALUE 'S'.

CALL METHOD zcl_crm_loy_utilities=>get_warehouse_details
    EXPORTING
      i_user             = sy-uname
    IMPORTING
      e_warehouse_detail = lw_warehouse_detail.

  lo_cuco_bp_head ?= get_custom_controller( 'GLOBAL.ZBP_HEAD/ZCOMMENTS' ).
  lv_bp = lo_cuco_bp_head->gv_bp_no.

  IF lv_bp IS NOT INITIAL.

    lo_cuco ?= get_custom_controller( 'GLOBAL.ZCCRMLOY_COMENT/CommentCuCo' ).
    IF lo_cuco->go_entity_save IS BOUND.

      lo_cuco->GV_BUTTON_NEW = abap_false.
      lo_entity_save = lo_cuco->go_entity_save.
      CLEAR lo_cuco->go_entity_save.

      lv_description = lo_entity_save->get_property_as_string( iv_attr_name = 'ZDESCRIPTION' ).
      lv_comments = lo_entity_save->get_property_as_string( iv_attr_name = 'ZCOMMENTS' ).

      SELECT SINGLE partner type name_org1 name_org2 name_last name_first partner_guid FROM    but000 INTO lw_partner_det WHERE partner = lv_bp.

         lo_cuco->create_member_docflow( EXPORTING iv_member = lv_bp
                                            iv_comment = lv_comments
                                            iv_description = lv_description ).

* Add Change pointers
      lv_objid = lv_bp.
      CALL FUNCTION 'ZCOMMENT_OBJECT_WRITE_DOCUMENT'
        EXPORTING
          objectid                   = lv_objid
          tcode                      = ' '
          utime                      = sy-uzeit
          udate                      = sy-datum
          username                   = sy-uname
          object_change_indicator    = ' '
          upd_icdtxt_zcomment_object = 'I'
          n_ztcrmloy_coment          = lw_comment
          o_ztcrmloy_coment          = lw_comment
          upd_ztcrmloy_coment        = 'I'
        TABLES
          icdtxt_zcomment_object     = lt_text.
    ENDIF.
  ENDIF.
ENDMETHOD.
Below is the method which is called above in the event handler. The purpose of this method is to create a document flow  by creating an order and updating the text of the comment for that particular partner.
METHOD create_member_docflow.

  DATA:
   lo_tx         TYPE REF TO if_bol_transaction_context,
   lo_factory    TYPE REF TO cl_crm_bol_entity_factory,
   lw_param      TYPE crmt_name_value_pair,
   lw_detail     TYPE zscrmloy_warehouse_details,
   lt_param      TYPE crmt_name_value_pair_tab,
   lo_result     TYPE REF TO if_bol_entity_col,
   lo_order      TYPE REF TO cl_crm_bol_entity,
   lo_core       TYPE REF TO cl_crm_bol_core,
   lo_admin      TYPE REF TO cl_crm_bol_entity,
   lo_activity   TYPE REF TO cl_crm_bol_entity,
   lo_text_set   TYPE REF TO cl_crm_bol_entity,
   lo_partnerset      TYPE REF TO cl_crm_bol_entity,
   lo_act_partner     TYPE REF TO cl_crm_bol_entity,
   lo_status_set      TYPE REF TO cl_crm_bol_entity,
   lo_status_current  TYPE REF TO cl_crm_bol_entity,
   lo_text       TYPE REF TO cl_crm_bol_entity.
   lv_partner          TYPE bu_partner,
   lv_object_id        TYPE crmt_object_id_db,
   lv_description      TYPE string,
   lw_partner_fct      TYPE crmst_partner_btil,
   lv_bp_number        TYPE bu_partner .
   lw_address TYPE bapibus1006_address.
 
CONSTANTS:
   lc_category  TYPE crmt_activity_category VALUE 'Z20',
   lc_process_type TYPE crmt_process_type_db VALUE 'Z004',
    lc_comments  TYPE char3 VALUE '014'.

* set process type
  lw_param-name = 'PROCESS_TYPE'.
  lw_param-value = lc_process_type.
  APPEND lw_param TO lt_param.

* Create Root Entity
  lo_core = cl_crm_bol_core=>get_instance( ).
  TRY.
      lo_factory = lo_core->get_entity_factory( 'BTOrder' ). "#EC NOTEXT
    CATCH cx_sy_ref_is_initial.
  ENDTRY.
  TRY.
      lo_order = lo_factory->create( lt_param ).
    CATCH cx_sy_ref_is_initial.
  ENDTRY.
  TRY.
      lo_tx ?= lo_order->get_transaction( ).
    CATCH cx_sy_ref_is_initial cx_sy_move_cast_error.
  ENDTRY.
  TRY.
      lo_admin = lo_order->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
    CATCH cx_sy_ref_is_initial cx_crm_genil_model_error . "#EC NO_HANDLER
  ENDTRY.
  IF lo_admin IS BOUND.
    lv_description = iv_description.
    lo_admin->set_property( iv_attr_name = 'DESCRIPTION'
                            iv_value     = lv_description ).
    CLEAR lv_description.
    IF lo_core IS BOUND.
      lo_core->modify( ).
    ENDIF.
  ENDIF.
  lo_partnerset = lo_admin->get_related_entity( iv_relation_name = 'BTHeaderPartnerSet'). "#EC NOTEXT
  IF lo_partnerset IS NOT BOUND.
    TRY.
        lo_partnerset = lo_admin->create_related_entity( iv_relation_name = 'BTHeaderPartnerSet'). "#EC NOTEXT
      CATCH cx_crm_genil_duplicate_rel cx_crm_genil_model_error. "#EC NO_HANDLER
    ENDTRY.
  ENDIF.
  IF lo_partnerset  IS BOUND.
    TRY.
        lo_act_partner = lo_partnerset->create_related_entity( iv_relation_name = 'BTPartner_PFT_0006_MAIN'). "#EC NOTEXT
      CATCH cx_crm_genil_duplicate_rel cx_crm_genil_model_error. "#EC NO_HANDLER
    ENDTRY.
  ENDIF.
  IF lo_act_partner IS BOUND.
    lw_partner_fct-partner_no    = iv_member.
    lo_act_partner->set_properties( is_attributes = lw_partner_fct ).
  ENDIF.
  TRY.
      lo_activity = lo_admin->get_related_entity( iv_relation_name = 'BTHeaderActivityExt' ).
    CATCH cx_sy_ref_is_initial cx_crm_genil_model_error . "#EC NO_HANDLER
  ENDTRY.
*--------------------------------------------------------------------------------------------------*
*set the location and category
  zcl_crm_loy_utilities=>get_warehouse_details( EXPORTING i_user = sy-uname
                                               IMPORTING e_warehouse_detail = lw_detail ).
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = lw_detail-warehouse_no
    IMPORTING
      output = lv_partner.

  IF lo_activity IS BOUND.
    lo_activity->set_property( iv_attr_name = 'ACT_LOCATION'
                               iv_value = lv_partner ).
*                               iv_value     = lv_description ).
    lo_activity->set_property( iv_attr_name = 'CATEGORY'
                               iv_value     = lc_category ).
    IF lo_core IS BOUND.
      lo_core->modify( ).
    ENDIF.
  ENDIF.
  TRY.
      lo_text_set = lo_admin->get_related_entity( iv_relation_name = 'BTHeaderTextSet' ).
    CATCH cx_sy_ref_is_initial cx_crm_genil_model_error . "#EC NO_HANDLER
  ENDTRY.
  TRY.
      lo_text = lo_text_set->get_related_entity( iv_relation_name = 'BTTextHFirstChangeable' ).
    CATCH cx_sy_ref_is_initial cx_crm_genil_model_error . "#EC NO_HANDLER
  ENDTRY.
*update the comments
  IF lo_text IS BOUND.
    lo_text->set_property( iv_attr_name = 'CONC_LINES'
                           iv_value     = iv_comment ).
    IF lo_core IS BOUND.
      lo_core->modify( ).
    ENDIF.
  ENDIF.
*Save the transaction
  IF lo_tx IS BOUND AND lo_tx->check_save_possible( )  EQ abap_true.
    IF lo_tx->save( ) EQ abap_true.
      lo_tx->commit( ).
      IF lo_admin IS BOUND.
        lo_admin->reread( ).
        TRY.
            lo_admin->if_bol_bo_property_access~get_property_as_value( EXPORTING iv_attr_name =   'OBJECT_ID'
                                                                       IMPORTING ev_result    = lv_object_id ).
          CATCH cx_crm_cic_parameter_error.
        ENDTRY.
      ENDIF.
    ELSE.
      lo_tx->revert( ).
    ENDIF.
  ENDIF.
ENDMETHOD.
Deletion of a comment
The logic for deletion of comments is mentioned below in the event handler ‘EH_ON_ONE_CLICK_ACTION’.  The deletion process works in two ways:
If the logged in user is a warehouse assistant then when comment is deleted on clicking “Trash can button “  it prompts for manager override and a manager override reason is filled in with manager credentials

It prompts for a pop up for manager approval.

If logged in user is other that warehouse assistant then the comment is deleted when the “Trashcan” button is clicked. .

METHOD eh_on_one_click_action.
  DATA:   lv_username          TYPE xubname,
          lv_event_id          TYPE ze_event_id,
          lv_title             TYPE string,
          lv_check             TYPE crm_boolean,
          lv_lock              TYPE crm_boolean,
          lv_enable            TYPE crm_boolean,
          lv_approval_req      TYPE crm_boolean,
          lv_guid              TYPE loy_frw_guid,
          lo_msg_srv           TYPE REF TO cl_bsp_wd_message_service,
          lo_tx                TYPE REF TO if_bol_transaction_context,
          lo_admin             TYPE REF TO cl_crm_bol_entity,
          lo_status_set        TYPE REF TO cl_crm_bol_entity,
          lo_factory           TYPE REF TO cl_crm_bol_entity_factory,
          lo_order             TYPE REF TO cl_crm_bol_entity,
          lw_param             TYPE crmt_name_value_pair,
          lo_dquery    TYPE REF TO cl_crm_bol_dquery_service,
          lv_proc_type TYPE string,
          lo_status_current    TYPE REF TO cl_crm_bol_entity,
          lo_result_col TYPE REF TO if_bol_entity_col,
          lo_result TYPE REF TO cl_crm_bol_entity,
          lo_core              TYPE REF TO cl_crm_bol_core,
          lt_param             TYPE crmt_name_value_pair_tab,
          lv_index             TYPE int4,
          lt_header_guid       TYPE crmt_object_guid_tab,
          lt_item_status       TYPE  crmt_status_wrkt,
          lw_item_status       TYPE  crmt_status_wrk,
          lt_requested_objects TYPE  crmt_object_name_tab,
          lo_current           TYPE REF TO if_bol_bo_property_access,
          lw_comment           TYPE ztcrmloy_coment,
          lo_cuco              TYPE REF TO zl_zccrmloy_commentcuco_impl,
          lw_comments          TYPE ztcrmloy_coment,
          lt_status            TYPE crmt_status_comt,
          lt_objects_to_save   TYPE crmt_object_guid_tab,
          lt_saved_objects     TYPE  crmt_return_objects,
          lt_exception         TYPE  crmt_exception_t,
          lt_objects_not_saved TYPE  crmt_object_guid_tab,
          lt_input_fields      TYPE crmt_input_field_tab,
          lw_input_fields      TYPE crmt_input_field,
          lt_field_names       TYPE crmt_input_field_names_tab,
          lw_field_names       TYPE crmt_input_field_names,
          lw_status            TYPE crmt_status_com,
          lv_objid             TYPE cdhdr-objectid,
          lv_object_id         TYPE crmt_object_id_db,
          lv_bp_number         TYPE bu_partner,
          lt_objects_to_delete TYPE crmt_object_guid_tab,
          lt_text              TYPE STANDARD TABLE OF cdtxt.
  DATA:
          lo_comp    TYPE REF TO zl_zccrmloy_bspwdcompone8_impl,
          lo_partner TYPE REF TO cl_crm_bol_entity.
  CONSTANTS:
               lc_msg_class     TYPE symsgid     VALUE 'ZCRM_LOYMGMT',     "Constant for Message class.
               lc_error         TYPE bapi_mtype  VALUE 'E',
               lc_msg_num       TYPE symsgno     VALUE '142',
               lc_fname  TYPE crmt_fieldname   VALUE 'ACTIVATE',
               lc_event_id      TYPE ze_event_id VALUE '18',
               lc_chn_his       TYPE char1       VALUE 'D',
               lc_item          TYPE crmt_object_kind VALUE 'A',
               lc_delete        TYPE char2 VALUE '03',
               lc_item_status   TYPE crmt_object_name VALUE 'STATUS',
               lc_proc          TYPE j_stsma VALUE 'ZINTLOG',
               lc_del           TYPE j_txt04 VALUE 'DELE',
               lc_status        TYPE j_estat VALUE 'E0003',
               lc_comments      TYPE char3 VALUE '014'.

  lo_cuco ?= get_custom_controller( 'GLOBAL.ZCCRMLOY_COMENT/CommentCuCo' ).
  lo_msg_srv = cl_bsp_wd_message_service=>get_instance( ).
  IF htmlb_event_ex IS BOUND.
    CALL METHOD cl_thtmlb_util=>get_event_info
      EXPORTING
        iv_event = htmlb_event_ex
      IMPORTING
        ev_index = lv_index.
    gv_selected = lv_index.
  ENDIF.
  lv_check = zcl_crm_loy_utilities=>user_role_check( lo_msg_srv ).
  IF lv_check = abap_false.
    EXIT.
  ENDIF.
  IF ( gv_approval_done IS INITIAL ) OR     "check whether the approval process is ran and status is success
     ( gv_app_status    IS INITIAL ).
    lv_username = sy-uname.
    lv_event_id = lc_event_id.
*call the static to check whether approval is needed for the user.
    CALL METHOD zcl_crm_loy_utilities=>check_approval
      EXPORTING
        iv_event_id     = lv_event_id
        iv_username     = lv_username
      RECEIVING
        rv_app_required = lv_approval_req.
    IF lv_approval_req = abap_true.  " approval required raise the pop up.
      CALL METHOD lo_msg_srv->add_message
        EXPORTING
          iv_msg_type   = lc_error
          iv_msg_id     = lc_msg_class
          iv_msg_number = lc_msg_num.
      TRY.
          lo_msg_srv->subscribe_message(
                           iv_message_class = lc_msg_class
                           iv_message_number = lc_msg_num
                           iv_subscriber = me
                           iv_activation = abap_true ).
        CATCH cx_bsp_wd_dupl_mess_subscr.
      ENDTRY.
    ELSE.
      IF lo_msg_srv IS BOUND.
        TRY.
            lo_msg_srv->subscribe_message(
                           iv_message_class = lc_msg_class
                           iv_message_number = lc_msg_num
                           iv_subscriber = me
                           iv_activation = abap_false ).
          CATCH cx_bsp_wd_dupl_mess_subscr.
        ENDTRY.
      ENDIF.
      IF htmlb_event_ex IS BOUND.
        CALL METHOD cl_thtmlb_util=>get_event_info
          EXPORTING
            iv_event = htmlb_event_ex
          IMPORTING
            ev_index = lv_index.
      ELSE.
        lv_index = gv_selected.
      ENDIF.
* get selected entity
      lo_current = me->typed_context->ztcomments->collection_wrapper->find( iv_index = lv_index ).
      IF lo_current IS BOUND.
        lo_current->get_properties( IMPORTING es_attributes = lw_comment ).
        lw_param-value = lw_comment-zbp_number.

        lo_core = cl_crm_bol_core=>get_instance( ).
        lo_dquery = cl_crm_bol_dquery_service=>get_instance( 'BTQ1Order' ).
        IF lo_dquery IS BOUND.
          CALL METHOD lo_dquery->add_selection_param
            EXPORTING
              iv_attr_name = 'BU_PARTNER'
              iv_sign      = 'I'
              iv_option    = 'EQ'
              iv_low       = lw_param-value.
          lo_result_col = lo_dquery->get_query_result( ).
          IF lo_result_col IS BOUND.
            lo_result = lo_result_col->get_first( ).
            WHILE lo_result IS BOUND.
              lo_result->get_property_as_value( EXPORTING iv_attr_name = 'GUID' IMPORTING ev_result = lv_guid ).
              IF lv_guid = lw_comment-order_id.
                TRY.
                    lo_admin = lo_result->get_related_entity( iv_relation_name = 'BTADVS1Ord' ).
                    lo_admin = lo_admin->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
                  CATCH cx_sy_ref_is_initial cx_crm_genil_model_error . "#EC NO_HANDLER
                ENDTRY.
                IF lo_admin IS BOUND.
                  TRY.
                      CALL METHOD lo_admin->get_related_entity
                        EXPORTING
                          iv_relation_name = 'BTHeaderStatusSet'
                        RECEIVING
                          rv_result        = lo_status_set.
                    CATCH cx_crm_genil_model_error .
                  ENDTRY.
                  IF lo_status_set IS NOT BOUND.
                    TRY.
                        CALL METHOD lo_admin->create_related_entity
                          EXPORTING
                            iv_relation_name = 'BTHeaderStatusSet'
                          RECEIVING
                            rv_result        = lo_status_set.
                      CATCH cx_crm_genil_duplicate_rel .
                      CATCH cx_crm_genil_model_error .
                    ENDTRY.
                    lo_core = cl_crm_bol_core=>get_instance( ).
                    IF lo_core IS BOUND.
                      lo_core->modify( ).
                    ENDIF.
                  ENDIF.
                  IF lo_status_set IS BOUND.
                    TRY.
                        CALL METHOD lo_status_set->get_related_entity
                          EXPORTING
                            iv_relation_name = 'BTStatusHCurrent'
                          RECEIVING
                            rv_result        = lo_status_current.
                      CATCH cx_crm_genil_model_error .
                    ENDTRY.
                    IF lo_status_current IS NOT BOUND.
                      TRY.
                          CALL METHOD lo_status_set->create_related_entity
                            EXPORTING
                              iv_relation_name = 'BTStatusHCurrent'
                            RECEIVING
                              rv_result        = lo_status_current.
                        CATCH cx_crm_genil_duplicate_rel .
                        CATCH cx_crm_genil_model_error .
                      ENDTRY.
                      lo_core = cl_crm_bol_core=>get_instance( ).
                      IF lo_core IS BOUND.
                        lo_core->modify( ).
                      ENDIF.
                    ENDIF.
                    IF lo_status_current IS BOUND.
                      lo_status_current->lock( RECEIVING rv_success = lv_check ).
                      lo_admin->lock( RECEIVING rv_success = lv_lock ).
                    ENDIF.
                    IF lv_check EQ abap_true AND lv_lock EQ abap_true.
                      lo_status_current->set_property( iv_attr_name = 'ACT_STATUS'
                                                       iv_value     = lc_status  ).

                      IF lo_core IS BOUND.
                        lo_core->modify( ).
                      ENDIF.
*Save the transaction
                      lo_tx ?= lo_status_current->get_transaction( ).
                      IF lo_tx IS BOUND AND lo_tx->check_save_possible( )  EQ abap_true.
                        IF lo_tx->save( ) EQ abap_true.
                          lo_tx->commit( ).
                        ENDIF.
                        EXIT.
                      ENDIF.
                    ENDIF.
                  ENDIF.
                ENDIF.
              ELSE.
                lo_result = lo_result_col->get_next( ).
              ENDIF.
            ENDWHILE.
          ENDIF.
        ENDIF.
* Add Change pointers
        lv_objid = lw_comment-zbp_number.
        CALL FUNCTION 'ZCOMMENT_OBJECT_WRITE_DOCUMENT'
          EXPORTING
            objectid                   = lv_objid
            tcode                      = ' '
            utime                      = sy-uzeit
            udate                      = sy-datum
            username                   = sy-uname
*           PLANNED_CHANGE_NUMBER      = ' '
            object_change_indicator    = ' '
*           PLANNED_OR_REAL_CHANGES    = ' '
*           NO_CHANGE_POINTERS         = ' '
            upd_icdtxt_zcomment_object = 'D'
            n_ztcrmloy_coment          = lw_comments
            o_ztcrmloy_coment          = lw_comments
            upd_ztcrmloy_coment        = 'D'
          TABLES
            icdtxt_zcomment_object     = lt_text.

        lo_cuco->gv_check_chn_his = lc_chn_his.
      ENDIF.

      CLEAR: gv_approval_done, gv_app_status.
    ENDIF.
  ELSE.
    IF lo_msg_srv IS BOUND.
      TRY.
          lo_msg_srv->subscribe_message(
                         iv_message_class = lc_msg_class
                         iv_message_number = lc_msg_num
                         iv_subscriber = me
                         iv_activation = abap_false ).
        CATCH cx_bsp_wd_dupl_mess_subscr.
      ENDTRY.
    ENDIF.
    IF htmlb_event_ex IS BOUND.
      CALL METHOD cl_thtmlb_util=>get_event_info
        EXPORTING
          iv_event = htmlb_event_ex
        IMPORTING
          ev_index = lv_index.
    ELSE.
      lv_index = gv_selected.
    ENDIF.
    lo_current = me->typed_context->ztcomments->collection_wrapper->find( iv_index = lv_index ).
    IF lo_current IS BOUND.
      lo_current->get_properties( IMPORTING es_attributes = lw_comment ).

      lw_param-value = lw_comment-zbp_number.

      lo_core = cl_crm_bol_core=>get_instance( ).
      lo_dquery = cl_crm_bol_dquery_service=>get_instance( 'BTQ1Order' ).
      IF lo_dquery IS BOUND.
        CALL METHOD lo_dquery->add_selection_param
          EXPORTING
            iv_attr_name = 'BU_PARTNER'
            iv_sign      = 'I'
            iv_option    = 'EQ'
            iv_low       = lw_param-value.
        lo_result_col = lo_dquery->get_query_result( ).
        IF lo_result_col IS BOUND.
          lo_result = lo_result_col->get_first( ).
          WHILE lo_result IS BOUND.
            lo_result->get_property_as_value( EXPORTING iv_attr_name = 'GUID' IMPORTING ev_result = lv_guid ).
            IF lv_guid = lw_comment-order_id.
              TRY.
                  lo_admin = lo_result->get_related_entity( iv_relation_name = 'BTADVS1Ord' ).
                  lo_admin = lo_admin->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
                CATCH cx_sy_ref_is_initial cx_crm_genil_model_error . "#EC NO_HANDLER
              ENDTRY.
              IF lo_admin IS BOUND.
                TRY.
                    CALL METHOD lo_admin->get_related_entity
                      EXPORTING
                        iv_relation_name = 'BTHeaderStatusSet'
                      RECEIVING
                        rv_result        = lo_status_set.
                  CATCH cx_crm_genil_model_error .
                ENDTRY.
                IF lo_status_set IS NOT BOUND.
                  TRY.
                      CALL METHOD lo_admin->create_related_entity
                        EXPORTING
                          iv_relation_name = 'BTHeaderStatusSet'
                        RECEIVING
                          rv_result        = lo_status_set.
                    CATCH cx_crm_genil_duplicate_rel .
                    CATCH cx_crm_genil_model_error .
                  ENDTRY.
                  lo_core = cl_crm_bol_core=>get_instance( ).
                  IF lo_core IS BOUND.
                    lo_core->modify( ).
                  ENDIF.
                ENDIF.
                IF lo_status_set IS BOUND.
                  TRY.
                      CALL METHOD lo_status_set->get_related_entity
                        EXPORTING
                          iv_relation_name = 'BTStatusHCurrent'
                        RECEIVING
                          rv_result        = lo_status_current.
                    CATCH cx_crm_genil_model_error .
                  ENDTRY.
                  IF lo_status_current IS NOT BOUND.
                    TRY.
                        CALL METHOD lo_status_set->create_related_entity
                          EXPORTING
                            iv_relation_name = 'BTStatusHCurrent'
                          RECEIVING
                            rv_result        = lo_status_current.
                      CATCH cx_crm_genil_duplicate_rel .
                      CATCH cx_crm_genil_model_error .
                    ENDTRY.
                    lo_core = cl_crm_bol_core=>get_instance( ).
                    IF lo_core IS BOUND.
                      lo_core->modify( ).
                    ENDIF.
                  ENDIF.
                  IF lo_status_current IS BOUND.
                    lo_status_current->lock( RECEIVING rv_success = lv_check ).
                    lo_admin->lock( RECEIVING rv_success = lv_lock ).
                  ENDIF.
                  IF lv_check EQ abap_true AND lv_lock EQ abap_true.
                    lo_status_current->set_property( iv_attr_name = 'ACT_STATUS'
                                                     iv_value     = lc_status  ).

                    IF lo_core IS BOUND.
                      lo_core->modify( ).
                    ENDIF.
*Save the transaction
                    lo_tx ?= lo_status_current->get_transaction( ).
                    IF lo_tx IS BOUND AND lo_tx->check_save_possible( )  EQ abap_true.
                      IF lo_tx->save( ) EQ abap_true.
                        lo_tx->commit( ).
                      ENDIF.
                      EXIT.
                    ENDIF.
                  ENDIF.
                ENDIF.
              ENDIF.
            ELSE.
              lo_result = lo_result_col->get_next( ).
            ENDIF.
          ENDWHILE.
        ENDIF.
      ENDIF.
* Add Change pointers
      lv_objid = lw_comment-zbp_number.
      CALL FUNCTION 'ZCOMMENT_OBJECT_WRITE_DOCUMENT'
        EXPORTING
          objectid                   = lv_objid
          tcode                      = ' '
          utime                      = sy-uzeit
          udate                      = sy-datum
          username                   = sy-uname
*         PLANNED_CHANGE_NUMBER      = ' '
          object_change_indicator    = ' '
*         PLANNED_OR_REAL_CHANGES    = ' '
*         NO_CHANGE_POINTERS         = ' '
          upd_icdtxt_zcomment_object = 'D'
          n_ztcrmloy_coment          = lw_comments
          o_ztcrmloy_coment          = lw_comments
          upd_ztcrmloy_coment        = 'D'
        TABLES
          icdtxt_zcomment_object     = lt_text.

      lo_cuco->gv_check_chn_his = lc_chn_his.
    ENDIF.

    CLEAR: gv_approval_done, gv_app_status.
  ENDIF.
ENDMETHOD


Toggle functionality to view and hide deleted comments.

On clicking the “Display deleted comments” button all the deleted comments along with the manager override reason appears and the “Hide deleted comments” button is enabled.


      
METHOD do_prepare_output.

IF gv_show EQ abap_false.
      lw_button-on_click = 'SHOW'.
      IF sy-subrc IS INITIAL.
        lw_button-enabled  = abap_true.
      ELSE.
        lw_button-enabled = abap_false.
      ENDIF.
      lw_button-text     = text-003.
      IF gv_display EQ abap_true.
        APPEND lw_button TO gt_button.
      ENDIF.
      CLEAR lw_button.
*If display deleted comments is selected on the screen then enable the button hide deleted comemnts
    ELSEIF gv_show EQ abap_true.
      lw_button-on_click = 'HIDE'.
      lw_button-enabled  = abap_true.
      lw_button-text     = text-004.
      IF gv_display EQ abap_true.
        APPEND lw_button TO gt_button.
      ENDIF.
      CLEAR lw_button.
ENDIF.

1 Comment