Skip to Content

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

drop down list in alv tree

Hi,

I am developing an ALV TREE. I need help Its really urgent. In the output screen there will be 2 level nodes. in the item line 1 field should be input enabled using which the database table is to be modified.when user left clicks on this field a drop down list will appear from which he selects his choice.

I looked into BCALV_TREE_SIMPLE_DEMO reports available in SAP.

I would also like to know what is register_events, what is an handler.

help me.

Edited by: Sudipa Das on Oct 4, 2008 11:53 AM

Edited by: Sudipa Das on Oct 4, 2008 11:53 AM

Edited by: Sudipa Das on Oct 4, 2008 11:54 AM

replied

Hello Sudipa

I do not think you can have editable fields other than checkboxes in ALV trees. In sample report ZUS_SDN_ALV_TREE_DEMO_1 I have set the fieldcatalog property LS_FCAT-EDIT = 'X' for all fields yet only LOEVM is editable because it is defined as checkbox, too.

However, you may use the LINK_CLICK of the ALV tree (set LS_FCAT-HOTSPOT = 'X' in fieldcatalog) to trigger e.g. a seach help for input.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_ALV_TREE_DEMO
*&
*&---------------------------------------------------------------------*
*& Thread: drop down list in alv tree
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1074082"></a>
*&
*& Thread: alv tree checbox problem when attempt to get the selected checjboxes
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1050473"></a>
*&
*& Thread: alv tree checkbox problem
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1046535"></a>
*&
*& Thread: double click in ALV tree output????
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="742412"></a>
*&---------------------------------------------------------------------*
*& Flow logic of screen '0100' (contains no screen elements):
**  PROCESS BEFORE OUTPUT.
**    MODULE STATUS_0100.
***
**  PROCESS AFTER INPUT.
**    MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------------*
*& user-command (for command window): DISPLAY, SELECTED_NODES
*&---------------------------------------------------------------------*

REPORT  zus_sdn_alv_tree_demo_1.

CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.

TYPE-POOLS: abap, shlp.

TYPES: BEGIN OF ty_s_key.
TYPES: nkey       TYPE lvc_nkey.
TYPES: parent_key TYPE lvc_nkey.
TYPES: END OF ty_s_key.

TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knvv AS data.
INCLUDE TYPE ty_s_key AS key.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab    TYPE STANDARD TABLE OF ty_s_outtab
                      WITH DEFAULT KEY.

DATA: gt_outtab    TYPE ty_t_outtab.


DATA:
  gd_okcode        TYPE ui_func,
  gd_repid         TYPE syst-repid,
*
  gt_fcat          TYPE lvc_t_fcat,
  gs_layout        TYPE lvc_s_layo,
  gs_variant       TYPE disvariant,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_tree          TYPE REF TO cl_gui_alv_tree.


*----------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:

    handle_node_double_click
      FOR EVENT node_double_click OF cl_gui_alv_tree
      IMPORTING node_key,

    handle_item_double_click
      FOR EVENT item_double_click OF cl_gui_alv_tree
      IMPORTING node_key
                fieldname,

    handle_checkbox_change
      FOR EVENT checkbox_change OF cl_gui_alv_tree
      IMPORTING checked
                fieldname
                node_key,

    handle_link_click
      FOR EVENT link_click OF cl_gui_alv_tree
      IMPORTING fieldname
                node_key.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_node_double_click.
    MESSAGE 'Event=Double-Click on Node' TYPE 'I'.
    CALL TRANSACTION 'XD03'.

  ENDMETHOD.                    "handle_node_double_click

  METHOD handle_item_double_click.
    MESSAGE 'Event=Double-Click on Item' TYPE 'I'.
    CALL TRANSACTION 'VA03'.
  ENDMETHOD.                    "handle_item_double_click

  METHOD handle_checkbox_change.
    DATA: ls_outtab     TYPE ty_s_outtab.

    BREAK-POINT.
    IF ( fieldname = 'LOEVM' ).

      CALL METHOD go_tree->get_outtab_line
        EXPORTING
          i_node_key     = node_key
        IMPORTING
          e_outtab_line  = ls_outtab
*          e_node_text    =
*          et_item_layout =
*          es_node_layout =
        EXCEPTIONS
          node_not_found = 1
          OTHERS         = 2.
      IF sy-subrc <> 0.
*       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.

      ls_outtab-loevm = checked.

      MODIFY gt_outtab FROM ls_outtab
        TRANSPORTING loevm
        WHERE ( nkey = node_key ).
    ENDIF.

    " Trigger PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFRESH'
