Sales Order Flow – Tree Report

report z_sales_tree_rpt .

 

*******************************************************************

*  Create a tree report of sales orders to deliveries to invoices *

*******************************************************************

include z_sales_tree_rpt_top.

include z_sales_tree_class_def.

 

selection-screen begin of block a0 with frame title text-001.

 

*selection-screen comment 5(60) text-c00 modif id sc1.

 

selection-screen begin of block b5 with frame title text-s05.

select-options:

  s_erdat for vbak-erdat,

  s_ernam for vbak-ernam.

parameters: s_vbtyp like vbfa-vbtyp_n default 'C'.

selection-screen end of block b5.

 

selection-screen end of block a0.

 

*----------------------------------------------------------------------*

* Initialization

*----------------------------------------------------------------------*

*at selection-screen output.

*  perform update_sel_screen_attributes.

 

*----------------------------------------------------------------------*

* Start of Selection

*----------------------------------------------------------------------*

start-of-selection.

 

  refresh: itab_data, itab_selection.

  perform update_selection_table tables itab_selection.

  perform create_input_table tables itab_data

                                    itab_selection.

 

  if not itab_data is initial.

* create the application object

* this object is needed to handle the ABAP Objects Events of Controls

    create object g_application.

    call screen 2000.

  else.

    message i043(z1).

  endif.

 

end-of-selection.

 

*----------------------------------------------------------------------*

* Includes

*----------------------------------------------------------------------*

  include z_sales_tree_forms.

 

  include z_sales_tree_pbo.

 

  include z_sale_tree_pai.


*----------------------------------------------------------------------*

*   INCLUDE Z_SALES_TREE_CLASS_DEF                                     *

*----------------------------------------------------------------------*

 class lcl_application definition.

  public section.

    methods:

      handle_node_double_click

        for event node_double_click

        of cl_gui_list_tree

        importing node_key,

      handle_expand_no_children

        for event expand_no_children

        of cl_gui_list_tree

        importing node_key,

      handle_item_double_click

        for event item_double_click

        of cl_gui_list_tree

        importing node_key item_name,

      handle_button_click

        for event button_click

        of cl_gui_list_tree

        importing node_key item_name,

      handle_link_click

        for event link_click

        of cl_gui_list_tree

        importing node_key item_name,

      handle_checkbox_change

        for event checkbox_change

        of cl_gui_list_tree

        importing node_key item_name checked.

endclass.

 

*---------------------------------------------------------------------*

*       CLASS lcl_application IMPLEMENTATION

*---------------------------------------------------------------------*

*       ........                                                      *

*---------------------------------------------------------------------*

class lcl_application implementation.

 

  method  handle_node_double_click.

    " this method handles the node double click event of the tree

    " control instance

 

    " show the key of the double clicked node in a dynpro field

    read table itab_data with key node_key = node_key into wa_data.

    if sy-subrc = 0.

      select single rfmng rfwrt matnr

        into (vbfa-rfmng, vbfa-rfwrt, vbfa-matnr)

        from vbfa

        where vbelv = wa_data-vbeln

        and   posnv = wa_data-posnn.

    endif.

  endmethod.

 

  method  handle_item_double_click.

    " this method handles the item double click event of the tree

    " control instance. You have variables node_key and item_name

 

    " show the key of the node and the name of the item

    " of the double clicked item in a dynpro field

    read table itab_data with key node_key = node_key into wa_data.

    if sy-subrc = 0.

      select single rfmng rfwrt matnr

        into (vbfa-rfmng, vbfa-rfwrt, vbfa-matnr)

        from vbfa

        where vbelv = wa_data-vbeln

        and   posnv = wa_data-posnn.

    endif.

 

  endmethod.

 

  method  handle_link_click.

    " this method handles the link click event of the tree

    " control instance

 

    " show the key of the node and the name of the item

    " of the clicked link in a dynpro field

*    g_event = 'LINK_CLICK'.

*    g_node_key = node_key.

*    g_item_name = item_name.

  endmethod.

 

  method  handle_button_click.

    " this method handles the button click event of the tree

    " control instance

 

    " show the key of the node and the name of the item

    " of the clicked button in a dynpro field

*    g_event = 'BUTTON_CLICK'.

*    g_node_key = node_key.

