Technical Articles
Deletion of Nodes in Column Tree
This blog post is to share how our team (UI Data Protection Masking for SAP S/4HANA) was able to solve a problem uniquely.
As part of our Policy Builder, we needed a column tree to provide a better UI for the user. We used the class ‘ CL_GUI_COLUMN_TREE’ to create the tree.
To provide a better sense, our display looks like this :
Our aim is to allow the user to delete a Node (eg: Block: SE16 or Block: PA30) from the tree. Scanning through the documentation of the class (CL_GUI_COLUMN_TREE). We found the method DELETE_NODE.
This method worked fine for a single node, but when we had multiple nodes, we got a short dump :
The analysis of the dump revealed that the reconstruction of the column tree is not handled implicitly through the method. We tried to look for a solution through SAP blog posts and question. (s).
We could not find a fix for this and all the blog posts gave us little hope on how well the COLUMN_TREE as a data structure is suited for deletion. So, we came up with a solution of our own.
As a fix, we modified our mappings before calling this method.
To avoid the need for reconstruction, we saved the NODE_ID of the node which was selected for deletion and implicitly moved it to the bottom of the Column tree and then re-adjusting our database table accordingly. This allowed the standard method to always delete a leaf node from the tree and circumvent the scenario which was failing.
IF lv_answer = 1 AND lv_node_id NE lv_last_node_id.
"Move the node to the last node first and then delete it.
WHILE lv_count <> ( lv_last_node_id - lv_selected_node_id ).
move_block(
EXPORTING
iv_operation = 'D'
iv_node_key = lv_node_id
iv_item_name = lv_item_name
CHANGING
ct_policy_rule = ct_policy_rule
).
lv_node_id = lv_node_id + 1.
lv_count = lv_count + 1.
CONDENSE lv_node_id.
ENDWHILE.
ENDIF.
gr_column_tree->delete_node(
EXPORTING
node_key = lv_node_id
EXCEPTIONS
failed = 1
node_not_found = 2
cntl_system_error = 3
OTHERS = 4
).
I feel, our out-of-the-box thinking will have two advantages –
- Provide developers a way to perform deletion in their column tree.
- Motivate others to solve problems through an experimental approach.
We also welcome any thoughts of a better approach to handle such scenarios.
Image sources: Screenshots.
Hi, Shantanu, thank you, that’s an interesting approach!
Some random thoughts:
Hi Egor,
I have a remark about the title: the term "ALV column tree" is not wrong, but the most-used name is just "ALV tree", as it's always based on the basic "column tree" control; but your post is about column trees, which are not always ALV trees. So maybe you could remove the word "ALV" from the title.
I second what has said Egor, that if DELETE_NODE makes the frontend fail, it's just that the ABAP code which does DELETE_NODE is buggy. What is also important to add is that if the deleted node was a unique child node and its parent node was declared as a folder. To avoid this short dump, you also need to check that case, and change its parent node to not be a folder.
Hi Sandra,
Thanks for your suggestions. I agree that this blog post is for Column Trees in general. I have made the changes to the title.
We are using this Tree as part of an editable UI to build customized security policies. Besides the root node, we can never be too sure of how a user manipulates(inserts/deletes/edits nodes) the tree. Although, we do have to ensure that the parent-child relationship is maintained and is uniform throughout.
Regards,
Shantanu