3 Replies Latest reply: May 17, 2010 3:15 PM by Luis Mesquita RSS

ALV tree get selected checkbox

Tomasz Mackowski
Currently Being Moderated

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.

  • Re: ALV tree get selected checkbox
    Srilatha T
    Currently Being Moderated

    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.

    • Re: ALV tree get selected checkbox
      Luis Mesquita
      Currently Being Moderated

      now u can read it

       

       
      * 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. 
      
      

       

      • Re: ALV tree get selected checkbox
        Luis Mesquita
        Currently Being Moderated

        Ok it follow the way i acted in order to read the content that as been check in the PAI module.

         

        
          DATA: lt_selected_node TYPE lvc_t_chit,
          ls_selected_node TYPE lvc_s_chit,
          wa_selected_node TYPE lvc_s_chit,
          e_outtab_line TYPE " put here the TYPE of your output table 
                                          " the same you assigned to the it_outtab
                                         ." in the method tree1->set_table_for_first_display
        
        * Get checked entries from the tree
          CALL METHOD tree1->get_checked_items
            IMPORTING
              et_checked_items = lt_selected_node.
        
        
        * now that you have the codes of the nodes
        * you might want to get the content of the correspondent lines
        * i did it with the code bellow
        
        loop at lt_selected_node into wa_selected_node.
         
        * this method gets the line correspondent to a node code
        
        CALL METHOD tree1->get_outtab_line
            EXPORTING
              i_node_key    = wa_selected_node-nodekey
            IMPORTING
              e_outtab_line = e_outtab_line.
        
        move-CORRESPONDING e_outtab_line to it_transfer_table.
        APPEND it_transfer_table.
        
        
          ENDLOOP.
        
        * that's it
        * now you have table with the checked items 
        
        

         

         

        hope this helps some of you!!

         

        if there is a better way of doing this post reply tks

Actions