Grafischer Belegfluß

Auf http://www.erpgenie.com wurde ein Programm bereitgestellt, mit dem man den Belegfluss zu Belegen grafisch darstellen kann. Es ist ein sehr nettes Tool, das vielleicht bei der täglichen Arbeit weiter hilft.

Das hier vorgestellte Coding ist leicht verschlankt. Eine Version mit Doppelklick-Funktionalität und Screenshots sehen Sie bei ERPgenie.

Screenshot

Belegfluss für Aufträge

Coding

*Sales Order Flow - Tree Report
REPORT z_sales_tree_rpt .
*http://www.erpgenie.com/sap/abap/SalesOrderFlow.htm

* Table Definitions
TABLES: vbak,            "Sales Document: Header Data
        vbfa.            "Sales Document Flow

* Type definitions
TYPES: BEGIN OF itab_type,
         folder   TYPE flag,
         node_key TYPE mtreeitm,
         relatkey TYPE tv_nodekey,
         type     LIKE vbak-vbtyp,
         vbeln    LIKE vbak-vbeln,
         posnn    LIKE vbfa-posnn,
         rfmng(10) TYPE c,
         rfwrt(12) TYPE c,
       END OF itab_type.

TYPES: BEGIN OF sel_type,
         vbeln    LIKE vbak-vbeln,
         vbtyp    LIKE vbak-vbtyp,
       END OF sel_type.

* Data Definitions
DATA: okcode    LIKE sy-ucomm,
      itab_data TYPE itab_type OCCURS 0,
      itab_selection TYPE sel_type OCCURS 0.
DATA: BEGIN OF it_vbfa OCCURS 0.
        INCLUDE STRUCTURE vbfa.
DATA: END OF it_vbfa,

      is_vbfa   LIKE LINE OF it_vbfa,
      is_vbc06  LIKE vbco6,
      wa_vbelv  LIKE vbfa-vbelv,
      wj_vbelv  LIKE vbfa-vbelv,
      wa_posnv  LIKE vbfa-posnv,
      wj_posnv  LIKE vbfa-posnv,
      wa_nodekey TYPE tv_nodekey,
      t_screen(3) TYPE c,
      t_dynnr LIKE sy-dynnr,
      wa_data   TYPE itab_type.

* Tree list definitions

CLASS cl_gui_cfw      DEFINITION LOAD.

TYPES: item_table_type LIKE STANDARD TABLE OF mtreeitm  WITH DEFAULT KEY.

DATA: g_custom_container TYPE REF TO cl_gui_custom_container,
      g_tree             TYPE REF TO cl_gui_list_tree,
      g_ok_code          TYPE sy-ucomm.

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

SELECTION-SCREEN BEGIN OF BLOCK a0 WITH FRAME TITLE text-001.

SELECT-OPTIONS:
  s_vbeln FOR vbak-vbeln,
  s_erdat FOR vbak-erdat,
  s_ernam FOR vbak-ernam.
PARAMETERS: p_vbtyp LIKE vbfa-vbtyp_n DEFAULT 'C'.

SELECTION-SCREEN END OF BLOCK a0.

*----------------------------------------------------------------------*
* 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.
    CALL SCREEN 2000.
  ENDIF.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Form  create_and_init_tree
*&---------------------------------------------------------------------*
FORM create_and_init_tree.

  DATA: node_table TYPE treev_ntab,
        item_table TYPE item_table_type.

* create a container for the tree control
  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = 'TREE_CONTROL'.