*        IMPORTING
*          rc       =
        .

  ENDMETHOD.                    "handle_checkbox_change

  METHOD handle_link_click.
    data: ls_shlp         type SHLP_DESCR,
          lt_retvalues    type STANDARD TABLE OF DDSHRETVAL.
    BREAK-POINT.

    CALL FUNCTION 'F4IF_GET_SHLP_DESCR'
      EXPORTING
        shlpname       = 'USER_COMP'
*       SHLPTYPE       = 'SH'
      IMPORTING
        SHLP           = ls_shlp.

    CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
      EXPORTING
        shlp                = ls_shlp
*       DISPONLY            = ' '
*       MAXRECORDS          = 500
*       MULTISEL            = ' '
*       CUCOL               = SY-CUCOL
*       CUROW               = SY-CUROW
*     IMPORTING
*       RC                  =
      tables
        return_values       = lt_retvalues.


  ENDMETHOD.                    "handle_link_click
ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION



START-OF-SELECTION.


  PERFORM init_controls.


  gd_repid = syst-repid.
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = gd_repid
      dynnr                       = '0100'
*      container                   =
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      lifetime_dynpro_dynpro_link = 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.

  CALL SCREEN '0100'.

** NOTE: no elements on screen
**  PROCESS BEFORE OUTPUT.
**    MODULE STATUS_0100.
***
**  PROCESS AFTER INPUT.
**    MODULE USER_COMMAND_0100.





END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.


ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.





  TRANSLATE gd_okcode TO UPPER CASE.

  CASE gd_okcode.
    WHEN 'BACK'  OR
         'EXIT'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

    WHEN 'REFRESH'.
      CALL METHOD go_tree->update_calculations
*        EXPORTING
*          no_frontend_update =
          .

    WHEN 'SELECTED_NODES'.
      PERFORM get_selected_nodes.

    WHEN 'DISPLAY'.
      PERFORM display.

    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  init_controls
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_controls .

* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent = cl_gui_container=>screen0
      ratio  = 90
    EXCEPTIONS
      OTHERS = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* create tree control
  CREATE OBJECT go_tree
    EXPORTING
      parent                      = go_docking
      node_selection_mode         = cl_gui_column_tree=>node_sel_mode_multiple
      item_selection              = 'X'  " required for double-click event on item
      no_html_header              = ''
      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.
  IF sy-subrc <> 0.
    MESSAGE x208(00) WITH 'ERROR'.                          "#EC NOTEXT
  ENDIF.


* create Hierarchy-header
  DATA ls_hierarchy_header TYPE treev_hhdr.
  PERFORM build_hierarchy_header CHANGING ls_hierarchy_header.


  PERFORM build_fieldcatalog.
  PERFORM set_layout_and_variant.

* create emty tree-control
  CALL METHOD go_tree->set_table_for_first_display
    EXPORTING
**      i_structure_name     = 'KNVV'
      is_variant           = gs_variant
      i_save               = 'A'
*      i_default            = 'X'
      is_hierarchy_header  = ls_hierarchy_header
*      is_exception_field   =
*      it_special_groups    =
*      it_list_commentary   =
*      i_logo               =
*      i_background_id      =
*      it_toolbar_excluding =
*      it_except_qinfo      =
    CHANGING
      it_outtab            = gt_outtab
*      it_filter            =
      it_fieldcatalog      = gt_fcat.

* create hierarchy
  PERFORM create_hierarchy.

* register events
  PERFORM register_events.

* adjust column_width
  CALL METHOD go_tree->column_optimize.

ENDFORM.                    " init_controls


*&---------------------------------------------------------------------*
*&      Form  build_hierarchy_header
*&---------------------------------------------------------------------*
*       build hierarchy-header-information
*----------------------------------------------------------------------*
*      -->P_L_HIERARCHY_HEADER  strucxture for hierarchy-header
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING
                               p_hierarchy_header TYPE treev_hhdr.

  p_hierarchy_header-heading = 'Hierarchy Header'.          "#EC NOTEXT
  p_hierarchy_header-tooltip =
                         'This is the Hierarchy Header !'.  "#EC NOTEXT
  p_hierarchy_header-width = 30.
  p_hierarchy_header-width_pix = ''.

ENDFORM.                               " build_hierarchy_header



