ALV-GRID-CLASS-SPLITTER
备注说明:
ALV屏幕分割,把一个ALV屏幕分成两个或多个屏幕
创建一个屏幕:0100,上面一个定制控件,名称: ALV_CONTAIN1 .
代码如下:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE F_INIT_SPLITTER.
MODULE F_CREAT_ALV_CONTROL.
PROCESS AFTER INPUT.
MODULE PAI_0100.
REPORT YTEST_HE12.
DATA: OK_CODE LIKE SY-UCOMM.
*&**定义CLASS ALV用到的变量
DATA: GS_LAYOUT TYPE lvc_s_layo,
GRID1 TYPE REF TO CL_GUI_ALV_GRID,
CUSTOM_CONTAIN1 TYPE REF TO cl_gui_custom_container.
DATA: G_SPLIT_CONTAINER TYPE REF TO CL_GUI_SPLITTER_CONTAINER.
DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA: ALV_GRID_1 TYPE REF TO CL_GUI_ALV_GRID,
ALV_GRID_2 TYPE REF TO CL_GUI_ALV_GRID.
DATA: G_CONTAINER_1 TYPE REF TO CL_GUI_CONTAINER,
G_CONTAINER_2 TYPE REF TO CL_GUI_CONTAINER.
DATA: G_CUSTOM_CONTROL_NAME TYPE SCRFNAME VALUE 'ALV_CONTAIN1'.
DATA: gt_fieldcat TYPE LVC_T_FCAT . "一个表
DATA: LS_FIELDCAT TYPE LVC_S_FCAT. "一个结构
DATA: BEGIN OF GT_DATA OCCURS 0.
INCLUDE STRUCTURE SPFLI.
DATA: END OF GT_DATA.
**&***************************************
CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*& Module PBO_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module PAI_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE PAI_0100 INPUT.
CASE OK_CODE.
WHEN 'BACK' OR 'EXIT' OR 'CANC'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " PAI_0100 INPUT
*&---------------------------------------------------------------------*
*& Module F_INIT_SPLITTER OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE F_INIT_SPLITTER OUTPUT.
IF G_CUSTOM_CONTAINER IS INITIAL .
*----CREATING CUSTOM CONTAINER INSTANCE
CREATE OBJECT G_CUSTOM_CONTAINER
EXPORTING
CONTAINER_NAME = G_CUSTOM_CONTROL_NAME
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
OTHERS = 6.
*--CREATE SPLITTER FOR CUSTOM_CONTAINER
IF G_SPLIT_CONTAINER IS INITIAL.
* CREATE SPLITTER
CREATE OBJECT G_SPLIT_CONTAINER
EXPORTING
PARENT = G_CUSTOM_CONTAINER
ROWS = 2 "2
COLUMNS = 1.
* GET UPPPER CONTAINER IN SPLITTER
CALL METHOD G_SPLIT_CONTAINER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = G_CONTAINER_1.
CALL METHOD G_SPLIT_CONTAINER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = G_CONTAINER_2.
ENDIF.
ENDIF.
ENDMODULE. " F_INIT_SPLITTER OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'GUI_STATUS'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module F_CREAT_ALV_CONTROL OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE F_CREAT_ALV_CONTROL OUTPUT.
IF ALV_GRID_1 IS INITIAL .
CREATE OBJECT ALV_GRID_1
EXPORTING
I_PARENT = G_CONTAINER_1.
PERFORM FRM_GET_DATA.
PERFORM FRM_PREPARE_FIELD_CATALOG.
PERFORM FRM_GET_LAYOUT.
CALL METHOD ALV_GRID_1->set_table_for_first_display
EXPORTING
* i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING
it_outtab = GT_DATA[] "没有表头行的内表
it_fieldcatalog = gt_fieldcat . "显示字段的内表
ENDIF.
IF ALV_GRID_2 IS INITIAL .
CLEAR:GS_LAYOUT,GT_DATA[],GT_FIELDCAT[].
CREATE OBJECT ALV_GRID_2
EXPORTING
I_PARENT = G_CONTAINER_2.
PERFORM FRM_GET_DATA.
PERFORM FRM_PREPARE_FIELD_CATALOG.
PERFORM FRM_GET_LAYOUT.
CALL METHOD ALV_GRID_2->set_table_for_first_display
EXPORTING
* i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING
it_outtab = GT_DATA[] "没有表头行的内表
it_fieldcatalog = gt_fieldcat . "显示字段的内表
ENDIF.
ENDMODULE. " F_CREAT_ALV_CONTROL OUTPUT
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .
CLEAR: GT_DATA,GT_DATA[].
select * from spfli into TABLE gt_data UP TO 22 rows.
ENDFORM. " FRM_GET_DATA
*&---------------------------------------------------------------------*
*& Form FRM_PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_PREPARE_FIELD_CATALOG .
PERFORM FRM_GET_FIELD_CATALOG USING '' '' '1' '2' 'L' 'CARRID' '航线承运人ID' CHANGING GT_FIELDCAT.
PERFORM FRM_GET_FIELD_CATALOG USING '' 'X' '1' '3' 'L' 'CONNID' '航班连接 Id' CHANGING GT_FIELDCAT.
PERFORM FRM_GET_FIELD_CATALOG USING '' 'X' '1' '16' 'L' 'CITYFROM' '起飞城市' CHANGING GT_FIELDCAT.
ENDFORM. " FRM_PREPARE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form FRM_GET_FIELD_CATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_FIELD_CATALOG USING P_CHECKBOX P_EDIT P_COL_POS
P_OUTPUTLEN P_JUST P_FIELDNAME P_COLTEXT
CHANGING P_GT_FIELDCAT TYPE LVC_T_FCAT.
DATA: LS_FIELDCAT TYPE LVC_S_FCAT.
LS_FIELDCAT-CHECKBOX = P_CHECKBOX. "是否以复选框显示
LS_FIELDCAT-EDIT = P_EDIT. "此列是否可编辑
LS_FIELDCAT-COL_POS = P_COL_POS. "弟几列
LS_FIELDCAT-OUTPUTLEN = P_OUTPUTLEN. " 列长度
LS_FIELDCAT-just = P_JUST. "对齐方式
LS_FIELDCAT-fieldname = P_FIELDNAME . "字段名
LS_FIELDCAT-coltext = P_COLTEXT . "字段文本
APPEND LS_FIELDCAT to P_GT_FIELDCAT .
CLEAR LS_FIELDCAT .
ENDFORM. " FRM_GET_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form FRM_GET_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GET_LAYOUT .
GS_LAYOUT-GRID_TITLE = 'SPFLI'.
GS_LAYOUT-CWIDTH_OPT = 'X'.
ENDFORM. " FRM_GET_LAYOUT