* 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       = ' '.

  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'.

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_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-node_key.
    item-item_name  = '1'.
    item-length     = 10.
    item-class      = cl_gui_list_tree=>item_class_text. " Text Item
    item-alignment  = cl_gui_list_tree=>align_auto.
    item-font       = cl_gui_list_tree=>item_font_prop.
    CASE wa_data-type.
      WHEN 'C'.
        item-text = 'Order'.
      WHEN 'J'.
        item-text = 'Delivery'.
      WHEN 'M'.
        item-text = 'Invoice'.
      WHEN '+'.
        item-text = 'Payment'.
      WHEN 'Q'.
        item-text = 'Warehouse Xfer'.
      WHEN 'R'.
        item-text = 'Goods Mvmt'.
      WHEN 'H'.
        item-text = 'Return Gds'.
    ENDCASE.
    APPEND item TO item_table.

    CLEAR item.
    item-node_key   = wa_data-node_key-node_key.
    item-item_name  = '2'.
    item-length     = 10.
    item-class      = cl_gui_list_tree=>item_class_text. " Text Item
    item-alignment  = cl_gui_list_tree=>align_auto.
    item-font       = cl_gui_list_tree=>item_font_prop.
    item-text       = wa_data-vbeln.
    APPEND item TO item_table.

    CLEAR item.
    item-node_key   = wa_data-node_key-node_key.
    item-item_name  = '3'.
    item-length     = 6.
    item-class      = cl_gui_list_tree=>item_class_text. " Text Item
    item-alignment  = cl_gui_list_tree=>align_auto.
    item-font       = cl_gui_list_tree=>item_font_prop.
    item-text       = wa_data-posnn.
    APPEND item TO item_table.

    CLEAR item.
    item-node_key   = wa_data-node_key-node_key.
    item-item_name  = '4'.
    item-length     = 10.
    item-class      = cl_gui_list_tree=>item_class_text. " Text Item
    item-alignment  = cl_gui_list_tree=>align_auto.
    item-font       = cl_gui_list_tree=>item_font_prop.
    item-text       = wa_data-rfmng.
    APPEND item TO item_table.

    CLEAR item.
    item-node_key   = wa_data-node_key-node_key.
    item-item_name  = '5'.
    item-length     = 10.
    item-class      = cl_gui_list_tree=>item_class_text. " Text Item
    item-alignment  = cl_gui_list_tree=>align_auto.
    item-font       = cl_gui_list_tree=>item_font_prop.
    item-text       = wa_data-rfwrt.
    APPEND item TO item_table.

  ENDLOOP.

ENDFORM.                    " build_node_and_item_table

*&---------------------------------------------------------------------*
*&      Form  create_input_table
*&---------------------------------------------------------------------*
FORM create_input_table TABLES   p_itab_data LIKE itab_data
                                 p_itab_selection LIKE itab_selection.

  DATA: l_tabix LIKE sy-tabix,
        lm_tabix LIKE sy-tabix,
        BEGIN OF wl_data,
          vbeln   LIKE vbfa-vbeln,
          posnn   LIKE vbfa-posnn,
        END OF  wl_data,
        t_counter(4) TYPE n,
        t_parent(4) TYPE c,
        t_parent1(4) TYPE c,
        t_exit TYPE flag,
        is_del_data LIKE LINE OF itab_data,
        it_inv_data TYPE itab_type OCCURS 0.

  t_counter = 1.
  LOOP AT p_itab_selection.

    CLEAR: t_parent, t_parent1, t_exit.
    REFRESH it_vbfa.
    is_vbc06-vbeln = p_itab_selection-vbeln.
    CALL FUNCTION 'RV_ORDER_FLOW_INFORMATION'
      EXPORTING
        aufbereitung        = '2'
        comwa               = is_vbc06
        nachfolger          = 'X'
        n_stufen            = '50'
        vorgaenger          = 'X'
        v_stufen            = '50'
      TABLES
        vbfa_tab            =  it_vbfa
      EXCEPTIONS
        no_vbfa             = 1
        no_vbuk_found       = 2
        OTHERS              = 3.

    CLEAR: wa_data.
    wa_data-folder = 'X'.
    WRITE t_counter TO wa_data-node_key-node_key..
    wa_data-relatkey = t_parent.
    wa_data-type     = p_itab_selection-vbtyp.
    wa_data-vbeln    = p_itab_selection-vbeln.
    wa_data-posnn    = '0'.
    APPEND wa_data TO p_itab_data.
    t_parent = t_counter.
    ADD 1 TO t_counter.