*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .
  DATA: ls_fcat   TYPE lvc_s_fcat.

  REFRESH: gt_fcat.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'KNVV'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
      i_bypassing_buffer           = 'X'
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  DELETE gt_fcat FROM 10.

  ls_fcat-tech = 'X'.
  MODIFY gt_fcat FROM ls_fcat
    TRANSPORTING tech
    WHERE ( key = 'X' ).

  ls_fcat-edit = 'X'.
  MODIFY gt_fcat FROM ls_fcat
    TRANSPORTING edit
    WHERE ( key NE 'X' ).

  READ TABLE gt_fcat INTO ls_fcat
       WITH KEY fieldname = 'LOEVM'.
  IF ( syst-subrc = 0 ).
    ls_fcat-checkbox = 'X'.
    ls_fcat-edit     = 'X'.
**    ls_fcat-hotspot  = 'X'.
    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDIF.

  READ TABLE gt_fcat INTO ls_fcat
       WITH KEY fieldname = 'ERNAM'.
  IF ( syst-subrc = 0 ).
    ls_fcat-hotspot  = 'X'.
    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDIF.

ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_layout_and_variant .

  CLEAR: gs_layout,
         gs_variant.


  gs_variant-report = syst-repid.
  gs_variant-handle = 'TREE'.

ENDFORM.                    " SET_LAYOUT_AND_VARIANT
*&---------------------------------------------------------------------*
*&      Form  create_hierarchy
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_hierarchy .
  DATA: ls_knvv     TYPE sflight,
        ld_idx      TYPE i,
        ls_outtab   TYPE ty_s_outtab,
        lt_outtab   TYPE ty_t_outtab.

* get data
  SELECT * FROM knvv INTO CORRESPONDING FIELDS OF TABLE lt_outtab
                        UP TO 20 ROWS .                 "#EC CI_NOWHERE

  SORT lt_outtab BY kunnr vkorg.

* add data to tree
  DATA: ld_root_key  TYPE lvc_nkey,
        ld_kunnr_key TYPE lvc_nkey,
        ld_vkorg_key TYPE lvc_nkey,
        ld_last_key  TYPE lvc_nkey.

  ld_idx = 0.
  LOOP AT lt_outtab INTO ls_outtab.

    AT FIRST.
      PERFORM add_root_line USING    ls_outtab-data
                                         ''
                              CHANGING ld_root_key.

      ADD 1 TO ld_idx.
      ls_outtab-nkey       = ld_root_key.
      ls_outtab-parent_key = space.
      MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
        TRANSPORTING key.
    ENDAT.

    ON CHANGE OF ls_outtab-kunnr.
      PERFORM add_customer_line USING    ls_outtab-data
                                         ld_root_key
                              CHANGING ld_kunnr_key.
      ADD 1 TO ld_idx.
      ls_outtab-nkey       = ld_kunnr_key.
      ls_outtab-parent_key = ld_root_key.
      MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
        TRANSPORTING key.
    ENDON.



    ON CHANGE OF ls_outtab-vkorg.
      PERFORM add_salesorg_line USING    ls_outtab-data
                                         ld_kunnr_key
                              CHANGING ld_vkorg_key.
      ADD 1 TO ld_idx.
      ls_outtab-nkey       = ld_vkorg_key.
      ls_outtab-parent_key = ld_kunnr_key.
      MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
        TRANSPORTING key.
    ENDON.
    PERFORM add_complete_line USING  ls_outtab-data
                                     ld_vkorg_key
                            CHANGING ld_last_key.

    ADD 1 TO ld_idx.
    ls_outtab-nkey       = ld_last_key.
    ls_outtab-parent_key = ld_vkorg_key.
    MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
      TRANSPORTING key.
  ENDLOOP.

* calculate totals
  CALL METHOD go_tree->update_calculations.

* this method must be called to send the data to the frontend
  CALL METHOD go_tree->frontend_update.
ENDFORM.                    " create_hierarchy


*&---------------------------------------------------------------------*
*&      Form  add_customer_line
*&---------------------------------------------------------------------*
*       add hierarchy-level 1 to tree
*----------------------------------------------------------------------*
*      -->P_LS_SFLIGHT  sflight
*      -->P_RELEATKEY   relatkey
*     <-->p_node_key    new node-key
*----------------------------------------------------------------------*
FORM add_root_line USING     us_data TYPE ty_s_outtab-data
                             ud_relat_key TYPE lvc_nkey
                     CHANGING  cd_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value,
        ls_data TYPE ty_s_outtab-data.

* set item-layout
  DATA: lt_item_layout TYPE lvc_t_layi,
        ls_item_layout TYPE lvc_s_layi.
  ls_item_layout-t_image = '@3Q@'.  " icon_overview
  ls_item_layout-fieldname = go_tree->c_hierarchy_column_name.
  ls_item_layout-style   =
                        cl_gui_column_tree=>style_intensifd_critical.
  APPEND ls_item_layout TO lt_item_layout.

