ABAP-OOALV

TOP

data:gt_alv_100 like table of ztmm0001_po_head.
field-symbols <fs_100> like ztmm0001_po_head.
data:gt_alv_200 like table of ztmm0002_po_item.
field-symbols <fs_200> like ztmm0002_po_item.


data:go_100_cc    type ref to cl_gui_custom_container,
     go_100_split type ref to cl_gui_splitter_container,
     go_101_split type ref to cl_gui_splitter_container.


data:go_200_cc   type ref to cl_gui_container,
     go_200_grid type ref to cl_gui_alv_grid.
data:gv_200_data type boolean,
     gv_200_fill type boolean,
     gv_200_refr type boolean.
data:gs_200_layout       type lvc_s_layo,
     gt_200_fcat         type lvc_t_fcat,
     gs_200_disvariant   type disvariant,
     gs_200_scroll_row   type lvc_s_roid,
     gs_200_scroll_col   type lvc_s_col,
     gt_200_selected_row type lvc_t_row,
     gt_200_toolbar_ex   type ui_functions.
field-symbols <fs_fcat_200> like lvc_s_fcat.


data:go_300_cc   type ref to cl_gui_container,
     go_300_grid type ref to cl_gui_alv_grid.
data:gv_300_data type boolean,
     gv_300_fill type boolean,
     gv_300_refr type boolean.
data:gs_300_layout       type lvc_s_layo,
     gt_300_fcat         type lvc_t_fcat,
     gs_300_disvariant   type disvariant,
     gs_300_scroll_row   type lvc_s_roid,
     gs_300_scroll_col   type lvc_s_col,
     gt_300_selected_row type lvc_t_row,
     gt_300_toolbar_ex   type ui_functions.
field-symbols <fs_fcat_300> like lvc_s_fcat.


data:go_400_cc   type ref to cl_gui_container,
     go_400_grid type ref to cl_gui_alv_grid.
data:gv_400_data type boolean,
     gv_400_fill type boolean,
     gv_400_refr type boolean.
data:gs_400_layout       type lvc_s_layo,
     gt_400_fcat         type lvc_t_fcat,
     gs_400_disvariant   type disvariant,
     gs_400_scroll_row   type lvc_s_roid,
     gs_400_scroll_col   type lvc_s_col,
     gt_400_selected_row type lvc_t_row,
     gt_400_toolbar_ex   type ui_functions.
field-symbols <fs_fcat_400> like lvc_s_fcat.

data:gs_stable  type lvc_s_stbl.

CLS

class cl_200_event_handler definition.
  public section.
    class-methods:
      handle_double_click
                    for event double_click of cl_gui_alv_grid
        importing e_row e_column es_row_no,
      handle_hotspot_click
                    for event hotspot_click of cl_gui_alv_grid
        importing e_row_id e_column_id es_row_no,
      handle_toolbar
                    for event toolbar of cl_gui_alv_grid
        importing e_object e_interactive,
      handle_user_command
                    for event user_command of cl_gui_alv_grid
        importing e_ucomm.
endclass.               "CL_EVENT_HANDLER

*&---------------------------------------------------------------------*
*&       Class (Implementation)  cl_event_handler
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
class cl_200_event_handler implementation.
  "双击行显示错误日志
  method handle_double_click.

    read table gt_alv_100 assigning <fs_100> index e_row-index.

    select ebeln ebelp
      into corresponding fields of table gt_alv_200
      from ztmm0002_po_item
      where ebeln eq <fs_100>-ebeln.

    perform frm_200_scr_refresh.

  endmethod.                    "handle_1100_data_changed

  method handle_hotspot_click.

  endmethod.                   "handle_1100_data_changed

  method handle_toolbar.
    field-symbols:
      <fs_s_tb> type stb_button.
*----------------------------------------------------------------------*
* 新增button
*----------------------------------------------------------------------*
*分隔符
    append initial line to e_object->mt_toolbar assigning <fs_s_tb>.
    <fs_s_tb>-butn_type = 3.