* Find any deliveries for this order
    LOOP AT it_vbfa WHERE vbtyp_n = 'J'.      " Delivery

      CLEAR: wa_data.
      wa_data-folder = 'X'.
      WRITE t_counter TO wa_data-node_key-node_key..
      wa_data-relatkey = t_parent.
      wa_data-type     = it_vbfa-vbtyp_n.
      wa_data-vbeln    = it_vbfa-vbeln.
      wa_data-posnn    = it_vbfa-posnn.
      wa_data-rfmng    = it_vbfa-rfmng.
      is_del_data      = wa_data.
*
      t_parent1 = t_counter.
      ADD 1 TO t_counter.
      wa_vbelv  = it_vbfa-vbeln.
      wa_posnv  = it_vbfa-posnn.
      l_tabix   = sy-tabix.
* Find any invoices Warehouse xfers or Goods Movements for this delivery
      REFRESH: it_inv_data.
      LOOP AT it_vbfa WHERE vbelv = wa_vbelv
                      AND   posnv = wa_posnv.

        CASE it_vbfa-vbtyp_n.
          WHEN 'M'.    "Invoice
            CLEAR: wa_data.
            wa_data-folder = ' '.
            wa_data-node_key-node_key = t_counter.
            wa_data-relatkey = t_parent1.
            wa_data-type     = it_vbfa-vbtyp_n.
            wa_data-vbeln    = it_vbfa-vbeln.
            wa_data-posnn    = it_vbfa-posnn.
            wa_data-rfmng    = it_vbfa-rfmng.
            wa_data-rfwrt    = it_vbfa-rfwrt.
            APPEND wa_data TO it_inv_data.
            wj_vbelv         = it_vbfa-vbeln.
            wj_posnv         = it_vbfa-posnn.
            wa_nodekey       = wa_data-node_key.
            DESCRIBE TABLE it_inv_data LINES lm_tabix.
            ADD 1 TO t_counter.
            PERFORM get_payment  TABLES it_inv_data USING t_counter.
            PERFORM get_returns  TABLES it_inv_data USING t_counter.
            DESCRIBE TABLE it_inv_data LINES l_tabix.
            IF l_tabix > lm_tabix.
              READ TABLE it_inv_data INDEX lm_tabix INTO wa_data.
              wa_data-folder = 'X'.
             MODIFY it_inv_data INDEX lm_tabix FROM wa_data.
            ENDIF.

          WHEN 'Q' OR 'R'.    " WMS transfer, or Goods Mvmt
            CLEAR: wa_data.
            wa_data-folder = ' '.
            wa_data-node_key-node_key = t_counter.
            wa_data-relatkey = t_parent1.
            wa_data-type     = it_vbfa-vbtyp_n.
            wa_data-vbeln    = it_vbfa-vbeln.
            wa_data-posnn    = it_vbfa-posnn.
            wa_data-rfmng    = it_vbfa-rfmng.
            APPEND wa_data TO it_inv_data.
            ADD 1 TO t_counter.
          WHEN OTHERS.
        ENDCASE.

      ENDLOOP.              " finding any matching invoices
      IF it_inv_data IS INITIAL.
        is_del_data-folder = ' '.
      ENDIF.
     APPEND is_del_data TO p_itab_data.
     APPEND LINES OF it_inv_data TO p_itab_data.
      REFRESH: it_inv_data.
    ENDLOOP.                " finding any deliveries

  ENDLOOP.
  CLEAR: t_parent, t_parent1, t_exit.

ENDFORM.                    " create_input_table

*&---------------------------------------------------------------------*
*&      Form  update_selection_table
*&---------------------------------------------------------------------*
FORM update_selection_table TABLES  itab_selection.

  IF NOT s_ernam IS INITIAL OR
     NOT s_erdat IS INITIAL OR
     NOT p_vbtyp IS INITIAL OR
     NOT s_vbeln IS INITIAL.

    SELECT vbeln vbtyp INTO CORRESPONDING FIELDS OF
    TABLE  itab_selection
    FROM   vbak
    WHERE vbeln IN s_vbeln AND
          erdat IN s_erdat AND
          ernam IN s_ernam AND
          vbtyp =  p_vbtyp.
  ENDIF.

