以前一直都是使用Function ALV實(shí)現(xiàn)報(bào)表需求,最近接到個(gè)需求,說是希望可以在手持設(shè)備上也能使用(具體怎么弄暫時(shí)不清楚)玄糟,我就思索把選擇界面和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, "設(shè)備號
s_kdauf FOR eqbs-kdauf, "銷售訂單
s_kdpos FOR eqbs-kdpos. "銷售訂單行項(xiàng)
PARAMETERS: p_pcode TYPE zpp01-pcode, "整機(jī)序列號
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.
"設(shè)置布局
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'. "最優(yōu)寬
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工具欄按鈕功能響應(yīng)事件處理類:
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.
設(shè)置工具欄按鈕及響應(yīng)按鈕功能:
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'. "最優(yōu)寬
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.