Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ALV tree get selected checkbox

Hi

I have an ALV report which uses cl_gui_alv_tree as display control.

In this report some items in hierarchy are marked as checkboxes with following code:

ls_item_layout-fieldname = '&Hierarchy'.

ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.

ls_item_layout-editable = 'X'.

APPEND ls_item_layout TO lt_item_layout.

CALL METHOD g_alv_tree->add_node

EXPORTING

i_relat_node_key = p_node_key2

i_relationship = cl_gui_column_tree=>relat_last_child

i_node_text = lv_node_text

is_outtab_line = ls_data

it_item_layout = lt_item_layout.

They apear in report as checkboxes but I cannot get their values in PAI module.

I need this to perform some operations after user clicks a button on application toolbar.

When I call method

CALL METHOD g_alv_tree->GET_CHECKED_ITEMS

IMPORTING ET_CHECKED_ITEMS = lt_nodes.

it returns an empty table even if some of items were checked.

Tags:
Former Member
Former Member replied

Hi Tomasz,

Please check whether you register the events or not.

  * define the events which will be passed to the backend
  DATA: LT_EVENTS TYPE CNTL_SIMPLE_EVENTS,
        L_EVENT TYPE CNTL_SIMPLE_EVENT.

* define the events which will be passed to the backend
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_EXPAND_NO_CHILDREN.
  APPEND L_EVENT TO LT_EVENTS.
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_CHECKBOX_CHANGE.
  APPEND L_EVENT TO LT_EVENTS.
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_HEADER_CONTEXT_MEN_REQ.
  APPEND L_EVENT TO LT_EVENTS.
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_NODE_CONTEXT_MENU_REQ.
  APPEND L_EVENT TO LT_EVENTS.
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_ITEM_CONTEXT_MENU_REQ.
  APPEND L_EVENT TO LT_EVENTS.
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_HEADER_CLICK.
  APPEND L_EVENT TO LT_EVENTS.
  L_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_ITEM_KEYPRESS.
  APPEND L_EVENT TO LT_EVENTS.

  CALL METHOD TREE1->SET_REGISTERED_EVENTS
    EXPORTING
      EVENTS = LT_EVENTS
    EXCEPTIONS
      CNTL_ERROR                = 1
      CNTL_SYSTEM_ERROR         = 2
      ILLEGAL_EVENT_COMBINATION = 3.
  IF SY-SUBRC <> 0.
    MESSAGE X208(00) WITH 'ERROR'.                          "#EC NOTEXT
  ENDIF.

* set Handler
  DATA: L_EVENT_RECEIVER TYPE REF TO LCL_TREE_EVENT_RECEIVER.
  CREATE OBJECT L_EVENT_RECEIVER.
  SET HANDLER L_EVENT_RECEIVER->HANDLE_NODE_CTMENU_REQUEST
                                                        FOR TREE1.
  SET HANDLER L_EVENT_RECEIVER->HANDLE_NODE_CTMENU_SELECTED
                                                        FOR TREE1.
  SET HANDLER L_EVENT_RECEIVER->HANDLE_ITEM_CTMENU_REQUEST
                                                        FOR TREE1.
  SET HANDLER L_EVENT_RECEIVER->HANDLE_ITEM_CTMENU_SELECTED
                                                        FOR TREE1.
 
  

then you can directly call the below method when user press on some button in PAI.

  DATA: LS_FINAL1 TYPE G_FINAL.
  DATA: V_ANS TYPE C.
  DATA: LT_SELECTED_NODE TYPE LVC_T_CHIT,
        LS_SELECTED_NODE TYPE LVC_S_CHIT.

* Get checked entries from the tree
  CALL METHOD TREE1->GET_CHECKED_ITEMS
     IMPORTING ET_CHECKED_ITEMS = LT_SELECTED_NODE.

  IF NOT LT_SELECTED_NODE[] IS INITIAL.
* Popup for confirmation
    CALL FUNCTION 'SWO_POPUP_TO_CONFIRM'
         EXPORTING
              TEXT   = 'Do you want to delete record(s)?'(016)
              TITLE  = 'Delete record(s)'(017)
         IMPORTING
              ANSWER = V_ANS.


Hope this will help you.

Thanks&Regards,

Siri.

1 View this answer in context
Not what you were looking for? View more on this topic or Ask a question