ENDFORM.                    " update_selection_table

*&---------------------------------------------------------------------*
*&      Form  get_payment
*&---------------------------------------------------------------------*
FORM get_payment  TABLES it_inv_data USING pt_counter .

  LOOP AT it_vbfa WHERE vbelv = wj_vbelv
                  AND   posnv = wj_posnv
                  AND   vbtyp_n = '+'.
    wa_data-folder = ' '.
    wa_data-relatkey = wa_nodekey.
    wa_data-node_key-node_key = pt_counter.
    wa_data-type     = it_vbfa-vbtyp_n.
    wa_data-vbeln    = it_vbfa-vbeln.
    wa_data-posnn    = it_vbfa-posnn.
    wa_data-rfmng    = it_vbfa-rfmng.
    wa_data-rfwrt    = it_vbfa-rfwrt.
    APPEND wa_data TO it_inv_data.
    ADD 1 TO pt_counter.
  ENDLOOP.

ENDFORM.                    " get_payment

*&---------------------------------------------------------------------*
*&      Form  get_returns
*&---------------------------------------------------------------------*
FORM get_returns   TABLES it_inv_data USING pt_counter .

  DATA: ld_rfwrt(11) TYPE c,
        ld_tabix LIKE sy-tabix.

  LOOP AT it_vbfa WHERE vbelv = wj_vbelv
                  AND   posnv = wj_posnv
                  AND   vbtyp_n = 'H'.
    ld_tabix         = sy-tabix.
    wa_data-folder   = ' '.
    wa_data-relatkey = wa_nodekey.
    wa_data-node_key-node_key = pt_counter.
    wa_data-type     = it_vbfa-vbtyp_n.
    wa_data-vbeln    = it_vbfa-vbeln.
    wa_data-posnn    = it_vbfa-posnn.
    wa_data-rfmng    = it_vbfa-rfmng.
    ld_rfwrt         = it_vbfa-rfwrt.
    CONCATENATE ld_rfwrt '-' INTO  ld_rfwrt.
    wa_data-rfwrt    = ld_rfwrt.
    APPEND wa_data TO it_inv_data.
    ADD 1 TO pt_counter.
  ENDLOOP.

ENDFORM.                    "get_returns

*&---------------------------------------------------------------------*
*&      Module  STATUS_2000  OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2000 OUTPUT.

  SET PF-STATUS 'Z_SALES_TREE_2000'.
  SET TITLEBAR 'Z_SALES_TREE_2000'.

ENDMODULE.                 " STATUS_2000  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  init_data_2000  OUTPUT
*&---------------------------------------------------------------------*
MODULE init_data_2000 OUTPUT.

  IF g_tree IS INITIAL.
    PERFORM create_and_init_tree.
  ENDIF.

ENDMODULE.                    "init_data_2000 OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_2000  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_2000 INPUT.

  DATA: return_code TYPE i.

  CALL METHOD cl_gui_cfw=>dispatch
    IMPORTING
      return_code = return_code.

  IF return_code <> cl_gui_cfw=>rc_noevent.
    CLEAR okcode.
    EXIT.
  ENDIF.

  CASE okcode.
    WHEN 'EXIT' OR 'RETURN'. " Finish program
      IF NOT g_custom_container IS INITIAL.
        " destroy tree container (detroys contained tree control, too)
        CALL METHOD g_custom_container->free
          EXCEPTIONS
            cntl_system_error = 1
            cntl_error        = 2.
        IF sy-subrc <> 0.
          MESSAGE a000(tree_control_msg).
        ENDIF.
        CLEAR g_custom_container.
        CLEAR g_tree.
      ENDIF.
      LEAVE TO SCREEN 0.
  ENDCASE.

  CLEAR okcode.

ENDMODULE.                 " USER_COMMAND_2000  INPUT
Enno Wulff
Letzte Artikel von Enno Wulff (Alle anzeigen)