*    g_item_name = item_name.

  endmethod.

 

  method  handle_checkbox_change.

    " this method handles the checkbox_change event of the tree

    " control instance

 

    " show the key of the node and the name of the item

    " of the clicked checkbox in a dynpro field

*    g_event = 'CHECKBOX_CHANGE'.

*    g_node_key = node_key.

*    g_item_name = item_name.

  endmethod.

 

 

  method handle_expand_no_children.

    data: node_table type treev_ntab,

          node type treev_node,

          item_table type item_table_type,

          item type mtreeitm.

 

* show the key of the expanded node in a dynpro field

*    g_event = 'EXPAND_NO_CHILDREN'.

*    g_node_key = node_key.

 

    if node_key = 'Child2'.                                 "#EC NOTEXT

* add the children for node with key 'Child2'

* Node with key 'New3'

      clear node.

      node-node_key = 'New3'.                               "#EC NOTEXT

      node-relatkey = 'Child2'.

      node-relatship = cl_gui_list_tree=>relat_last_child.

      append node to node_table.

 

* Node with key 'New4'

      clear node.

      node-node_key = 'New4'.                               "#EC NOTEXT

      node-relatkey = 'Child2'.

      node-relatship = cl_gui_list_tree=>relat_last_child.

      append node to node_table.

 

* Items of node with key 'New3'

      clear item.

      item-node_key = 'New3'.

      item-item_name = '1'.

      item-class = cl_gui_list_tree=>item_class_text.

      item-length = 11.

      item-usebgcolor = 'X'. "

      item-text = 'SAPTROX1'.

      append item to item_table.

 

      clear item.

      item-node_key = 'New3'.

      item-item_name = '2'.

      item-class = cl_gui_list_tree=>item_class_text.

      item-alignment = cl_gui_list_tree=>align_auto.

      item-font = cl_gui_list_tree=>item_font_prop.

      item-text = 'Comment to SAPTROX1'.                    "#EC NOTEXT

      append item to item_table.

 

* Items of node with key 'New4'

      clear item.

      item-node_key = 'New4'.

      item-item_name = '1'.

      item-class = cl_gui_list_tree=>item_class_text.

      item-length = 11.

      item-usebgcolor = 'X'. "

      item-text = 'SAPTRIXTROX'.

      append item to item_table.

 

      clear item.

      item-node_key = 'New4'.

      item-item_name = '2'.

      item-class = cl_gui_list_tree=>item_class_text.

      item-alignment = cl_gui_list_tree=>align_auto.

      item-font = cl_gui_list_tree=>item_font_prop.

      item-text = 'Comment to SAPTRIXTROX'.                 "#EC NOTEXT

      append item to item_table.

    endif.

 

    call method g_tree->add_nodes_and_items

      exporting

        node_table = node_table

        item_table = item_table

        item_table_structure_name = 'MTREEITM'

      exceptions

        failed = 1

        cntl_system_error = 3

        error_in_tables = 4

        dp_error = 5

        table_structure_name_not_found = 6.

    if sy-subrc <> 0.

      message a000(tree_control_msg).

    endif.

  endmethod.

 

endclass.


*----------------------------------------------------------------------*

*   INCLUDE Z_SALES_TREE_FORMS                                         *

*----------------------------------------------------------------------*

*----------------------------------------------------------------------*

*&      Form  update_sel_screen_attributes

*&---------------------------------------------------------------------*

form update_sel_screen_attributes.

  loop at screen.

 

    if screen-group1 = 'SC1'.

      screen-intensified = '1'.

      modify screen.

    endif.

    if screen-group1 = 'ECR' and sy-tcode <> 'ZCMR'.

      if not sy-tcode = 'ZCM'.

        screen-invisible = '1'.

        screen-active = '0'.

        modify screen.

      endif.

    endif.

    if screen-group1 = 'ECN' and sy-tcode <> 'ZCMN'.

      if not sy-tcode = 'ZCM'.

        screen-invisible = '1'.

        screen-active = '0'.

        modify screen.

      endif.

    endif.

    if screen-group1 = 'ECO' and sy-tcode <> 'ZCMO'.

      if not sy-tcode = 'ZCM'.

        screen-invisible = '1'.

        screen-active = '0'.

        modify screen.

      endif.

    endif.

 

  endloop.

endform.                    " update_sel_screen_attributes

 

*&---------------------------------------------------------------------*

