Quantcast
Channel: SCN: Message List - ABAP Connectivity
Viewing all articles
Browse latest Browse all 3125

Tree List not getting refresh

$
0
0

Hi,

  I have a requirement to display a list of documents to upload in tree(Hierarchy) view like below screenshot:

img 1.png

When we click on child node(trigger double click event), the relevant details display in right side of field. When we upload a document by pressing upload button, it uploads document using global class and after successful upload it should display a green check mark against that document. Logic is updating database table but it does not refresh the screen to show that check mark icon ( like we use refresh_table_display). How to refresh the this tree.

 

My code is: (It is a module pool tab strip program.)

 

 

CLASS LCL_APPLICATION_TREE DEFINITION DEFERRED.


TYPES: ITEM_TABLE_TYPE LIKE STANDARD TABLE OF MTREEITM WITH DEFAULT KEY.

 

   DATA: G_APPLICATION_TREE TYPE REF TO LCL_APPLICATION_TREE,

              cc_alv_cont                     TYPE REF TO CL_GUI_CUSTOM_CONTAINER,

              G_TREE                         TYPE REF TO CL_GUI_LIST_TREE,

              G_OK_CODE                  TYPE SY-UCOMM.

 

data:      Root      type tv_nodekey value 'Root'.          


data:      it_doc_list      type TABLE OF /spli/doc_list,

             wa_doc_list    like LINE OF it_doc_list,

             it_doc_h type  table of /SPLI/CL_DOC_H

             wa_doc_h like line of it_doc_h.

 

FIELD-SYMBOLS: <fs_doc_h> like line of it_doc_h.

 

data: it_doc  type table of /spli/cl_doc_h,       " temp table to get document history

       wa_doc  like line of it_doc,                " temp wa to get dociment history

       wa_hist_temp like line of it_doc_h.         "

 

DATA: NODE_TABLE     TYPE TREEV_NTAB,         

           ITEM_TABLE       TYPE ITEM_TABLE_TYPE,    

           NODE                 TYPE TREEV_NODE,             

           ITEM                   TYPE MTREEITM                

           wa_ITEM             like line of item_table.

 

 

*************************************************

*  IN PBO in have written below code      *

*************************************************

 

if g_tree is INITIAL.

           IF cc_alv_cont is INITIAL.

             perform get_tree_data.

             perform build_tree_container.

             perform build_tree.

           endif.

endif.

 

____________________________________________________________________________________________

FORM GET_TREE_DATA .

clear: wa_doc_list, it_doc_list, it_doc_h.

  * if application open first time it select data from config table TAB1

     bla bla bla

        bla bla bla

   * endif.

 

  * if application open 2nd time (document uploaded and have to refresh tree), it select data from transaction  table TAB2

     bla bla bla

        bla bla bla

   * endif.

 

ENDFORM.                    " GET_TREE_DATA

______________________________________________________________________________________________


* create a container for the tree control

   CREATE OBJECT cc_alv_cont

     EXPORTING    

       CONTAINER_NAME = 'TREE_CONTAINER'

     EXCEPTIONS

       CNTL_ERROR = 1

       CNTL_SYSTEM_ERROR = 2

       CREATE_ERROR = 3

       LIFETIME_ERROR = 4

       LIFETIME_DYNPRO_DYNPRO_LINK = 5.

   IF SY-SUBRC <> 0.

     MESSAGE A011.

   ENDIF.


________________________________________________________________________________________


FORM BUILD_TREE .

   DATA: EVENTS      TYPE CNTL_SIMPLE_EVENTS,

               event            type cntl_simple_event.

 