* 数据校验
    append initial line to e_object->mt_toolbar assigning <fs_s_tb>.
    <fs_s_tb>-butn_type = 0."0 button;2 button list.
    <fs_s_tb>-function = 'RECAL'.
    <fs_s_tb>-icon = icon_check.
    <fs_s_tb>-text = 'RECAL'.
* 确认执行
    append initial line to e_object->mt_toolbar assigning <fs_s_tb>.
    <fs_s_tb>-butn_type = 0."0 button;2 button list.
    <fs_s_tb>-function = 'EXEC'.
    <fs_s_tb>-icon = icon_execute_object.
    <fs_s_tb>-text = 'EXEC'.
  endmethod.                    "handle_toolbar

  method handle_user_command.

    "获取选中位置
    perform frm_100_get_cursor.
*
    perform frm_100_data_change.

*    case e_ucomm.
*      when 'RECAL'.
*      when 'EXEC'.
*      when '&IC1'.
*    endcase.
*
*    "数据刷新
    perform frm_100_scr_refresh.
  endmethod.                "handle_user_command
endclass.                    "cl_event_handler IMPLEMENTATION

PRO

start-of-selection.
  call screen 100.

FRM

*&---------------------------------------------------------------------*
*&      Form  FRM_200_BUILD_FCAT_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_200_build_fcat_list .
  define fieldcat.
    append initial line to gt_200_fcat assigning <fs_fcat_200>.
    <fs_fcat_200>-fieldname = &1.
    <fs_fcat_200>-coltext   = &2.
  end-of-definition.
  fieldcat: 'EBELN' '采购订单号'.
endform.
*&---------------------------------------------------------------------*
*&      Form  FRM_300_BUILD_FCAT_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_300_build_fcat_list .
  define fieldcat.
    append initial line to gt_300_fcat assigning <fs_fcat_300>.
    <fs_fcat_300>-fieldname = &1.
    <fs_fcat_300>-coltext   = &2.
  end-of-definition.
  fieldcat: 'EBELN' '采购订单号'.
  fieldcat: 'EBELP' '行项目'.
endform.
*&---------------------------------------------------------------------*
*&      Form  FRM_200_SCR_REFRESH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_200_scr_refresh .
  gs_stable-row = 'X'.
  gs_stable-col = 'X'.

  call method go_300_grid->refresh_table_display
    exporting
      is_stable = gs_stable
    exceptions
      finished  = 1
      others    = 2.
endform.
*&---------------------------------------------------------------------*
*&      Form  FRM_100_GET_CURSOR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_100_get_cursor .
  if go_200_grid is bound.
* 得到选中行
    go_200_grid->get_selected_rows(
      importing
        et_index_rows = gt_200_selected_row ).

* 得到位置
    go_200_grid->get_scroll_info_via_id(
       importing
         es_row_no      = gs_200_scroll_row
         es_col_info    = gs_200_scroll_col ).
  endif.
endform.
*&---------------------------------------------------------------------*
*&      Form  FRM_100_DATA_CHANGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_100_data_change .
  go_200_grid->check_changed_data( ).
endform.
*&---------------------------------------------------------------------*
*&      Form  FRM_100_SCR_REFRESH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_100_scr_refresh .
  gs_stable-row = 'X'.
  gs_stable-col = 'X'.

  call method go_200_grid->refresh_table_display
    exporting
      is_stable = gs_stable
    exceptions
      finished  = 1
      others    = 2.
endform.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.



endmodule.
*&---------------------------------------------------------------------*
*&      Module  SCR_300_DSP  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module scr_300_dsp output.

  if go_400_grid is not bound.
    create object go_400_grid exporting i_parent = go_400_cc.
  endif.

endmodule.

MOD

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status 'ST_100'.
  set titlebar 'T100'.
endmodule.
*&---------------------------------------------------------------------*
*&      Module  ALV_SCREEN_SPLIT  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module alv_screen_split output.

