Skip to Content

Recently I start to study SD and I found the product hierarchy in transaction code V/76 could not be viewed in tree style and it is not so convenient to check:

/wp-content/uploads/2016/09/clipboard1_1033297.png

So I wrote a simple report to retrieve hierarchy data from table T179 and display the data in a tree as below:

/wp-content/uploads/2016/09/clipboard2_1033466.png

The source code of report is listed below:

REPORT zdisplay_hierarchy.
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
  gt_data TYPE STANDARD TABLE OF zcl_alv_tool=>ty_displayed_node,
  ok_code LIKE sy-ucomm,
  save_ok LIKE sy-ucomm,
  ls_data LIKE LINE OF gt_data.
END-OF-SELECTION.
  DATA(lo_tool) = NEW zcl_alv_tool( ).
  DATA(lt_fieldcat) = lo_tool->get_fieldcat_by_data( ls_data ).
  PERFORM change_label.
  CALL SCREEN 100.
MODULE pbo OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR 'MAINTITLE'.
  IF g_alv_tree IS INITIAL.
  PERFORM init_tree.
  CALL METHOD cl_gui_cfw=>flush
  EXCEPTIONS
  cntl_system_error = 1
  cntl_error = 2.
  ASSERT sy-subrc = 0.
  ENDIF.
ENDMODULE. " PBO OUTPUT
MODULE pai INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
  WHEN 'EXIT' OR 'BACK' OR 'CANC'.
  PERFORM exit_program.
  WHEN OTHERS.
  CALL METHOD cl_gui_cfw=>dispatch.
  ENDCASE.
  CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " PAI INPUT
FORM change_label.
  READ TABLE lt_fieldcat ASSIGNING FIELD-SYMBOL(<id>) INDEX 1.
  <id>-seltext = <id>-reptext = <id>-scrtext_m = <id>-scrtext_s = <id>-scrtext_l = 'Hierarchy ID'.
  <id>-outputlen = 20.
  READ TABLE lt_fieldcat ASSIGNING FIELD-SYMBOL(<text>) INDEX 2.
  <text>-seltext = <text>-reptext = <text>-scrtext_m = <text>-scrtext_l = 'Description'.
  <text>-scrtext_s = 'Text'.
  <text>-outputlen = 40.
ENDFORM.
FORM init_tree.
  g_alv_tree = lo_tool->get_tree( ).
  DATA l_hierarchy_header TYPE treev_hhdr.
  PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
  CALL METHOD g_alv_tree->set_table_for_first_display
  EXPORTING
  is_hierarchy_header = l_hierarchy_header
  CHANGING
  it_fieldcatalog = lt_fieldcat
  it_outtab = gt_data.
  PERFORM create_tree.
  g_alv_tree->frontend_update( ).
  lo_tool->expand( ).
ENDFORM.
FORM create_tree.
  DATA(lt_data) = lo_tool->get_hierarchy_data( ).
  lo_tool->draw_tree( lt_data ).
ENDFORM. " init_tree
FORM build_hierarchy_header CHANGING p_hierarchy_header TYPE treev_hhdr.
  p_hierarchy_header-heading = 'Material hierarchy'.
  p_hierarchy_header-width = 30.
  p_hierarchy_header-width_pix = ' '.
ENDFORM. " build_hierarchy_header
FORM exit_program.
  LEAVE PROGRAM.
ENDFORM. " exit_program

In order to use the report, all you need is to just create a new screen :

/wp-content/uploads/2016/09/clipboard3_1033467.png

And drag a custom container to screen with name “CCONTAINER1”:

/wp-content/uploads/2016/09/clipboard4_1033468.png

The source code of utility class zcl_alv_tool could be found from this link.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. VINAY REDDY

    Hi Jerry Wang,

    thanks for your useful document,

    how do i book mark your blog post,

    also hot spot isn’t enabled when i hit like button.

    Note : While writing comments in the editor many times i have mistakenly selected CANCEL button as it is just left of SUBMIT COMMENT , i think the CANCEL button should be on extreme left to avoid this.

    regards,
    vinay reddy

    (0) 
  2. Veselina Peykova

    An interesting solution to a deeper problem… 🙂

    Recently, I faced the challenge to present the SAP product hierarchy in a user-friendly manner in an external application. The target group of users have prior experience with non-SAP software (some of which was built especially for their processes) and they have higher expectations for UI than most SAP GUI users.

    This might come as a surprise to some SAP experts, but business users don’t think of the hierarchy in the way it is presented here. For example, when speaking of the second hierarchy level, nobody cites the full code – only the part, which uniquely identifies it. Instead of 0000100002, they will tell you that Compressors is 00002. In fact, if you try to enforce numbers-only hierarchy, people will start complaining, that it is too hard to memorize these and ask for TCO2 or something similar.

    As the product hierarchy was expected to be retrieved from SAP, but also returned to other systems, I had to explain to a non-SAP colleague why we needed an additional development to present the information in a way, which makes sense to the business. Needless to say, my colleague was shocked to see how the data is actually stored in T179. I was unable to come up with a logical explanation why the product hierarchy was designed in such way, considering that customer hierarchy in KNVH follows a different concept. And I also struggle to explain to the business people why, despite the fact that you set PRODH in MVKE (sales area data level), you don’t actually define product hierarchy per sales area.

    Why I need to explain this to others? Because we have some uncommon processes, where the user has to specify manually the product hierarchy at document creation.

    And it is a very common business requirement, that you present product hierarchy in sales documents lists reports (ALV grid-based) in separate sections – one field for highest level, another for second level, another for the third one (00001|00001|00001 with their descriptions in separate fields). Most users, with whom I have spoken, don’t like tree control in reports – they want to sort, filter, make subtotals. If I try to present a mockup for a tree-based report to our users, they would simply tell me: “We are not going to pay for that, we can’t use it”.

    (2) 

Leave a Reply