Skip to Content
Technical Articles

Configuration Tree Path enhancement

Introduction

Hi and welcome to my next SAP Community blog post.

Imagine a situation where you’re creating a training material and need to provide a configuration path. Or, from the other side, you’re reading a manual and want to find the tree path yourself. Standard SAP requires you to do it manually – node by node.

This enhancement is meant to make these tasks easier – concatenating the full path to a selected node or finding the node from the copied path.

This blog post first appeared on the Int4 blog.

The basics

As the configuration tree is a standard functionality contained in a standard report, you want to make as few modifications as possible. You can achieve this by enhancing the context menu of the tree and adding two new items to it:

  1. Paste Node Path – this item will be responsible for finding the configuration node from the configuration path stored in the clipboard,
  2. Copy Node’s Path – this item will be responsible for creating a full path to the first selected node and copying it into the clipboard.

To add new context menu items, you need to create an implicit enhancement (or code modification) at the end of the SPROJECT_CONTEXT_MENU function. In this enhancement, call the MODIFY_CONTEXT_MENU method of the custom class with the enhancement logic.

Context%20menu%20implicit%20enhancement

Context menu implicit enhancement

To handle the new context menu items, you need to create an implicit enhancement (or code modification) at the end of the S_IMG_USER_EXIT_1 function. In this enhancement, call the HANDLE_COMMAND method of the custom class.

Handle%20command%20implicit%20enhancement

Handle command implicit enhancement

This is all that you need to modify in the standard code. The rest of the logic is contained in a custom class.

The enhancement logic

As mentioned before, the whole logic of the enhancement is contained in one custom class. The class is available for download from the link presented at the bottom of this article.

For the ease of use, all of the methods of the class are marked as static. These could be instance methods as well. Below you will find a short description of what each of the methods does.

Method HANDLE_COMMAND

The HANDLE_COMMAND method is used to execute the action after the user picks an item from the context menu. The method itself does not contain any action-related logic, it reroutes the processing to other appropriate methods.

  METHOD handle_command.
    CASE iv_command.
      WHEN ac_command_copy.
        CALL METHOD handle_command_copy
          EXPORTING
            iv_command   = iv_command
            iv_language  = iv_language
            it_nodes     = it_nodes
            it_all_nodes = it_all_nodes
            it_all_texts = it_all_texts.

        cv_execute_command = abap_false.
      WHEN ac_command_paste.
        CALL METHOD handle_command_paste
          EXPORTING
            iv_command            = iv_command
            iv_language           = iv_language
            it_nodes              = it_nodes
            it_all_nodes          = it_all_nodes
            it_all_texts          = it_all_texts
          CHANGING
            cv_update_actual_node = cv_update_actual_node
            cs_actual_node        = cs_actual_node.

        cv_execute_command = abap_false.
    ENDCASE.
  ENDMETHOD.

Method MODIFY_CONTEXT_MENU

The MODIFY_CONTEXT_MENU method contains the code responsible for appending custom items to the context menu of the configuration tree. The logic is very simple, although there are two things worth mentioning:

  1. The empty item appended in the first line of the method is later converted by the system to a separator.
  2. Custom commands assigned to the context menu items are taken from constants defined in the class, thus making it possible to reuse the same values in other methods of the class.
  METHOD modify_context_menu.
    APPEND INITIAL LINE TO ct_menu REFERENCE INTO DATA(ld_menu).
    APPEND INITIAL LINE TO ct_menu REFERENCE INTO ld_menu.
    ld_menu->menu_fcode = ac_command_paste.
    ld_menu->menu_text = 'Paste Node Path'(m01).
    ld_menu->is_no_ref = abap_true.
    APPEND INITIAL LINE TO ct_menu REFERENCE INTO ld_menu.
    ld_menu->menu_fcode = ac_command_copy.
    ld_menu->menu_text = 'Copy Node''s Path'(m02).
    ld_menu->is_no_ref = abap_true.
  ENDMETHOD.

Method GET_DEFAULT_SEPARATOR

