Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

alv tree get selected items

alejandro_romero2
Participant
0 Kudos

hi gusrus i would like to know how can i get the user selected items from an alvtree oo.

thanks.

5 REPLIES 5

0 Kudos

thanks a lot but im really new in abap object so i dont know how to implment it

i am using this portion of code, what should i do next to get the selected rows?

CREATE OBJECT g_custom_container

EXPORTING

container_name = l_tree_container_name

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

CREATE OBJECT g_alv_tree

EXPORTING

parent = g_custom_container

node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple

item_selection = ''

no_html_header = 'X'

no_toolbar = ''

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

illegal_node_selection_mode = 5

failed = 6

illegal_column_name = 7.

Edited by: Alejandro Romero on Sep 8, 2008 8:26 PM

0 Kudos

Hi Alejandro,

The code you have provided is far not enought to create an alv tree control. I assume this is only part of your program.

Providing you have tree already displayed and you can select nodes, now you may use below to get selected nodes (keys of rows) from the tree:


data: it_nodes type TREEMNOTAB.

call method g_alv_tree->GET_SELECTED_NODES
	importing
		NODE_KEY_TABLE = it_nodes.

I hope it will help you

BR,

Marcin

0 Kudos

Hello Alejandro

Copy report BCALV_TREE_DEMO to a z-report and make the following changes in the PAI module.

Please note than you can select multiple nodes but only single items.

In addition, to allow item selection you have to change the instantiation of your tree:


CREATE OBJECT g_alv_tree
EXPORTING
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'   " if space then no item selection is possible
no_html_header = 'X'
...


*&---------------------------------------------------------------------*
*&      Module  PAI  INPUT
*&---------------------------------------------------------------------*
*       process after input
*----------------------------------------------------------------------*
module pai input.

  translate ok_code to UPPER CASE.

  case ok_code.
    when 'EXIT' or 'BACK' or 'CANC'.
      perform exit_program.


    when 'GET_SELECTED_ITEM'.
      perform GET_SELECTED_ITEM.

    when others.
      call method cl_gui_cfw=>dispatch.
  endcase.
  clear ok_code.
  call method cl_gui_cfw=>flush.

endmodule.                             " PAI  INPUT

*&---------------------------------------------------------------------*
*&      Form  GET_SELECTED_ITEM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form GET_SELECTED_ITEM .
  data: ld_nkey         type lvc_nkey,
        ld_fieldname    type lvc_fname,
        ld_msg          type bapi_msg.

  CALL METHOD tree1->get_selected_item
    IMPORTING
      e_selected_node   = ld_nkey
      e_fieldname       = ld_fieldname
    EXCEPTIONS
      no_item_selection = 1
      cntl_system_error = 2
      failed            = 3
      others            = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  concatenate 'NKey=' ld_nkey
              'Fieldname=' ld_fieldname
              into ld_msg.
  message ld_msg type 'I'.

endform.                    " GET_SELECTED_ITEM

You may want to have a look at thread to get some more details about this sample report.

Regards

Uwe

alejandro_romero2
Participant
0 Kudos

Thanks guys i solve the problem thanks again