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.