alv 的面向对象实现

 program z_alv_grid_oo.

data: ok_code like sy-ucomm,
      save_ok like sy-ucomm,
      container_name   type scrfname value 'MYCONTAINER',
      grid1            type ref to cl_gui_alv_grid,
      grid_detail      type ref to cl_gui_alv_grid,
      custom_container type ref to cl_gui_custom_container,
      dialogbox_container type ref to cl_gui_dialogbox_container.

data: it_lfa1 like  table of lfa1,
      wa_lfa1 like line of it_lfa1,
      it_fieldscatalog type lvc_t_fcat,
      it_detail        type lvc_t_fcat,
      it_eina like table of eina,
      wa_fieldscatalog like line of it_fieldscatalog.

class lcl_event_receiver definition deferred.
data: event_receiver      type ref to lcl_event_receiver.

start-of-selection.

  wa_fieldscatalog-fieldname = 'LIFNR'.
  wa_fieldscatalog-scrtext_m = '供应商代码'.
*& 颜色变化
*  wa_fieldscatalog-emphasize = 'C710'.
  wa_fieldscatalog-emphasize = 'X'.
  append wa_fieldscatalog to it_fieldscatalog.

  wa_fieldscatalog-fieldname = 'NAME1'.
  wa_fieldscatalog-scrtext_m = '名称'.
  append wa_fieldscatalog to it_fieldscatalog.

  wa_fieldscatalog-fieldname = 'INFNR'.
  wa_fieldscatalog-scrtext_m = '信息记录号'.
  append wa_fieldscatalog to it_detail.
  wa_fieldscatalog-fieldname = 'MATNR'.
  wa_fieldscatalog-scrtext_m = '供应物料号'.
  append wa_fieldscatalog to it_detail.

end-of-selection.
  call screen 100.
*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_receiver definition.

  public section.
    methods:handle_double_click
            for event double_click of cl_gui_alv_grid
            importing e_row e_column,
           handle_close
           for event close of cl_gui_dialogbox_container
           importing sender.

  private section.
    data: dialogbox_status type c.

endclass.                    "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_receiver implementation.

  method handle_double_click.

    read table it_lfa1 index e_row-index into wa_lfa1 .

    select infnr matnr
    into corresponding fields of table it_eina
    from eina
    where lifnr = wa_lfa1-lifnr and
          loekz = ''.

    if dialogbox_status is initial.
      dialogbox_status = 'X'.
      perform create_detail_list.
    else.
      call method dialogbox_container->set_visible
        exporting
          visible = 'X'.
      call method grid_detail->refresh_table_display.
    endif.
  endmethod.                    "handle_double_click

  method handle_close.
    call method sender->set_visible
      exporting
        visible = space.
  endmethod.                    "handle_close
endclass.                    "lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
form exit_program.
  call method custom_container->free.
  call method cl_gui_cfw=>flush.
  leave program.
endform.                    "exit_program
*&---------------------------------------------------------------------*
*&      Module  PBO_100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module pbo_100 output.

  set pf-status 'ZGRID'.
  set titlebar 'ZGRID'.

  if custom_container is initial.

    create object custom_container
      exporting
        container_name              = container_name
      exceptions
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5.

    create object grid1
      exporting
        i_parent = custom_container.


    select *
    into table it_lfa1
    up to 60 rows
    from lfa1
    where lifnr > '0000000066'.

*& i_structure_name 和 it_fieldcatalog  有一个即可,I_STRUCTURE_NAME对应的ddic结构,it_fieldcatalog 为自定义的
*&  输出抬头目录
    call method grid1->set_table_for_first_display
      changing
        it_fieldcatalog = it_fieldscatalog
        it_outtab       = it_lfa1.
    create object event_receiver.
    set handler event_receiver->handle_double_click for grid1.
    call method cl_gui_control=>set_focus
      exporting
        control = grid1.
  endif.
endmodule.                             " PBO_100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  PAI_100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module pai_100 input.
  save_ok = ok_code.
  case save_ok.
    when 'BACK'.
      perform exit_program.
    when 'EXIT'.
      perform exit_program.
  endcase.
  clear save_ok.
endmodule.                             " PAI_100  INPUT

*&---------------------------------------------------------------------*
*&      Form  create_detail_list
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_detail_list.
* create dialogbox container as dynpro-instance
* When the user switches to another screen, it is
* destroyed by lifetime mangagement of CFW
  create object dialogbox_container
    exporting
      top      = 150
      left     = 150
      lifetime = cntl_lifetime_dynpro
      caption  = 'information_record!'(200)
      width    = 400
      height   = 200.
  create object grid_detail
    exporting
      i_parent = dialogbox_container.
  call method grid_detail->set_table_for_first_display
    changing
      it_fieldcatalog = it_detail
      it_outtab       = it_eina.
  call method cl_gui_control=>set_focus
    exporting
      control = grid_detail.

  set handler event_receiver->handle_close for dialogbox_container.
endform.                    " create_detail_list

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值