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!
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Creating the new button involves the following four steps:

  1. 1. Enhance the component and view

  2. 2. Create a method to create the button

  3. 3. Call the new method from the do_prepare_output

  4. 4. Implement the event to be triggered when the button is clicked

  5. 1. Enhancing the component and view
    First enhance the component and enhance the view. How to enhance a component and a view can be found here.

2. Creating the method to create the button
In the workbench, navigate to the implementation class of the view. The implementation class is located directly under the view controller. The implementation class typically ends with '_IMPL'.

Double click on this Z-class. If the class does not start with a Z, you have either not enhanced the view yet, or you should go one screen back and re-open the component in the workbench.

In the attributes tab, create a new attribute called GT_BUTTONS (Instance Attribute, Public) of type CRMT_THTMLB_BUTTON_T

In the Methods tab, create a new method called 'CREATE_TOOLBAR' or 'CREATE_BUTTONS' (Instance Method, Private).

In the Method, add the following code:


  DATA: ls_button     TYPE crmt_thtmlb_button.
CLEAR gt_button.
ls_button-type     = cl_thtmlb_util=>gc_icon_add
ls_button-text     =
ls_button-on_click = [name of the event].
ls_button-enabled  = [abap_true|abap_false].
ls_button-id       = [ID].
APPEND ls_button TO gt_buttons.
CLEAR ls_button.

One of the variables is the name of the event. You can name this event anything you like. For instance 'create_line' or 'edit_line'. The implementation of the event will be done in step four.

The following attributes are available to buttons, and can be set:

Identifies the button at runtime
This is the text as displayed on the button -Keep it short!-
This is the text that shows when the mouse hovers over the button
This is the event that is raised when clicking the button
If this is set to false, the button is greyed out, and cannot be clicked.
This can be used to refer to an externally located gif image, i.e. '/sap/bc/bsp/...../w_pdf__s.gif',
This is used to add standard icons to the button. The available set can be found in cl_thtmlb_util, in the attributes tab.

3. Redefine the do_prepare_output to call the method as defined in step 2.

In the view, navigate to the Request Processing, and redefine the method do_prepare_output.
How to redefine a method can be found here.
In this method, call the newly created method to create the toolbar buttons.
This would be a statement like
create_toolbar( ) or create_buttons( ).

4. Create the event to be raised when clicking the button

'Event Handler'. Right click on it, and click on 'create'. Create an event with the exact name as coded in step 2.

The system will now create a method within the event handler called 'EH_ON[event_name]'. Double click this event to enter the logic to be performed when clicking the button.

Having the button switch between edit and change mode.
me->view_group_context->set_view_editable( me ).

Call a transaction launcher transaction.
In order to navigate to a screen or launch transaction in the coding, you should customize a 'Generic OP Mapping' in the nav bar profile.

SAP IMG -->  Customer Relationship Management --> UI Framework --> Technical Role Definition --> Define Navigation Bar Profile.

Within the nav bar customizing transaction, Select the correct profile, and double click on 'Define Generic OP Mapping' on the left side of the screen.

Add a line to the table where you map the new object name to an existing logical link. You can use this object name in the coding to call the logical link. The action should be the same as the action as customized in the OP Mapping.

DATA: lr_col            TYPE REF TO cl_crm_bol_bo_col.
DATA: lr_nav_descr TYPE REF TO if_bol_bo_property_access.

lr_nav_descr = cl_crm_ui_descriptor_obj_srv=>create_ui_object_based(
  iv_ui_object_type   =
[name of the object type]
  iv_ui_object_action =
'D' ).

insert( iv_bo    = lr_nav_descr
  iv_index =
1 ).

op_tobt( iv_data_collection = lr_col ).


If you do this, you should also implement the outbound plug op_tobt.
This outbound plug contains the following coding:

TYPE REF TO cl_bsp_wd_window.

lr_window = me->view_manager->get_window_controller( ).
lr_window->call_outbound_plug( iv_outbound_plug   =
  iv_data_collection = iv_data_collection ).