*&      Form  create_and_init_tree

*&---------------------------------------------------------------------*

form create_and_init_tree.

  data: node_table type treev_ntab,

        item_table type item_table_type,

        events type cntl_simple_events,

        event type cntl_simple_event.

 

* create a container for the tree control

  create object g_custom_container

    exporting

      " the container is linked to the custom control with the

      " name 'TREE_CONTROL' on the dynpro

      container_name = 'TREE_CONTROL'

    exceptions

      cntl_error = 1

      cntl_system_error = 2

      create_error = 3

      lifetime_error = 4

      lifetime_dynpro_dynpro_link = 5.

  if sy-subrc <> 0.

    message a000(tree_control_msg).

  endif.

 

 

* create a list tree control

  create object g_tree

    exporting

      parent              = g_custom_container

      node_selection_mode = cl_gui_list_tree=>node_sel_mode_single

      item_selection     = 'X'

      with_headers       = ' '

    exceptions

      cntl_system_error           = 1

      create_error                = 2

      failed                      = 3

      illegal_node_selection_mode = 4

      lifetime_error              = 5.

  if sy-subrc <> 0.

    message a000(tree_control_msg).

  endif.

 

* define the events which will be passed to the backend

  " node double click

  event-eventid = cl_gui_list_tree=>eventid_node_double_click.

  event-appl_event = 'X'.                                   "

  append event to events.

 

  " item double click

  event-eventid = cl_gui_list_tree=>eventid_item_double_click.

  event-appl_event = 'X'.

  append event to events.

 

  " expand no children

  event-eventid = cl_gui_list_tree=>eventid_expand_no_children.

  event-appl_event = 'X'.

  append event to events.

 

  " link click

  event-eventid = cl_gui_list_tree=>eventid_link_click.

  event-appl_event = 'X'.

  append event to events.

 

  " button click

  event-eventid = cl_gui_list_tree=>eventid_button_click.

  event-appl_event = 'X'.

  append event to events.

 

  " checkbox change

  event-eventid = cl_gui_list_tree=>eventid_checkbox_change.

  event-appl_event = 'X'.

  append event to events.

 

  call method g_tree->set_registered_events

    exporting

      events = events

    exceptions

      cntl_error                = 1

      cntl_system_error         = 2

      illegal_event_combination = 3.

  if sy-subrc <> 0.

    message a000(tree_control_msg).

  endif.

 

* assign event handlers in the application class to each desired event

  set handler g_application->handle_node_double_click for g_tree.

  set handler g_application->handle_item_double_click for g_tree.

  set handler g_application->handle_expand_no_children for g_tree.

  set handler g_application->handle_link_click for g_tree.

  set handler g_application->handle_button_click for g_tree.

  set handler g_application->handle_checkbox_change for g_tree.

 

* add some nodes to the tree control

* NOTE: the tree control does not store data at the backend. If an

* application wants to access tree data later, it must store the

* tree data itself.

 

  perform build_node_and_item_table using node_table item_table.

 

  call method g_tree->add_nodes_and_items

    exporting

      node_table = node_table

      item_table = item_table

      item_table_structure_name = 'MTREEITM'

    exceptions

      failed                         = 1

      cntl_system_error              = 3

      error_in_tables                = 4

      dp_error                       = 5

      table_structure_name_not_found = 6.

  if sy-subrc <> 0.

    message a000(tree_control_msg).

  endif.

 

endform.                    " create_and_init_tree

*&---------------------------------------------------------------------*

*&      Form  build_node_and_item_table

*&---------------------------------------------------------------------*

form build_node_and_item_table  using

                                       node_table type treev_ntab

                                       item_table type item_table_type.

  data: node type treev_node,

        item type mtreeitm.

 

* Build the node and item table.

  loop at itab_data into wa_data.

    clear node.

 

    node-node_key = wa_data-node_key.

    node-relatkey = wa_data-relatkey.

    node-isfolder = wa_data-folder.

    if wa_data-relatkey is initial.

      clear: node-relatship,

             node-exp_image,

             node-expander.

      node-hidden = ' '.

      node-disabled = ' '.

    else.

      node-relatship = cl_gui_list_tree=>relat_last_child.

    endif.

    append node to node_table.

 

* Update Items

    clear item.

    item-node_key = wa_data-node_key.

    item-item_name = '1'.

    item-length