ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 【转】利用ALVTree显示BOM结构

【转】利用ALVTree显示BOM结构

Linux操作系统 作者:5anc 时间:2016-05-26 11:40:56 0 删除 编辑

转自:http://blog.chinaunix.net/u1/40527/showart_1205851.html

*&---------------------------------------------------------------------*
*& Report  ZY_ALV_TREE_BOM                                             *
*&                                                                     *
*&---------------------------------------------------------------------*
*&      定义屏幕9000,在屏幕上定义一个“定制控制” ,名字为:TREE1
*&                                                                    
*&---------------------------------------------------------------------*

report  zy_alv_tree_bom   message-id oo    .

tables: stpox.
include <icon>.

class: cl_gui_column_tree definition load,
       cl_gui_cfw definition load .

data: tree1  type ref to cl_gui_alv_tree ,
      mr_toolbar type ref to cl_gui_toolbar .

data: gs_stpox       type stpox,
      gt_stpox       type stpox occurs 0,
      gt_fieldcatalog  type lvc_t_fcat,
      gt_item_layout   type lvc_t_laci,
      gs_item_layout   type lvc_s_laci,
      okcode           like sy-ucomm .

types: begin of gs_f.
        include structure stpox.
types:  node_key      type lvc_nkey,
       end   of gs_f.

data: gs_xstpox       type gs_f ,
      gt_xstpox       type gs_f occurs 0.
data: l_custom_container type ref to cl_gui_custom_container.

data:  wa_topmat type cstmat,
       wa_dstst type csdata-xfeld.
data: it_matcat type standard table of cscmat.

parameters: p_matnr like mara-matnr default '2000C071268',
            p_werks like ekpo-werks default '8010' .

start-of-selection.
  perform. getdata.
  call screen 9000.
*&---------------------------------------------------------------------*
*&      Form  getdata
*&---------------------------------------------------------------------*
form. getdata.
  call function 'CS_BOM_EXPL_MAT_V2'
    exporting
      capid                 = 'PP01'    " p_capid
      datuv                 = sy-datum
      mehrs                 = '1'        "p_mehrs
     " stlal                 = '01'     "可选BOM
      stlan                 = '1'      "BOM 用途
      mtnrv                 = p_matnr
      werks                 = p_werks
      emeng                 = 1
    importing
      topmat                = wa_topmat
      dstst                 = wa_dstst
    tables
      stb                   = gt_stpox
      matcat                = it_matcat
    exceptions
      alt_not_found         = 1
      call_invalid          = 2
      material_not_found    = 3
      missing_authorization = 4
      no_bom_found          = 5
      no_plant_data         = 6
      no_suitable_bom_found = 7
      conversion_error      = 8
      others                = 9.
  case sy-subrc .
    when 1 .
      message e899(fi) with 'alt_not_found'.
    when 2 .
      message e899(fi) with 'call_invalid '.
    when 3 .
      message e899(fi) with 'material_not_found'.
    when 4 .
      message e899(fi) with 'missing_authorization'.
    when 5 .
      message e899(fi) with 'no_bom_found'.
    when 6 .
      message e899(fi) with 'no_plant_data'.
    when 7 .
      message e899(fi) with 'no_suitable_bom_found'.
    when 8 .
      message e899(fi) with 'conversion_error'.
    when 9 .
      message e899(fi) with 'OTHERS Error'.
  endcase.
  loop at gt_stpox into gs_stpox.
    move-corresponding gs_stpox to gs_xstpox .
    append gs_xstpox to gt_xstpox.
  endloop.
endform.                    "getdata
*----------------------------------------------------------------------*
*  MODULE status_9000 OUTPUT
*----------------------------------------------------------------------*
module status_9000 output.
  set pf-status 'MAIN'.
  set titlebar 'TITLE'.
  if tree1 is initial.
    perform. init_tree.
  endif.
  call method cl_gui_cfw=>flush.
endmodule.                 " PBO_9000  OUTPUT
*----------------------------------------------------------------------*
*  MODULE user_command_9000 INPUT
*----------------------------------------------------------------------*
module user_command_9000 input.
  case okcode.
    when 'EXIT' or 'BACK' or 'CANC'.
      call method tree1->free.
      leave program .
    when others.
      call method cl_gui_cfw=>dispatch.
  endcase.
  clear okcode.
  call method cl_gui_cfw=>flush.
endmodule.                 " okcode  INPUT
*&---------------------------------------------------------------------*
*&      Form  init_tree
*&---------------------------------------------------------------------*
form. init_tree .
  perform. build_fieldcatalog.

  create object tree1
    exporting