* create a list tree

   CREATE OBJECT g_tree

     EXPORTING

       PARENT              = cc_alv_cont

       NODE_SELECTION_MODE = CL_GUI_LIST_TREE=>NODE_SEL_MODE_SINGLE

       ITEM_SELECTION     = 'X'

       WITH_HEADERS       = ' '

     EXCEPTIONS

       CNTL_SYSTEM_ERROR           = 1

       CREATE_ERROR                = 2

       FAILED                      = 3

       ILLEGAL_NODE_SELECTION_MODE = 4

       LIFETIME_ERROR              = 5.

   IF SY-SUBRC <> 0.

     MESSAGE A011.

   ENDIF.

 

* define the events which will be passed to the backend

  " node double click

   event-eventid = CL_GUI_list_TREE=>EVENTID_NODE_DOUBLE_CLICK.

   event-appl_event = 'X'.                                   "

   append event to events.

 

    " item double click

   EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_ITEM_DOUBLE_CLICK.

   event-appl_event = 'X'.

   append event to events.

 

     " expand no children

   EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_EXPAND_NO_CHILDREN.

   event-appl_event = 'X'.

   append event to events.

 

   " link click

   EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_LINK_CLICK.

   event-appl_event = 'X'.

   append event to events.

 

    " button click

   EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_BUTTON_CLICK.

   event-appl_event = 'X'.

   append event to events.

 

    " checkbox change

   EVENT-EVENTID = CL_GUI_LIST_TREE=>EVENTID_CHECKBOX_CHANGE.

   event-appl_event = 'X'.

   append event to events.

 

   CALL METHOD G_TREE->SET_REGISTERED_EVENTS

     EXPORTING

       EVENTS = EVENTS

     EXCEPTIONS

       CNTL_ERROR                = 1

       CNTL_SYSTEM_ERROR         = 2

       ILLEGAL_EVENT_COMBINATION = 3.

   IF SY-SUBRC <> 0.

     MESSAGE A011.

   ENDIF.

 

  CREATE OBJECT G_APPLICATION_TREE.

* assign event handlers in the application class to each desired event

   SET HANDLER G_APPLICATION_TREE->HANDLE_NODE_DOUBLE_CLICK  FOR G_TREE.

   SET HANDLER G_APPLICATION_TREE->HANDLE_ITEM_DOUBLE_CLICK  FOR G_TREE.

   SET HANDLER G_APPLICATION_TREE->HANDLE_EXPAND_NO_CHILDREN FOR G_TREE.

   SET HANDLER G_APPLICATION_TREE->HANDLE_LINK_CLICK         FOR G_TREE.

   SET HANDLER G_APPLICATION_TREE->HANDLE_BUTTON_CLICK       FOR G_TREE.

   SET HANDLER G_APPLICATION_TREE->HANDLE_CHECKBOX_CHANGE    FOR G_TREE.

 

* add some nodes to the tree control

* NOTE: the tree control does not store data at the backend. If an

* application wants to access tree data later, it must store the

* tree data itself.

 

   PERFORM BUILD_NODE_AND_ITEM_TABLE USING NODE_TABLE ITEM_TABLE.

 

   CALL METHOD G_TREE->ADD_NODES_AND_ITEMS

     EXPORTING

       NODE_TABLE = NODE_TABLE

       ITEM_TABLE = ITEM_TABLE

       ITEM_TABLE_STRUCTURE_NAME = 'MTREEITM'

     EXCEPTIONS

       FAILED = 1

       CNTL_SYSTEM_ERROR = 3

       ERROR_IN_TABLES = 4

       DP_ERROR = 5

       TABLE_STRUCTURE_NAME_NOT_FOUND = 6.

   IF SY-SUBRC <> 0.

     MESSAGE A011.

   ENDIF.

 

ENDFORM.                    " BUILD_TREE


_____________________________________________________________________________


FORM BUILD_NODE_AND_ITEM_TABLE  USING    NODE_TABLE TYPE TREEV_NTAB

                                          ITEM_TABLE TYPE ITEM_TABLE_TYPE.

   if flg_clm eq 2.

     clear: node_table, item_table.

   endif.

 

 