* add node
  l_node_text =  'Overview: Sales Areas'.

  DATA: ls_node TYPE lvc_s_layn.
  ls_node-n_image   = space.
  ls_node-exp_image = space.

  CALL METHOD go_tree->add_node
    EXPORTING
      i_relat_node_key = ud_relat_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      i_node_text      = l_node_text
      is_outtab_line   = ls_data
      is_node_layout   = ls_node
      it_item_layout   = lt_item_layout
    IMPORTING
      e_new_node_key   = cd_node_key.

ENDFORM.                               " add_root_line


*&---------------------------------------------------------------------*
*&      Form  add_customer_line
*&---------------------------------------------------------------------*
*       add hierarchy-level 1 to tree
*----------------------------------------------------------------------*
*      -->P_LS_SFLIGHT  sflight
*      -->P_RELEATKEY   relatkey
*     <-->p_node_key    new node-key
*----------------------------------------------------------------------*
FORM add_customer_line USING     us_data TYPE ty_s_outtab-data
                                 ud_relat_key TYPE lvc_nkey
                     CHANGING  cd_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value,
        ls_data TYPE ty_s_outtab-data.

* set item-layout
  DATA: lt_item_layout TYPE lvc_t_layi,
        ls_item_layout TYPE lvc_s_layi.
  ls_item_layout-t_image = '@A0@'.  " icon_customer.
  ls_item_layout-fieldname = go_tree->c_hierarchy_column_name.
  ls_item_layout-style   =
                        cl_gui_column_tree=>style_intensifd_critical.
  APPEND ls_item_layout TO lt_item_layout.

* add node
  l_node_text =  us_data-kunnr.

  DATA: ls_node TYPE lvc_s_layn.
  ls_node-n_image   = space.
  ls_node-exp_image = space.

  CALL METHOD go_tree->add_node
    EXPORTING
      i_relat_node_key = ud_relat_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      i_node_text      = l_node_text
      is_outtab_line   = ls_data
      is_node_layout   = ls_node
      it_item_layout   = lt_item_layout
    IMPORTING
      e_new_node_key   = cd_node_key.

ENDFORM.                               " add_customer_line


*&---------------------------------------------------------------------*
*&      Form  add_salesorg_line
*&---------------------------------------------------------------------*
*       add hierarchy-level 1 to tree
*----------------------------------------------------------------------*
*      -->P_LS_SFLIGHT  sflight
*      -->P_RELEATKEY   relatkey
*     <-->p_node_key    new node-key
*----------------------------------------------------------------------*
FORM add_salesorg_line USING     us_data TYPE ty_s_outtab-data
                                 ud_relat_key TYPE lvc_nkey
                     CHANGING  cd_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value,
        ls_data TYPE ty_s_outtab-data.

* set item-layout
  DATA: lt_item_layout TYPE lvc_t_layi,
        ls_item_layout TYPE lvc_s_layi.
  ls_item_layout-t_image = '@DS@'.  " ICON_PARTNER_SALES_ACTIVITY
  ls_item_layout-fieldname = go_tree->c_hierarchy_column_name.
  ls_item_layout-style   =
                        cl_gui_column_tree=>style_intensifd_critical.
  APPEND ls_item_layout TO lt_item_layout.

* add node
  l_node_text =  us_data-vkorg.

  DATA: ls_node TYPE lvc_s_layn.
  ls_node-n_image   = space.
  ls_node-exp_image = space.

  CALL METHOD go_tree->add_node
    EXPORTING
      i_relat_node_key = ud_relat_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      i_node_text      = l_node_text
      is_outtab_line   = ls_data
      is_node_layout   = ls_node
      it_item_layout   = lt_item_layout
    IMPORTING
      e_new_node_key   = cd_node_key.

ENDFORM.                               " add_salesorg_line


*&---------------------------------------------------------------------*
*&      Form  add_cmplete_line
*&---------------------------------------------------------------------*
*       add hierarchy-level 3 to tree
*----------------------------------------------------------------------*
*      -->P_LS_SFLIGHT  sflight
*      -->P_RELEATKEY   relatkey
*     <-->p_node_key    new node-key
*----------------------------------------------------------------------*
FORM add_complete_line USING     us_data TYPE ty_s_outtab-data
                                 ud_relat_key TYPE lvc_nkey
                     CHANGING  cd_node_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value.

* set item-layout
  DATA: lt_item_layout TYPE lvc_t_layi,
        ls_item_layout TYPE lvc_s_layi.
  ls_item_layout-fieldname = go_tree->c_hierarchy_column_name.
  ls_item_layout-class   = cl_gui_column_tree=>item_class_checkbox.
  ls_item_layout-editable = 'X'.
  APPEND ls_item_layout TO lt_item_layout.

