1 REPORT y4_b4_test20.
2
3 TABLES: sflight.
4
5 "抬头数据输出
6 TYPES: BEGIN OF ty_head.
7 INCLUDE TYPE scarr.
8 TYPES: slbox TYPE c,
9 light TYPE icon_d,
10 message TYPE string,
11 END OF ty_head.
12
13 DATA: gt_head TYPE TABLE OF ty_head,
14 gs_head TYPE ty_head.
15
16 "行项目数据输出
17 TYPES: BEGIN OF ty_item.
18 INCLUDE TYPE sflight.
19 TYPES: slbox TYPE c,
20 light TYPE icon_d,
21 message TYPE string,
22 END OF ty_item.
23
24 DATA: gt_item TYPE TABLE OF ty_item,
25 gs_item TYPE ty_item.
26
27 DATA:g_cust_con TYPE REF TO cl_gui_custom_container.
28
29 "字段属性定义
30 DATA: gs_fcat TYPE lvc_s_fcat.
31 DATA: gt_fcat_h TYPE lvc_t_fcat,
32 gt_fcat_i TYPE lvc_t_fcat.
33 DATA: gs_layout_h TYPE lvc_s_layo,
34 gs_layout_i TYPE lvc_s_layo.
35 DATA: gs_variant_h TYPE disvariant,
36 gs_variant_i TYPE disvariant,
37 gv_colno TYPE i.
38 DATA: gt_ui_func TYPE ui_functions. "隐藏alv菜单控件
39
40 DATA: ok_code TYPE sy-ucomm. "用户功能码接收
41 DATA: save_ok TYPE sy-ucomm. "用户功能码接收
42
43 "ALV grid
44 DATA: gs_dock TYPE REF TO cl_gui_docking_container,
45 gs_splitter TYPE REF TO cl_gui_splitter_container, "分割屏幕类
46 gs_container_h TYPE REF TO cl_gui_container, "抬头容器
47 gs_container_i TYPE REF TO cl_gui_container, "行项目容器
48 gs_grid_h TYPE REF TO cl_gui_alv_grid, "抬头屏幕对象类
49 gs_grid_i TYPE REF TO cl_gui_alv_grid. "行项目屏幕对象类
50
51 CONSTANTS: gc_h TYPE c VALUE 'H'. "抬头标识符
52 CONSTANTS: gc_i TYPE c VALUE 'I'. "行项目标识符
53
54 "选择屏幕
55 SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME.
56 SELECT-OPTIONS: s_carrid FOR sflight-carrid.
57 SELECTION-SCREEN END OF BLOCK blk1 .
58
59 START-OF-SELECTION.
60 "取数
61 PERFORM frm_select_data.
62
63 END-OF-SELECTION.
64 "输出屏幕准备
65 PERFORM frm_prepare_alv.
66 "调用100屏幕输出
67 CALL SCREEN 0100.
68
69 MODULE pbo OUTPUT.
70 SET PF-STATUS 'MAIN100'.
71 SET TITLEBAR 'MAINTITLE' WITH 'OOALV分割'.
72 ENDMODULE.
73
74 MODULE pai INPUT.
75 save_ok = ok_code.
76 CLEAR ok_code.
77
78 CASE save_ok.
79 WHEN '&F03' OR '&F12' OR '&F15'.
80 LEAVE TO SCREEN 0. "返回上一个屏幕
81 WHEN OTHERS.
82 ENDCASE.
83
84 ENDMODULE.
85
86 MODULE init_alv OUTPUT.
87
88 IF gs_dock IS INITIAL.
89 "屏幕分割
90 PERFORM frm_split_screen.
91
92 "创建alv grid
93 PERFORM frm_create_grid.
94
95 "显示数据
96 PERFORM frm_display_alv USING gc_h gs_grid_h.
97 PERFORM frm_display_alv USING gc_i gs_grid_i.
98
99 ELSE.
100 "alv 刷新
101 PERFORM frm_refresh_alv USING gs_grid_h.
102 PERFORM frm_refresh_alv USING gs_grid_i.
103 ENDIF.
104
105 ENDMODULE.
106
107 FORM frm_select_data .
108
109 SELECT *
110 FROM scarr
111 INTO CORRESPONDING FIELDS OF TABLE gt_head
112 WHERE carrid IN s_carrid.
113
114 SELECT *
115 FROM sflight
116 INTO CORRESPONDING FIELDS OF TABLE gt_item
117 WHERE carrid IN s_carrid.
118
119 ENDFORM.
120
121 FORM frm_prepare_alv .
122 * ALV字段属性
123 PERFORM frm_build_fieldcat.
124
125 * 屏幕隐藏按钮
126 PERFORM frm_build_ui_functions.
127
128 * 屏幕布局
129 PERFORM frm_set_layout.
130
131 * 屏幕自定义布局参数
132 PERFORM frm_set_variant.
133
134 ENDFORM.
135
136 FORM frm_build_fieldcat .
137 DEFINE m_fcat_0100.
138 CLEAR gs_fcat.
139 gs_fcat-fieldname = &1.
140 gs_fcat-ref_field = &2.
141 gs_fcat-ref_table = &3.
142 gs_fcat-coltext =
143 gs_fcat-seltext =
144 gs_fcat-tooltip =
145 gs_fcat-reptext =
146 gs_fcat-scrtext_l = &4.
147 gs_fcat-checkbox = &5.
148 gs_fcat-edit = &6.
149 gs_fcat-hotspot = &7.
150 gv_colno = gv_colno + 1.
151 gs_fcat-col_pos = gv_colno.
152 CASE &8.
153 WHEN gc_h.
154 APPEND gs_fcat TO gt_fcat_h.
155 WHEN gc_i.
156 APPEND gs_fcat TO gt_fcat_i.
157 WHEN OTHERS.
158 ENDCASE.
159
160 END-OF-DEFINITION.
161
162
163 REFRESH: gt_fcat_h.
164 CLEAR: gv_colno.
165
166 * 抬头屏幕字段
167 m_fcat_0100 'CARRID' '' '' '航线代码' '' '' '' gc_h.
168 m_fcat_0100 'CARRNAME' '' '' '航线名称' '' '' '' gc_h.
169 m_fcat_0100 'CURRCODE' '' '' '航班的本地货币' '' '' '' gc_h.
170 m_fcat_0100 'URL' '' '' '航线 URL' '' '' '' gc_h.
171
172 REFRESH: gt_fcat_i.
173 CLEAR: gv_colno.
174 * 行项目屏幕字段
175 m_fcat_0100 'CARRID' '' '' '航线代码' '' '' '' gc_i.
176 m_fcat_0100 'CONNID' '' '' '航班连接编号' '' '' '' gc_i.
177 m_fcat_0100 'FLDATE' '' '' '航班日期' '' '' '' gc_i.
178 m_fcat_0100 'PRICE' '' '' '航空运费' '' '' '' gc_i.
179 m_fcat_0100 'CURRENCY' '' '' '航班的本地货币' '' '' '' gc_i.
180 m_fcat_0100 'PLANETYPE' '' '' '飞机类型' '' '' '' gc_i.
181 m_fcat_0100 'SEATSMAX' '' '' '经济舱的最大容量' '' '' '' gc_i.
182 m_fcat_0100 'SEATSOCC' '' '' '占据的经济舱座位' '' '' '' gc_i.
183 m_fcat_0100 'PAYMENTSUM' '' '' '当前预定总数' '' '' '' gc_i.
184 m_fcat_0100 'SEATSMAX_B' '' '' '商务舱的最大容量' '' '' '' gc_i.
185 m_fcat_0100 'SEATSOCC_B' '' '' '占据的商务舱座位' '' '' '' gc_i.
186 m_fcat_0100 'SEATSMAX_F' '' '' '头等舱的最大容量' '' '' '' gc_i.
187 m_fcat_0100 'SEATSOCC_F' '' '' '占据的头等舱座位' '' '' '' gc_i.
188
189 ENDFORM.
190
191 FORM frm_build_ui_functions.
192
193 DATA: ls_ui_func TYPE ui_func.
194
195 REFRESH: gt_ui_func.
196 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_copy .
197 APPEND ls_ui_func TO gt_ui_func.
198 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_copy_row .
199 APPEND ls_ui_func TO gt_ui_func.
200 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_cut .
201 APPEND ls_ui_func TO gt_ui_func.
202 ls_ui_func = cl_gui_alv_grid=>mc_fc_refresh .
203 APPEND ls_ui_func TO gt_ui_func.
204 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_move_row .
205 APPEND ls_ui_func TO gt_ui_func.
206 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_paste .
207 APPEND ls_ui_func TO gt_ui_func.
208 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_paste_new_row .
209 APPEND ls_ui_func TO gt_ui_func.
210 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_undo .
211 APPEND ls_ui_func TO gt_ui_func.
212 ls_ui_func = cl_gui_alv_grid=>mc_fc_pc_file .
213 APPEND ls_ui_func TO gt_ui_func.
214 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_delete_row .
215 APPEND ls_ui_func TO gt_ui_func.
216 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_insert_row .
217 APPEND ls_ui_func TO gt_ui_func.
218 ls_ui_func = cl_gui_alv_grid=>mc_fc_loc_append_row.
219 APPEND ls_ui_func TO gt_ui_func.
220
221 ENDFORM. " FRM_BUILD_UI_FUNCTIONS
222
223 FORM frm_set_layout .
224
225 CLEAR: gs_layout_h.
226 gs_layout_h-zebra = 'X'. "striped pattern
227 gs_layout_h-cwidth_opt = 'X'. "Optimized width
228
229 gs_layout_i = gs_layout_h.
230
231 ENDFORM. " FRM_SET_LAYOUT
232
233 FORM frm_set_variant .
234
235 "用于区分抬头和项目的布局
236
237 CLEAR: gs_variant_h.
238 gs_variant_h-handle = '1001'.
239 gs_variant_h-report = sy-repid.
240
241 CLEAR: gs_variant_i.
242 gs_variant_i-handle = '2001'.
243 gs_variant_i-report = sy-repid.
244
245 ENDFORM. " FRM_SET_VARIANT
246
247 FORM frm_split_screen.
248
249 ****************开始*******************
250 "创建屏幕容器:comtainer
251 * CREATE OBJECT gs_dock
252 * EXPORTING
253 * repid = sy-repid
254 * dynnr = '0100'
255 ** side = cl_gui_docking_container=>property_floating
256 * side = cl_gui_docking_container=>dock_at_left
257 * extension = 200
258 * metric = 0
259 * ratio = 95
260 * EXCEPTIONS
261 * cntl_error = 1
262 * cntl_system_error = 2
263 * create_error = 3
264 * lifetime_error = 4
265 * lifetime_dynpro_dynpro_link = 5
266 * OTHERS = 6.
267 * IF sy-subrc <> 0.
268 * MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
269 * WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
270 * ENDIF.
271
272 * CREATE OBJECT gs_splitter
273 * EXPORTING
274 * parent = gs_dock
275 * rows = 2
276 * columns = 1.
277
278 *********************结束***********************
279
280 ****************开始*******************
281 IF g_cust_con IS INITIAL.
282 CREATE OBJECT g_cust_con
283 EXPORTING
284 container_name = 'GC_CON'.
285 ENDIF.
286
287 *拆分成二行一列部分*
288 CREATE OBJECT gs_splitter
289 EXPORTING
290 parent = g_cust_con
291 rows = 2
292 columns = 1.
293 *********************结束***********************
294
295 *第一行一列*
296 CALL METHOD gs_splitter->get_container
297 EXPORTING
298 row = 1
299 column = 1
300 RECEIVING
301 container = gs_container_h.
302
303 *第二行一列*
304 CALL METHOD gs_splitter->get_container
305 EXPORTING
306 row = 2
307 column = 1
308 RECEIVING
309 container = gs_container_i.
310
311 ENDFORM.
312
313 FORM frm_create_grid .
314
315 "创建抬头屏幕对象
316 CREATE OBJECT gs_grid_h
317 EXPORTING
318 i_parent = gs_container_h.
319
320 "准备输入事件
321 CALL METHOD gs_grid_h->set_ready_for_input
322 EXPORTING
323 i_ready_for_input = 1.
324
325 "check data changed
326 CALL METHOD gs_grid_h->check_changed_data.
327
328 "数据变更事件
329 CALL METHOD gs_grid_h->register_edit_event
330 EXPORTING
331 i_event_id = cl_gui_alv_grid=>mc_evt_modified.
332
333 "创建行项目屏幕对象
334 CREATE OBJECT gs_grid_i
335 EXPORTING
336 i_parent = gs_container_i.
337
338 ENDFORM. " FRM_CREATE_GRID
339
340 FORM frm_display_alv USING pv_flg TYPE c
341 pv_grid TYPE REF TO cl_gui_alv_grid .
342
343 CASE pv_flg.
344 WHEN gc_h.
345
346 CALL METHOD pv_grid->set_table_for_first_display
347 EXPORTING
348 * I_CONSISTENCY_CHECK = 'X'
349 is_variant = gs_variant_h
350 it_toolbar_excluding = gt_ui_func
351 i_save = 'A'
352 i_default = 'X' "允许定义默认布局
353 is_layout = gs_layout_h
354 CHANGING
355 it_outtab = gt_head
356 it_fieldcatalog = gt_fcat_h
357 EXCEPTIONS
358 invalid_parameter_combination = 1
359 program_error = 2
360 too_many_lines = 3
361 OTHERS = 4.
362 IF sy-subrc <> 0.
363 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
364 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
365 ENDIF.
366 WHEN gc_i.
367
368 CALL METHOD pv_grid->set_table_for_first_display
369 EXPORTING
370 * I_CONSISTENCY_CHECK = 'X'
371 is_variant = gs_variant_i
372 it_toolbar_excluding = gt_ui_func
373 i_save = 'A'
374 i_default = 'X' "允许定义默认布局
375 is_layout = gs_layout_i
376 CHANGING
377 it_outtab = gt_item
378 it_fieldcatalog = gt_fcat_i
379 EXCEPTIONS
380 invalid_parameter_combination = 1
381 program_error = 2
382 too_many_lines = 3
383 OTHERS = 4.
384 IF sy-subrc <> 0.
385 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
386 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
387 ENDIF.
388
389 WHEN OTHERS.
390 ENDCASE.
391
392 ENDFORM. " FRM_DISPLAY_ALV
393
394 FORM frm_refresh_alv USING pv_grid TYPE REF TO cl_gui_alv_grid.
395
396 "刷新变量
397 DATA: ls_stable TYPE lvc_s_stbl.
398
399 "刷新显示
400 CLEAR ls_stable.
401 ls_stable-row = 'X'."基于行刷新
402 ls_stable-col = 'X'."基于列刷新
403 CALL METHOD pv_grid->refresh_table_display
404 EXPORTING
405 is_stable = ls_stable
406 EXCEPTIONS
407 finished = 0
408 OTHERS = 0.
409
410 ENDFORM. " FRM_REFRESH_ALV
1 *100屏幕
2 PROCESS BEFORE OUTPUT.
3 MODULE pbo .
4 MODULE init_alv .
5
6 PROCESS AFTER INPUT.
7 MODULE pai .
![](https://img2022.cnblogs.com/blog/1858853/202206/1858853-20220624141743825-1227425549.png)
![](https://img2022.cnblogs.com/blog/1858853/202206/1858853-20220624141810130-730992789.png)
![](https://img2022.cnblogs.com/blog/1858853/202206/1858853-20220624141901606-1195295133.png)