11-11-2008 11:49 AM
Hello Community,
I have a serious Problem with the p_node_key value while using it in u201Cread table with index p_node_key.u201D
During the run of a program the content of the data-table with is used for the tree changes. Because he does not show the data correctly a rebuild of the nodes is necessary.
I read all nodes treenodes = tree->get_nodes( ). Then delete them treenodes ->delete_all.
Then add the nodes based on the current data-table
node = nodes->add_node( related_node = u2026
data_row = u2026
row_style = u2026
relationship = cl_gui_column_tree=>relat_last_child )
Unfortunately p_node_key counts endlessly and does not restart with one.
Example: Datatable with 50 rows.
In the first run reading the table with index p_node_key works fine.
Second run the table still has 50 rows but the p_node_key now starts with 51 so he will select an emty row while reading the table with index p_node_key.
How do I reset the p_node_key for every rebuild of the tree?
11-12-2008 4:54 AM
Hello Markus
The trick is not to rely on the NODE_KEY as index but to include it into the record of your data itab. For a sample report have a look at ZUS_SDN_ALV_TREE_DEMO in thread .
The crucial parts of the coding are shown below:
TYPES: BEGIN OF ty_s_key.
TYPES: nkey TYPE lvc_nkey. " key of record
TYPES: parent_key TYPE lvc_nkey. " parent key of record
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.
*&---------------------------------------------------------------------*
*& 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
Read your records like this:
READ gt_outtab INTO ls_outtab
WITH key nkey = p_node_key.
...
Regards
Uwe
11-12-2008 8:30 PM
Hi ,
yu might have kept the adding of node process inside a loop . It might be looping on your main internal table. Instead of looping it on your main internal table make one local internal table and loop on it .
Please take the below code as reference. In this code li_vbap is local internal table and gi_vbap as global one.
form create_hierarchy .
data:
l_vbeln type vbap-vbeln,
l_posnr type vbap-posnr,
l_matnr type vbap-matnr,
li_vbap like standard table of w_vbap.
li_vbap = gi_vbap.
refresh gi_vbap.
loop at li_vbap into w_vbap.
l_vbeln = w_vbap-vbeln.
l_posnr = w_vbap-posnr.
l_matnr = w_vbap-matnr.
on change of w_vbap-vbeln.
perform add_vbeln using l_vbeln
' '.
endon.
on change of w_vbap-posnr.
perform add_posnr using l_posnr
w_vbeln_key.
endon.
perform add_matnr using l_matnr
w_posnr_key.
endloop.
endform. " create_hierarchy
With Regards,
Anomitro Guha