*  "alv splitter
  if go_100_split is not bound.
    if go_100_cc is not bound.
      create object go_100_cc
        exporting
          container_name = 'ALV_CON'.
    endif.

    create object go_100_split
      exporting
        parent  = go_100_cc
        rows    = 2
        columns = 1.

*    go_100_split->set_row_height(
*      exporting
*        id = 2
*        height = 28 ).
  endif.

  "alv 子屏幕
  if go_101_split is not bound.
    create object go_101_split
      exporting
        parent  = go_100_split->get_container( row = 1 column = 1 )
        rows    = 1
        columns = 2.
*
*    "alv 子屏幕
    if go_200_cc is not bound.
      go_200_cc = go_101_split->get_container( row = 1 column = 1 ).
    endif.

    if go_300_cc is not bound.
      go_300_cc = go_101_split->get_container( row = 1 column = 2 ).
    endif.

    if go_400_cc is not bound.
      go_400_cc = go_100_split->get_container( row = 2 column = 1 ).
    endif.
  endif.
endmodule.
*&---------------------------------------------------------------------*
*&      Module  SCR_100_INIT  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module scr_100_init output.

  if gv_200_data ne 'X'.
    select *
      up to 10 rows
      into corresponding fields of table gt_alv_100
      from ztmm0001_po_head.
    gv_200_data = 'X'.
  endif.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  SCR_100_DSP  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module scr_100_dsp output.
  if gv_200_fill <> 'X'.
*   创建Grid对象
    if go_200_grid is not bound.
      create object go_200_grid exporting i_parent = go_200_cc.
    endif.

**   创建Field Catalog
    perform frm_200_build_fcat_list.
*
**   创建toolbar excluding
*    perform frm_200_build_toolbar_ex.

*   创建layout
    gs_200_layout-cwidth_opt = 'X'."优化输出字段宽度
    gs_200_layout-sel_mode = 'A'. "允许行选择
*   gs_200_layout-box_fname  = 'CHECK'. "选择
*   gs_200_layout-no_toolbar = 'X'. "无按钮
*   gs_200_layout-ctab_fname = 'CELLCOLORS'."颜色字段
*   gs_200_layout-info_fname = 'ROWCOLOR'.

*   保存格式
    clear gs_200_disvariant.
    gs_200_disvariant-report = sy-repid.
    gs_200_disvariant-handle = '200'.
    gs_200_disvariant-username = sy-uname.

*  注册事件
    set handler cl_200_event_handler=>handle_double_click for go_200_grid.
    set handler cl_200_event_handler=>handle_toolbar for go_200_grid.
    set handler cl_200_event_handler=>handle_user_command for go_200_grid.
    set handler cl_200_event_handler=>handle_hotspot_click for go_200_grid.

*   第一次显示ALV
    go_200_grid->set_table_for_first_display(
      exporting
        is_variant           = gs_200_disvariant
        i_save               = 'U'
        is_layout            = gs_200_layout
        it_toolbar_excluding = gt_200_toolbar_ex
      changing
        it_fieldcatalog      = gt_200_fcat
        it_outtab            = gt_alv_100[] ).

    gv_200_refr = gv_200_fill = abap_true.
  else.
* 刷新ALV
    if gv_200_refr <> abap_true.
      go_200_grid->refresh_table_display( ).

      gv_200_refr = abap_true.
    endif.
* 设置选中行
    if gt_200_selected_row is not initial.
      go_200_grid->set_selected_rows(
        exporting
          it_index_rows = gt_200_selected_row ).
    endif.
* 设置位置
    if gs_200_scroll_row is not initial
      or gs_200_scroll_col is not initial.
      go_200_grid->set_scroll_info_via_id(
         exporting
           is_row_no      = gs_200_scroll_row
           is_col_info    = gs_200_scroll_col ).
    endif.
  endif.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  SCR_200_INIT  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module scr_200_init output.