**  clear: ls_item_layout.
**  ls_item_layout-fieldname = 'BEGRU'.
**  ls_item_layout-class   = cl_gui_column_tree=>ITEM_CLASS_CHECKBOX.
**  ls_item_layout-editable = 'X'.
**  APPEND ls_item_layout TO lt_item_layout.

**  CLEAR ls_item_layout.
**  ls_item_layout-fieldname = 'PLANETYPE'.
**  ls_item_layout-alignment = cl_gui_column_tree=>align_right.
**  APPEND ls_item_layout TO lt_item_layout.

  l_node_text =  us_data-vtweg.

  DATA: ls_node TYPE lvc_s_layn.
  ls_node-n_image   = space.
  ls_node-exp_image = space.

  CALL METHOD go_tree->add_node
    EXPORTING
      i_relat_node_key = ud_relat_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      is_outtab_line   = us_data
      i_node_text      = l_node_text
      is_node_layout   = ls_node
      it_item_layout   = lt_item_layout
    IMPORTING
      e_new_node_key   = cd_node_key.
ENDFORM.                               " add_complete_line



*&---------------------------------------------------------------------*
*&      Form  register_events
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM register_events.
* 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.

  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
  APPEND l_event TO lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
  APPEND l_event TO lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_link_click.
  APPEND l_event TO lt_events.

  CALL METHOD go_tree->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
  SET HANDLER:
    lcl_eventhandler=>handle_node_double_click FOR go_tree,
    lcl_eventhandler=>handle_item_double_click FOR go_tree,
    lcl_eventhandler=>handle_checkbox_change   FOR go_tree,
    lcl_eventhandler=>handle_link_click        FOR go_tree.

**  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.
**  SET HANDLER l_event_receiver->handle_checkbox_change FOR tree1.

ENDFORM.                               " register_events



*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display .
  DATA: ls_outtab   TYPE ty_s_outtab,
        ls_line     TYPE ty_s_outtab,
        ld_msg      TYPE bapi_msg.


  BREAK-POINT.

  LOOP AT gt_outtab INTO ls_outtab
          WHERE ( loevm = 'X' ).
    CONCATENATE 'Checkbox:'
                ls_outtab-kunnr
                ls_outtab-vkorg
                ls_outtab-vtweg
                ls_outtab-spart
                ls_outtab-loevm
      INTO ld_msg SEPARATED BY space.
    MESSAGE ld_msg TYPE 'I'.
  ENDLOOP.
  IF ( syst-subrc NE 0 ).
    MESSAGE 'No marked checkboxes found' TYPE 'I'.
  ENDIF.

  PERFORM get_selected_nodes.

ENDFORM.                    " DISPLAY


*&---------------------------------------------------------------------*
*&      Form  GET_SELECTED_NODES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_selected_nodes.
* define local data
  DATA: ld_msg        TYPE bapi_msg,
        lt_nodes      TYPE lvc_t_nkey,
        ls_outtab     TYPE ty_s_outtab,
        ld_nkey       TYPE lvc_nkey,
        lt_items      TYPE lvc_t_layi,
        ls_item       TYPE lvc_s_layi.


  CALL METHOD go_tree->get_selected_nodes
    CHANGING
      ct_selected_nodes = lt_nodes
    EXCEPTIONS
      cntl_system_error = 1
      dp_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.

  CHECK ( lt_nodes IS NOT INITIAL ).
  BREAK-POINT.

  LOOP AT lt_nodes INTO ld_nkey.
    CALL METHOD go_tree->get_outtab_line
      EXPORTING
        i_node_key     = ld_nkey
      IMPORTING
        e_outtab_line  = ls_outtab-data
*        e_node_text    =
        et_item_layout = lt_items
*        es_node_layout =
      EXCEPTIONS
        node_not_found = 1
        OTHERS         = 2.
    IF sy-subrc <> 0.
*     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    LOOP AT lt_items INTO ls_item
                     WHERE ( chosen = 'X' ).
      CONCATENATE 'Item:'
                  ls_outtab-kunnr
                  ls_outtab-vkorg
                  ls_outtab-vtweg
                  ls_outtab-spart
                  ls_outtab-loevm
        INTO ld_msg SEPARATED BY space.
      MESSAGE ld_msg TYPE 'I'.
    ENDLOOP.

  ENDLOOP.

ENDFORM.                    " GET_SELECTED_NODES

Regards

Uwe

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