画1个屏幕:1001,分别再画2个自定义控件:CONT1以及CONT3.
TABLES t001w.
TYPES:BEGIN OF typ_t001w ,
werks TYPE t001w-werks,
name1 TYPE t001w-name1,
werks2 TYPE t001w-werks,
rowcolor TYPE char10,
zcheckbox TYPE c, "LAYOUT-CHECBOX = 'ZCHECKBOX'.
* zflag TYPE c, "LAYOUT-BOX_FNAME = 'ZFLAG'.
zicon TYPE char10, "LAYOUT-ICON = 'ZICON' 图标需要显示的
END OF typ_t001w.
TYPES:BEGIN OF typ_smf ,
werks TYPE t001w-werks,
name1 TYPE t001w-name1,
END OF typ_smf.
DATA:i_t001w TYPE TABLE OF typ_t001w,"""""第一次ALV内表
i_t001w1 TYPE TABLE OF typ_t001w,
i_detail TYPE TABLE OF typ_smf, """""单击ALV内表列ZICON显示的明细ALV内表
i_smf TYPE TABLE OF typ_smf.""""SF内表
DATA:fieldcat TYPE lvc_t_fcat,
fieldcat1 TYPE lvc_t_fcat,
grid TYPE REF TO cl_gui_alv_grid, "alv控件名
grid1 TYPE REF TO cl_gui_alv_grid,
grid2 TYPE REF TO cl_gui_alv_grid, "alv控件名
g_container TYPE scrfname VALUE 'CONT1',"重新定义本地容器对象名
g_container1 TYPE scrfname VALUE 'CONT3',
g_container2 TYPE scrfname VALUE 'CONT2',"重新定义本地容器对象名
is_layout TYPE lvc_s_layo,
ps_layout TYPE lvc_s_layo,
g_custom_container TYPE REF TO cl_gui_custom_container,
g_custom_container1 TYPE REF TO cl_gui_custom_container,
g_custom_container2 TYPE REF TO cl_gui_custom_container.
DATA: ui_functions TYPE ui_functions. "隐藏按钮的内表
*********ALV上事件捕捉类
DATA:gs_toolbar TYPE stb_button. "按钮
CLASS alv_event_receiver DEFINITION DEFERRED. "声明类对象
*----------------------------------------------------------------------*
* CLASS alv_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS alv_event_receiver DEFINITION. "声明类成员可见性
PUBLIC SECTION. "定义相关类成员可以被程序中的所有对象调用
CLASS-METHODS: "静态方法
handle_toolbar "初始化工具栏对象事件,如增加按钮并设定其属性
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
handle_menu_button "用于在下拉菜单中增加选项
FOR EVENT menu_button OF cl_gui_alv_grid
IMPORTING e_object e_ucomm,
handle_user_command "工具栏中的按钮的单击事件
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm,
handle_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid "屏幕中的单击事件,可以具体到某行某列,需要设置热点
IMPORTING e_row_id e_column_id es_row_no,
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid "屏幕中的双击事件,可以具体到某行某列,即使设置热点也必须双击
IMPORTING e_row e_column es_row_no.
ENDCLASS. "alv_event_receiver DEFINITION
*&---------------------------------------------------------------------*
*& Class (Implementation) alv_event_receiver
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
CLASS alv_event_receiver IMPLEMENTATION. "实现类方法
METHOD handle_toolbar.
gs_toolbar-function = 'B_SUM'. "为按钮分配功能码
gs_toolbar-icon = icon_display. "为按钮分配图标
gs_toolbar-text = '总行数'. "为按钮分配文本
gs_toolbar-butn_type = '0'. "定义按钮类型,不填时默认为0
APPEND gs_toolbar TO e_object->mt_toolbar. "添加按钮到工具栏
gs_toolbar-function = 'B_PRINT'. "为按钮分配功能码
gs_toolbar-icon = icon_import. "为按钮分配图标
gs_toolbar-text = '转储订单打印'. "为按钮分配文本
gs_toolbar-checked = 'X'.
gs_toolbar-butn_type = '0'. "定义按钮类型,不填时默认为0
APPEND gs_toolbar TO e_object->mt_toolbar. "添加按钮到工具栏
gs_toolbar-function = 'B_LIST'. "为按钮分配功能码
gs_toolbar-quickinfo = '自定义下拉菜单'.
gs_toolbar-icon = icon_biw_report_view. "为按钮分配图标
gs_toolbar-text = '下拉菜单'. "为按钮分配文本
gs_toolbar-butn_type = '1'. "定义按钮类型
APPEND gs_toolbar TO e_object->mt_toolbar. "添加按钮到工具栏
gs_toolbar-function = 'B_EDIT'. "为按钮分配功能码
gs_toolbar-icon = icon_change. "为按钮分配图标
gs_toolbar-text = '切换编辑状态'. "为按钮分配文本
gs_toolbar-checked = 'X'.
gs_toolbar-butn_type = '0'. "定义按钮类型,不填时默认为0
APPEND gs_toolbar TO e_object->mt_toolbar. "添加按钮到工具栏
ENDMETHOD. "handle_toolbar
METHOD handle_menu_button.
IF e_ucomm = 'B_LIST'.
CALL METHOD e_object->add_function
EXPORTING
icon = icon_display
fcode = 'B_SUM'
text = '显示ALV总数'.
ENDIF.
ENDMETHOD. "handle_menu_button
METHOD handle_user_command.
DATA sum TYPE i.
DATA text TYPE string.
DATA:lwa_t001w LIKE LINE OF i_t001w.
DATA: lwa_smf LIKE LINE OF i_smf.
CASE e_ucomm.
WHEN 'B_SUM'.
DESCRIBE TABLE i_t001w[] LINES sum.
text = sum.
CONCATENATE '当前表格中数据的总行数:' text INTO text.
MESSAGE text TYPE 'I'. "为何消息类型为 E 时运行时显示A类型,异常终止到初始界面
WHEN 'B_PRINT'.
WHEN 'B_EDIT'.
IF grid->is_ready_for_input( ) EQ 0.
CALL METHOD grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ELSE.
CALL METHOD grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "handle_user_command
"ALV内表展示处单击事件捕捉,需要设置热点对单击列字段
METHOD handle_hotspot_click.
DATA:lwa_t001w LIKE LINE OF i_t001w.
DATA: lwa_t001w1 LIKE LINE OF i_t001w.
READ TABLE i_t001w INTO lwa_t001w INDEX es_row_no-row_id. "判断行号
LOOP AT i_t001w INTO lwa_t001w.
READ TABLE i_t001w INTO lwa_t001w INDEX es_row_no-row_id.
IF lwa_t001w-zcheckbox = 'X'..
lwa_t001w-zcheckbox = ' '.
ELSEIF lwa_t001w-zcheckbox = ' '.
lwa_t001w-zcheckbox = 'X'.
ENDIF.
MODIFY i_t001w FROM lwa_t001w INDEX es_row_no-row_id.
CLEAR lwa_t001w.
ENDLOOP.
CALL METHOD grid->refresh_table_display.
CASE e_column_id-fieldname . "判断列名
WHEN 'NAME1'.
CALL TRANSACTION 'ME51N' AND SKIP FIRST SCREEN. "随便写的
WHEN 'ZCHECKBOX'.
* LOOP AT i_t001w INTO lwa_t001w WHERE zcheckbox = 'X'.
* LOOP AT i_t001w1 INTO lwa_t001w1 WHERE werks = lwa_t001w-werks.
* lwa_t001w1-zcheckbox = 'X'.
* MODIFY i_t001w1 FROM lwa_t001w1 INDEX sy-tabix.
* CLEAR lwa_t001w1.
* ENDLOOP.
LOOP AT I_T001W1 INTO LWA_T001W1.
READ TABLE I_T001W INTO LWA_T001W WITH KEY WERKS = LWA_T001W1.
IF SY-SUBRC = 0.
LWA_T001W1-ZCHECKBOX = LWA_T001W-ZCHECKBOX.
ENDIF.
MODIFY i_t001w1 FROM lwa_t001w1 INDEX sy-tabix.
CLEAR: lwa_t001w,LWA_T001W1.
ENDLOOP.
CALL METHOD grid1->refresh_table_display.
WHEN 'ZICON'. "
SELECT werks
name1
INTO TABLE i_detail
FROM t001w
WHERE werks = lwa_t001w-werks2.
CLEAR lwa_t001w.
IF sy-subrc NE 0.
MESSAGE 'No result finding!' TYPE 'I'.
ELSE.
CALL SCREEN 1002.
ENDIF.
WHEN OTHERS.
ENDCASE.
* MESSAGE i001(00) WITH '当前行:' es_row_no-row_id ',航线代码:' ls_lt001w-werks.
ENDMETHOD. "handle_hotspot_click
"ALV内表展示处双击击事件捕捉,如果设置热点双击不起作用
METHOD handle_double_click.
DATA:lwa_t001w LIKE LINE OF i_t001w.
READ TABLE i_t001w INTO lwa_t001w INDEX es_row_no-row_id.
IF e_column-fieldname = 'WERKS'.
SET PARAMETER ID 'AUN' FIELD lwa_t001w-werks.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
ENDMETHOD. "handle_double_click
ENDCLASS. "alv_event_receiver
START-OF-SELECTION.
CALL SCREEN 1001.
*&---------------------------------------------------------------------*
*& Module STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1001 OUTPUT.
SET PF-STATUS 'T001'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_1001 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
FIELD-SYMBOLS <field> TYPE typ_t001w .
DATA: i TYPE i VALUE 0.
DATA ok_code TYPE sy-ucomm.
ok_code = sy-ucomm.
CLEAR sy-ucomm.
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EDIT'.
IF grid->is_ready_for_input( ) EQ 0.
CALL METHOD grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.
ELSE.
CALL METHOD grid->set_ready_for_input
EXPORTING
i_ready_for_input = 0.
ENDIF.
WHEN 'EXECU'.
SELECT * FROM t001w
INTO CORRESPONDING FIELDS OF TABLE i_t001w.
LOOP AT i_t001w ASSIGNING <field> .
<field>-werks2 = <field>-werks.
<field>-zicon = '@16@'. "图标
ENDLOOP.
SELECT * FROM t001w
INTO CORRESPONDING FIELDS OF TABLE i_t001w1.
LOOP AT i_t001w1 ASSIGNING <field> .
<field>-werks2 = <field>-werks.
<field>-zicon = '@16@'. "图标
ENDLOOP.
IF g_custom_container IS INITIAL.
PERFORM exclude_tb_functions CHANGING ui_functions. "隐藏某些按钮
PERFORM frm_layout_set.
PERFORM frm_fieldcat_set.
PERFORM alv_show.
ELSE.
CALL METHOD grid->refresh_table_display. "刷新
ENDIF.
IF g_custom_container1 IS INITIAL.
PERFORM exclude_tb_functions CHANGING ui_functions. "隐藏某些按钮
PERFORM frm_layout_set.
PERFORM frm_fieldcat_set1.
PERFORM alv_show2.
ELSE.
CALL METHOD grid1->refresh_table_display. "刷新
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDMODULE. " USER_COMMAND_1001 INPUT
*&---------------------------------------------------------------------*
*& Form ALV_SHOW
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_show .
CREATE OBJECT g_custom_container "创建容器对象
EXPORTING container_name = g_container.
CREATE OBJECT grid "创建ALV对象
EXPORTING i_parent = g_custom_container.
CALL METHOD grid->register_edit_event "可编辑回传方法
EXPORTING
i_event_id = grid->mc_evt_modified.
CALL METHOD grid->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME = 'T001W'
* IS_VARIANT =
i_save = 'X'
* I_DEFAULT = 'X'
is_layout = is_layout
* IS_PRINT =
* IT_SPECIAL_GROUPS =
it_toolbar_excluding = ui_functions[]
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = i_t001w[]
it_fieldcatalog = fieldcat[].
* IT_SORT =
* IT_FILTER =
* EXCEPTIONS
* INVALID_PARAMETER_COMBINATION = 1
* PROGRAM_ERROR = 2
* TOO_MANY_LINES = 3
* others = 4
.
******注册ALV中引用的事件
SET HANDLER alv_event_receiver=>handle_toolbar
alv_event_receiver=>handle_menu_button
alv_event_receiver=>handle_user_command
alv_event_receiver=>handle_hotspot_click
alv_event_receiver=>handle_double_click
FOR ALL INSTANCES.
****调用方法激活自定义工具对象
CALL METHOD grid->set_toolbar_interactive.
ENDFORM. " ALV_SHOW
*&---------------------------------------------------------------------*
*& Form exclude_tb_functions
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PT_EXCLUDE text
*----------------------------------------------------------------------*
FORM exclude_tb_functions CHANGING pt_exclude TYPE ui_functions .
DATA ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_filter . "过滤器
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_current_variant . "布局更改
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average ."平均值
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum ."求和
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_export . "导出
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut . "剪切
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row . "删除行
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row . "插入行
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_refresh . "刷新
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_find ."查找
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc . "升序排列
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc . "降序排列
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_views . "视图
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print ."打印
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail . "详细按钮
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph . "显示图形
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info . "最终用户文档
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row . "附加行
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row . "复制行
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy . "复制文本
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo . "撤消
APPEND ls_exclude TO pt_exclude.
ENDFORM . "exclude_tb_functions
*&---------------------------------------------------------------------*
*& Form FRM_LAYOUT_SET
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_layout_set .
is_layout-zebra = 'X' .
is_layout-grid_title = '仓储转储订单跟踪及打印' .
is_layout-smalltitle = 'X' . "ALV 控制: 标题大小
is_layout-cwidth_opt = 'X' . "优化列宽
* is_layout-no_toolbar = 'X' . "隐藏按钮
is_layout-sel_mode = 'A' . "flag选择方式 A:行和列的选择,无法选择单元格 多行,多列 B
is_layout-info_fname = 'ROWCOLOR'.
ENDFORM. " FRM_LAYOUT_SET
*&---------------------------------------------------------------------*
*& Form FRM_FIELDCAT_SET
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_fieldcat_set .
DATA ls_fcat TYPE lvc_s_fcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'ZCHECKBOX' .
ls_fcat-coltext = '选择'.
* ls_fcat-emphasize = 'C601' ."列颜色控制
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'WERKS' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '4' .
ls_fcat-coltext = '工厂'."Carrier ID.列标题
ls_fcat-seltext = 'AAA' ."ALV 控制: 对话功能的列标识符
ls_fcat-emphasize = 'C601' ."列颜色控制
* ls_fcat-hotspot = 'X'. “不能设置hotspot 否则double click事件无效
APPEND ls_fcat TO fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'NAME1' .
ls_fcat-ref_table = 'T001W' .
ls_fcat-ref_field = 'NAME1' .
ls_fcat-outputlen = '30' .
ls_fcat-coltext = '工厂名称' .
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'WERKS2' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '4' .
ls_fcat-coltext = '工厂2号'."Carrier ID.列标题
ls_fcat-seltext = 'AAA' ."ALV 控制: 对话功能的列标识符
ls_fcat-emphasize = 'C601' ."列颜色控制
ls_fcat-edit = 'X'.
APPEND ls_fcat TO fieldcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'ZICON' .
ls_fcat-coltext = '交货明细凭证'."Carrier ID.列标题
ls_fcat-seltext = 'AAA' ."ALV 控制: 对话功能的列标识符
ls_fcat-icon = 'X'.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO fieldcat .
CLEAR ls_fcat .
ENDFORM. " FRM_FIELDCAT_SET
*&---------------------------------------------------------------------*
*& Form FRM_PRINT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_print_data .
ENDFORM. " FRM_PRINT_DATA
*&---------------------------------------------------------------------*
*& Module STATUS_1002 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_1002 OUTPUT.
SET PF-STATUS 'T001'.
* SET TITLEBAR 'xxx'.
PERFORM frm_alv_show_detail.
ENDMODULE. " STATUS_1002 OUTPUT
*&---------------------------------------------------------------------*
*& Form FRM_ALV_SHOW_DETAIL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM frm_alv_show_detail .
DATA: ls_fcat TYPE lvc_s_fcat ,
fieldcat2 TYPE lvc_t_fcat.
ls_fcat-fieldname = 'WERKS' .
ls_fcat-coltext = '工厂'."Carrier ID.列标题
APPEND ls_fcat TO fieldcat2 .
CLEAR ls_fcat .
ls_fcat-fieldname = 'NAME1' .
ls_fcat-coltext = '工厂名称'.
APPEND ls_fcat TO fieldcat2 .
CLEAR ls_fcat .
ps_layout-zebra = 'X' .
ps_layout-grid_title = '交货明细凭证' .
ps_layout-smalltitle = 'X' . "ALV 控制: 标题大小
ps_layout-cwidth_opt = 'X' . "优化列宽
ps_layout-no_toolbar = 'X' . "隐藏按钮
* ps_layout-SEL_MODE = 'A' . "flag选择方式 A:行和列的选择,无法选择单元格 多行,多列 B
* ps_layout-info_fname = 'ROWCOLOR'.
IF g_custom_container2 IS INITIAL.
CREATE OBJECT g_custom_container2 "创建容器对象
EXPORTING container_name = g_container2.
CREATE OBJECT grid2 "创建ALV对象
EXPORTING i_parent = g_custom_container2.
ELSE.
CALL METHOD grid2->refresh_table_display. "刷新
ENDIF.
CALL METHOD grid2->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME = 'T001W'
* IS_VARIANT =
i_save = 'X'
* I_DEFAULT = 'X'
is_layout = ps_layout
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = i_detail[]
it_fieldcatalog = fieldcat2[].
* IT_SORT =
* IT_FILTER =
* EXCEPTIONS
* INVALID_PARAMETER_COMBINATION = 1
* PROGRAM_ERROR = 2
* TOO_MANY_LINES = 3
* others = 4
.
ENDFORM. " FRM_ALV_SHOW_DETAIL
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_1002 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_1002 INPUT.
DATA ok_code2 TYPE sy-ucomm.
ok_code2 = sy-ucomm.
CLEAR sy-ucomm.
CASE ok_code2.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_1002 INPUT
*&---------------------------------------------------------------------*
*& Form ALV_SHOW2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ALV_SHOW2 .
CREATE OBJECT g_custom_container1 "创建容器对象
EXPORTING container_name = g_container1.
CREATE OBJECT grid1 "创建ALV对象
EXPORTING i_parent = g_custom_container1.
CALL METHOD grid1->register_edit_event "可编辑回传方法
EXPORTING
i_event_id = grid1->mc_evt_modified.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME = 'T001W'
* IS_VARIANT =
i_save = 'X'
* I_DEFAULT = 'X'
is_layout = is_layout
* IS_PRINT =
* IT_SPECIAL_GROUPS =
it_toolbar_excluding = ui_functions[]
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
it_outtab = i_t001w1[]
it_fieldcatalog = fieldcat1[].
* IT_SORT =
* IT_FILTER =
* EXCEPTIONS
* INVALID_PARAMETER_COMBINATION = 1""""
* PROGRAM_ERROR = 2
* TOO_MANY_LINES = 3
* others = 4
.
******注册ALV中引用的事件
SET HANDLER alv_event_receiver=>handle_toolbar
alv_event_receiver=>handle_menu_button
alv_event_receiver=>handle_user_command
alv_event_receiver=>handle_hotspot_click
alv_event_receiver=>handle_double_click
FOR ALL INSTANCES.
****调用方法激活自定义工具对象
CALL METHOD grid1->set_toolbar_interactive.
ENDFORM. " ALV_SHOW2
*&---------------------------------------------------------------------*
*& Form FRM_FIELDCAT_SET1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_FIELDCAT_SET1 .
DATA ls_fcat TYPE lvc_s_fcat .
CLEAR ls_fcat .
ls_fcat-fieldname = 'ZCHECKBOX' .
ls_fcat-coltext = '选择'.
* ls_fcat-emphasize = 'C601' ."列颜色控制
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO fieldcat1 .
CLEAR ls_fcat .
ls_fcat-fieldname = 'WERKS' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '4' .
ls_fcat-coltext = '工厂'."Carrier ID.列标题
ls_fcat-seltext = 'AAA' ."ALV 控制: 对话功能的列标识符
ls_fcat-emphasize = 'C601' ."列颜色控制
* ls_fcat-hotspot = 'X'. “不能设置hotspot 否则double click事件无效
APPEND ls_fcat TO fieldcat1 .
CLEAR ls_fcat .
ls_fcat-fieldname = 'NAME1' .
ls_fcat-ref_table = 'T001W' .
ls_fcat-ref_field = 'NAME1' .
ls_fcat-outputlen = '30' .
ls_fcat-coltext = '工厂名称' .
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO fieldcat1 .
CLEAR ls_fcat .
ls_fcat-fieldname = 'WERKS2' .
ls_fcat-inttype = 'C' .
ls_fcat-outputlen = '4' .
ls_fcat-coltext = '工厂2号'."Carrier ID.列标题
ls_fcat-seltext = 'AAA' ."ALV 控制: 对话功能的列标识符
ls_fcat-emphasize = 'C601' ."列颜色控制
ls_fcat-edit = 'X'.
APPEND ls_fcat TO fieldcat1 .
CLEAR ls_fcat .
ls_fcat-fieldname = 'ZICON' .
ls_fcat-coltext = '交货明细凭证'."Carrier ID.列标题
ls_fcat-seltext = 'AAA' ."ALV 控制: 对话功能的列标识符
ls_fcat-icon = 'X'.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO fieldcat1 .
CLEAR ls_fcat .
ENDFORM. " FRM_FIELDCAT_SET1