*  suppress dialog.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  SCR_200_DSP  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module scr_200_dsp output.
  if gv_300_fill <> 'X'.
*   创建Grid对象
    if go_300_grid is not bound.
      create object go_300_grid exporting i_parent = go_300_cc.
    endif.

**   创建Field Catalog
    perform frm_300_build_fcat_list.
*
**   创建toolbar excluding
*    perform frm_300_build_toolbar_ex.

*   创建layout
    gs_300_layout-cwidth_opt = 'X'."优化输出字段宽度
    gs_300_layout-sel_mode = 'A'. "允许行选择
*   gs_200_layout-box_fname  = 'CHECK'. "选择
*   gs_200_layout-no_toolbar = 'X'. "无按钮
*   gs_200_layout-ctab_fname = 'CELLCOLORS'."颜色字段
*   gs_200_layout-info_fname = 'ROWCOLOR'.

*   保存格式
    clear gs_300_disvariant.
    gs_300_disvariant-report = sy-repid.
    gs_300_disvariant-handle = '200'.
    gs_300_disvariant-username = sy-uname.


*   第一次显示ALV
    go_300_grid->set_table_for_first_display(
      exporting
        is_variant           = gs_300_disvariant
        i_save               = 'U'
        is_layout            = gs_300_layout
        it_toolbar_excluding = gt_300_toolbar_ex
      changing
        it_fieldcatalog      = gt_300_fcat
        it_outtab            = gt_alv_200[] ).

    gv_300_refr = gv_300_fill = abap_true.
  else.
* 刷新ALV
    if gv_300_refr <> abap_true.
      go_300_grid->refresh_table_display( ).

      gv_300_refr = abap_true.
    endif.
* 设置选中行
    if gt_300_selected_row is not initial.
      go_300_grid->set_selected_rows(
        exporting
          it_index_rows = gt_300_selected_row ).
    endif.
* 设置位置
    if gs_300_scroll_row is not initial
      or gs_300_scroll_col is not initial.
      go_300_grid->set_scroll_info_via_id(
         exporting
           is_row_no      = gs_300_scroll_row
           is_col_info    = gs_300_scroll_col ).
    endif.
  endif.
endmodule.
*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module exit input.
  leave to screen 0.
endmodule.
*&---------------------------------------------------------------------*
*&      Module  SCR_300_INIT  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module scr_300_init output.
endmodule.

0100屏幕

process before output.
  module status_0100.
  module alv_screen_split.
  module scr_100_init.
  module scr_100_dsp.
  module scr_200_init.
  module scr_200_dsp.
  module scr_300_init.
  module scr_300_dsp.

process after input.
  module exit at exit-command .
  module user_command_0100.
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,921评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,635评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,393评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,836评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,833评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,685评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,043评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,694评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,671评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,670评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,779评论 1 332
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,424评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,027评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,984评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,214评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,108评论 2 351
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,517评论 2 343

推荐阅读更多精彩内容

  • 辩论会,也叫辩论赛,还有的叫做论辩赛。它在形式上是参赛双方就某一问题进行辩论的一种竞赛活动,实际上是围绕辩论的问题...
    李衍廷阅读 216评论 0 0
  • 1月31日,我一个人在TC的角落里,给爸爸打电话,还没开口就开始哽咽… 一个人在外面租房住了这么多年,第...
    云_有光阅读 532评论 0 0
  • 1 蒋勋先生总能把复杂的道理用他简洁优美的文体娓娓道来。《生活十讲》中的第九讲,蒋先生开讲情欲的世界。在我看来,情...
    阿玛阅读 746评论 0 0
  • 我现在记叙的是当下的日子。 十八岁,美好的岁月,离别的岁月。
    林抱朴阅读 182评论 0 0
  • 每个人, 都有自己的了不起。 你的优秀,不需要任何人来证明。 欣赏,自己 对别人生气1分钟, 就失去了自...
    安果果Lily阅读 132评论 0 1