*      parent                      = l_custom_container
      parent                      = cl_gui_container=>screen0
      node_selection_mode         = cl_gui_column_tree=>node_sel_mode_single
      item_selection              = 'X'
      no_html_header              = 'X'
      no_toolbar                  = ' '
    exceptions
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      illegal_node_selection_mode = 5
      failed                      = 6
      illegal_column_name         = 7.

  if sy-subrc <> 0.
    message e000 with '创建TREE错误'.
  endif.

  data l_hierarchy_header type treev_hhdr.

  perform. build_hierarchy_header changing l_hierarchy_header.

  data: ls_variant type disvariant.
  ls_variant-report = sy-repid.

  call method tree1->set_table_for_first_display
    exporting
      is_hierarchy_header = l_hierarchy_header
      i_background_id     = 'ALV_BACKGROUND'
      i_save              = 'A'
      is_variant          = ls_variant
    changing
      it_outtab           = gt_stpox "table must be emty !!
      it_fieldcatalog     = gt_fieldcatalog.

  data: l1 type lvc_nkey ,l2 type lvc_nkey ,l3 type lvc_nkey ,l4 type lvc_nkey ,
        l5 type lvc_nkey ,l6 type lvc_nkey ,l7 type lvc_nkey ,l8 type lvc_nkey ,
        l_key type lvc_nkey,
        l_last_key type lvc_nkey,
        added .

  loop at gt_xstpox into gs_xstpox .
    move-corresponding gs_xstpox to gs_stpox.
    case gs_stpox-stufe .
      when '1'.
        l_key = ''.
      when '2'.
        l_key = l1.
      when '3'.
        l_key = l2.
      when '4'.
        l_key = l3.
      when '5'.
        l_key = l4.
      when '6'.
        l_key = l5.
    endcase.

    perform. add_complete_line using  gs_stpox l_key
                              changing l_last_key.

    gs_xstpox-node_key = l_last_key.

    case gs_stpox-stufe .
      when '1'.
        l1 = l_last_key.
      when '2'.
        l2 = l_last_key.
      when '3'.
        l3 = l_last_key.
      when '4'.
        l4 = l_last_key.
      when '5'.
        l5 = l_last_key.
      when '6'.
        l6 = l_last_key.
    endcase.

    modify gt_xstpox from gs_xstpox .
  endloop.

  call method tree1->update_calculations.
  call method tree1->frontend_update.
endform.                    " init_tree
*&---------------------------------------------------------------------*
*&      Form  build_fieldcatalog
*&---------------------------------------------------------------------*
form. build_fieldcatalog.
  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      i_structure_name = 'STPOX'
    changing
      ct_fieldcat      = gt_fieldcatalog.

*  DATA: ls_fieldcatalog TYPE lvc_s_fcat.
*  LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
**    CASE ls_fieldcatalog-fieldname.
**      WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'.
**        ls_fieldcatalog-no_out = 'X'.
**        ls_fieldcatalog-key    = ''.
**      WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'.
***        ls_fieldcatalog-do_sum = 'X'.
**      WHEN 'PLANETYPE'.
**        ls_fieldcatalog-edit = 'X'.
**        ls_fieldcatalog-style. = cl_gui_alv_grid=>mc_style_enabled .
**    ENDCASE.
*    MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
*  ENDLOOP.
endform.                               " build_fieldcatalog
*&---------------------------------------------------------------------*
*&      Form  build_hierarchy_header
*&---------------------------------------------------------------------*
form. build_hierarchy_header changing
                               p_hierarchy_header type treev_hhdr.
*
  p_hierarchy_header-heading = 'BOM层次'.
  p_hierarchy_header-tooltip = 'ToolTip'.
  p_hierarchy_header-width = 30.
  p_hierarchy_header-width_pix = ''.
*
endform.                               " build_hierarchy_header
*&---------------------------------------------------------------------*
*&      Form  add_complete_line
*&---------------------------------------------------------------------*
form. add_complete_line using  ps_stpox type stpox
                               p_relat_key type lvc_nkey
                     changing  p_node_key type lvc_nkey.
  data: l_node_text type lvc_value.
* set item-layout
  data: lt_item_layout type lvc_t_layi,
        ls_item_layout type lvc_s_layi.
  data: stufe_num(2) type n.

  ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
  ls_item_layout-class     = cl_gui_column_tree=>item_class_text.
*  ls_item_layout-editable  = 'X'.
*  ls_item_layout-chosen    = 'X'.  " 设置为选中状态
  append ls_item_layout to lt_item_layout.

*  l_node_text =  ps_stpox-ojtxp.
  stufe_num = ps_stpox-stufe.
  concatenate stufe_num ',' ps_stpox-ojtxp into l_node_text.

  call method tree1->add_node
    exporting
      i_relat_node_key = p_relat_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      is_outtab_line   = ps_stpox
      i_node_text      = l_node_text
      it_item_layout   = lt_item_layout
    importing
      e_new_node_key   = p_node_key.
endform.                               " add_complete_line

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7411792/viewspace-2107259/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-06-05

  • 博文量
    4
  • 访问量
    4693