以前一直都是使用Function ALV实现报表需求,最近接到个需求,说是希望可以在手持设备上也能使用(具体怎么弄暂时不清楚),我就思索把选择界面和ALV放在一块显示,如下图:
自定义Screen 100,上面放置选择条件的子屏幕控件,下面放置展示ALV的容器控件:
子屏幕选择界面:
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK bk1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_equnr FOR eqbs-equnr, "设备号
s_kdauf FOR eqbs-kdauf, "销售订单
s_kdpos FOR eqbs-kdpos. "销售订单行项
PARAMETERS: p_pcode TYPE zpp01-pcode, "整机序列号
p_lgort TYPE mard-lgort. "接收库位
SELECTION-SCREEN END OF BLOCK bk1.
SELECTION-SCREEN END OF SCREEN 101.
Screen 100屏幕逻辑流:
PROCESS BEFORE OUTPUT.
MODULE display_data.
MODULE status_0100.
CALL SUBSCREEN subscreen INCLUDING sy-repid '101'.
PROCESS AFTER INPUT.
CALL SUBSCREEN subscreen.
MODULE exit_command_0100 AT EXIT-COMMAND.
MODULE user_command_0100.
Screen 100 PBO:
MODULE display_data OUTPUT.
IF gr_container IS INITIAL.
CREATE OBJECT gr_container
EXPORTING
container_name = 'ALV_CONTAINER'.
CREATE OBJECT gr_grid
EXPORTING
i_parent = gr_container.
"设置布局
PERFORM frm_set_layout CHANGING gs_layout.
"获取字段目录
PERFORM frm_set_fieldcat CHANGING gt_fieldcat.
"显示ALV
CALL METHOD gr_grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fieldcat.
CREATE OBJECT gr_event_handler.
SET HANDLER gr_event_handler->handle_data_changed FOR gr_grid.
SET HANDLER gr_event_handler->handle_toolbar FOR gr_grid.
SET HANDLER gr_event_handler->handle_user_command FOR gr_grid.
CALL METHOD gr_grid->set_toolbar_interactive.
ELSE.
DATA: ls_layout TYPE lvc_s_layo.
CALL METHOD gr_grid->get_frontend_layout
IMPORTING
es_layout = ls_layout.
ls_layout-cwidth_opt = 'X'. "最优宽
CALL METHOD gr_grid->set_frontend_layout
EXPORTING
is_layout = ls_layout.
CALL METHOD gr_grid->refresh_table_display.
ENDIF.
ENDMODULE.
Screen 100 PAI:
MODULE user_command_0100 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN '&EXEC'.
PERFORM frm_get_data.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
OO ALV工具栏按钮功能响应事件处理类:
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed,
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object,
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_data_changed.
PERFORM frm_handle_data_changed USING er_data_changed.
ENDMETHOD.
METHOD handle_toolbar.
PERFORM frm_set_toolbar CHANGING e_object.
ENDMETHOD.
METHOD handle_user_command.
PERFORM frm_user_command USING e_ucomm.
ENDMETHOD.
ENDCLASS.
DATA gr_event_handler TYPE REF TO lcl_event_handler.
设置工具栏按钮及响应按钮功能:
FORM frm_set_toolbar CHANGING e_object TYPE REF TO cl_alv_event_toolbar_set.
DATA ls_button TYPE stb_button.
CLEAR e_object->mt_toolbar.
CLEAR ls_button.
ls_button-function = '&ALL1'.
ls_button-quickinfo = '全选'.
ls_button-text = '全选'.
APPEND ls_button TO e_object->mt_toolbar.
CLEAR ls_button.
ls_button-function = '&SAL1'.
ls_button-quickinfo = '取消全选'.
ls_button-text = '取消全选'.
APPEND ls_button TO e_object->mt_toolbar.
CLEAR ls_button.
ls_button-function = '&POST'.
ls_button-quickinfo = '移库过账'.
ls_button-text = '移库过账'.
APPEND ls_button TO e_object->mt_toolbar.
ENDFORM.
FORM frm_user_command USING e_ucomm TYPE sy-ucomm.
CASE e_ucomm.
WHEN '&ALL1'.
LOOP AT gt_outtab ASSIGNING FIELD-SYMBOL(<lfs_outtab>).
<lfs_outtab>-check = 'X'.
ENDLOOP.
WHEN '&SAL1'.
LOOP AT gt_outtab ASSIGNING <lfs_outtab>.
<lfs_outtab>-check = ''.
ENDLOOP.
WHEN '&POST'.
PERFORM frm_post.
WHEN OTHERS.
ENDCASE.
DATA: ls_layout TYPE lvc_s_layo.
CALL METHOD gr_grid->get_frontend_layout
IMPORTING
es_layout = ls_layout.
ls_layout-cwidth_opt = 'X'. "最优宽
CALL METHOD gr_grid->set_frontend_layout
EXPORTING
is_layout = ls_layout.
CALL METHOD gr_grid->check_changed_data.
CALL METHOD gr_grid->refresh_table_display.
ENDFORM.