To concatenate the whole path of the first selected configuration tree node, a separator is needed. The GET_DEFAULT_SEPARATOR method is responsible for providing it. It first checks user parameters to look for a user-defined separator and, if none is found, the first from the list of possible separators is used. The name of the user parameter is defined in the AC_USER_PARAMETER_SEPARATOR constant.

  METHOD get_default_separator.
    DATA:
      lt_parameters TYPE ustyp_t_parameters.

    CALL FUNCTION 'SUSR_USER_PARAMETERS_GET'
      EXPORTING
        user_name           = sy-uname
      TABLES
        user_parameters     = lt_parameters
      EXCEPTIONS
        user_name_not_exist = 1
        OTHERS              = 2.
    IF sy-subrc = 0.
      READ TABLE lt_parameters REFERENCE INTO DATA(ld_parameter)
        WITH KEY parid = ac_user_parameter_separator.
      IF sy-subrc = 0 AND ld_parameter->parva IS NOT INITIAL.
        rv_separator = ld_parameter->parva.
        RETURN.
      ENDIF.
    ENDIF.

    DATA(lt_separators) = get_possible_separators( ).
    READ TABLE lt_separators INTO rv_separator INDEX 1.
  ENDMETHOD.

Method GET_POSSIBLE_SEPARATORS

When parsing a copied path, the class first tries to split it with the use of different separators. These possible separators are defined in method GET_POSSIBLE SEPARATORS. The parsing is done using the same sequence that separators are added to the list.

Method HANDLE_COMMAND_COPY

The HANDLE_COMMAND_COPY method is responsible for concatenating the whole path of the first selected configuration tree node. A separator obtained from the GET_DEFAULT_SEPARATOR method is used to separate the path elements. After the concatenation is complete, the result is copied to clipboard for easy use in other applications.

The method tries to obtain the nodes description in four different languages:

  1. The language of the configuration tree,
  2. The language of the system for the current user,
  3. English,
  4. German.

If the description is not found in any of the languages, a hard-coded text “NODE {node_id} DESCRIPTION MISSING” is used instead.
The maximum length of the path is defined as 4096 characters.

Method HANDLE_COMMAND_PASTE

The HANDLE_COMMAND_PASTE method is responsible for parsing a pasted configuration tree path. Separators listed in the GET_POSSIBLE_SEPARATORS method are used to split the path into separate elements. The separators are used in the sequence defined in the GET_POSSIBLE_SEPARATORS method and splitting is stopped after the first success.
Because not all nodes of the configuration tree are available after the tree is presented, the method loads missing nodes if required. For better performance, only the children of the parsed path elements are loaded.

Similar as in the HANDLE_COMMAND_COPY method, the logic responsible for finding configuration tree nodes uses four different languages. This is to maximize the chance of finding the node.
When parsing is finished, a success message is presented to the user at the bottom of the screen.

Summary

A custom class and two implicit enhancements is all you need to simplify the configuration tree navigation. Now you’re able to easily create and parse a configuration tree path.

Configuration%20tree%20enhancement%20in%20action

Configuration tree enhancement in action

You can download the solution from GitHub (https://github.com/peyn/Configuration-Tree-Path).

3 Comments
You must be Logged on to comment or reply to a post.
  • Could you compare and contrast using this vs. setting up a project?

    Also if you look into your crystal ball can you see any issues with this in the future?  For me having custom paths would drive me slightly crazy.   The one thing I use a lot is the search functionality.  It would just mean more results.  But that is a personal preference.  Sometimes I do open the nodes.  Usually when I know my search will come up with too many results.   Then it's just easier to drill into the nodes.

    The other thing is "some of the time" the links are described in a message from another question/answer.  If I read this correctly that wouldn't be an issue as both the original and the "custom" version of the links are out there still.

    TIA,

    Michelle

    • Hi Michelle,

       

      Thanks for the comment. 🙂

      This is a generic solution, useful in a situation where you have a configuration path, for example from a webpage/blog/training and you want to quickly find it in the tree. Or, the other way around, you want to create a path and paste it into a document/email. It works on the currently visible tree.

      If you have configuration nodes which you often use, then you will probably find them faster manually.

      I can see issues if the standard implementation of the configuration tree is changed. But it also depends on the changes made.

      I'm not sure what you mean by "custom paths". The enhancement works on the tree currently visible on the screen. It dynamically reads and parses the visible nodes. If you have a path in your clipboard, the enhancement tries to find the path in the tree. If it is there, then the node is showed and selected. The paths consist of the nodes that are in the tree, nothing additional is used.

      Search functionality is useful, too. However, it shows all nodes with the searched word. Regardless of the path they are in.

      Kind regards,

      Mateusz

      • Thank you for the clarification.   Get to it quick and easy.   Yes, I was just worried by creating the copies that it would cause more nodes to show up.   It's something interesting to think about.