* Node with root.

   node-node_key = root.

   clear node-relatkey.

   clear node-relatship.

   node-hidden   = ' '.

   node-isfolder = 'X'.

   clear node-n_image.

   clear Node-exp_image.

   clear node-expander.

   APPEND node to node_table.

   clear node.

 

*  node with parent

   LOOP AT it_doc_list into wa_doc_list.

     node-node_key = wa_doc_list-doc_group.

     node-relatkey = root.

     node-relatship = cl_gui_list_tree=>relat_last_child.

     node-isfolder  = 'X'.

     Append node to node_table.

     clear node.

*   node with child

       LOOP AT it_doc_h into wa_doc_h where doc_group eq wa_doc_list-doc_group.

         node-node_key  = wa_doc_h-doc_name.

         node-relatkey = wa_doc_list-doc_group.

         node-relatship = cl_gui_list_tree=>relat_last_child.

         APPEND node to node_table.

         clear: node, wa_doc_h.

       ENDLOOP.

       clear: node, wa_doc_list.

   ENDLOOP.

 

*  the items of the nodes:

*  node with key root.

data: lv_parent type i value 0,

       lv_child  type i value 0.

   clear item.

   lv_parent = lv_parent + 1.

   item-node_key   = root.

   item-item_name  = lv_parent.

   item-class = cl_gui_list_tree=>item_class_text.      " text item piyush

   " the width of the item is adjusted to its content (text)

   item-alignment  = cl_gui_list_tree=>align_auto.

   " use proportional font for the item

   item-font       = cl_gui_list_tree=>item_font_prop.

   item-text       = 'Documents Check List'.

   APPEND item to item_table.

   clear: item, lv_parent.

 

 

 

   LOOP AT it_doc_list into wa_doc_list.

     item-node_key   = wa_doc_list-doc_group.

     lv_parent = lv_parent + 1.

     item-item_name  = lv_parent.    "wa_doc_list-doc_name.

     item-class      = cl_gui_list_tree=>item_class_text.

     item-alignment  = cl_gui_list_tree=>align_auto.

     item-font       = cl_gui_list_tree=>item_font_prop.

     item-text       = wa_doc_list-doc_group.

     append item to item_table.

     clear: item, wa_doc_list, lv_parent.

   ENDLOOP.

 

     clear: item, wa_doc_h.

     LOOP AT it_doc_h into wa_doc_h.

       clear item.

       lv_child = lv_child + 1.

       item-node_key   = wa_doc_h-doc_name.

       ITEM-ITEM_NAME = lv_child.               "wa_doc_h-doc_name.

       ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

       ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.

*      ITEM-LENGTH    = '72'.

       ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.

       item-text = wa_doc_h-doc_name.

       APPEND ITEM TO ITEM_TABLE.

       clear item.

 

   IF wa_doc_h-doc_upload eq 'X'.

     lv_child = lv_child + 1.

       item-node_key = wa_doc_h-doc_name.      "'Uploaded'. "wa_doc_h-upload_icon.

       ITEM-ITEM_NAME = lv_child. "wa_doc_h-upload_icon.

       ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

       ITEM-LENGTH = 4. " the width of the item is 4 characters

       ITEM-IGNOREIMAG = 'X'.               " see documentation of Structure

                                            " TREEV_ITEM

*      ITEM-USEBGCOLOR = 'X'.               " item has light grey background

       ITEM-T_IMAGE = wa_doc_h-upload_icon"'@01@'          " icon of the item

       APPEND ITEM TO ITEM_TABLE.

    endif.

 

       clear: itemlv_child, wa_doc_h.

      ENDLOOP.

 

 

ENDFORM.                    " BUILD_NODE_AND_ITEM_TABLE

_______________________________________________________________________________



When I open program first time, it works fine, but when I upload a document it doesn't refresh the tree, to refresh the tree, I have to re-start the program. If I do some code then either it overlap to all the tabs or double click event doesn't work.


Please suggest me how to handle this asap.



Regards

Piyush


Viewing all articles
Browse latest Browse all 3125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>