1 REPORT ztest05.
2
3 TYPES:BEGIN OF ty_data ,
4 matnr TYPE marc-matnr,
5 mtart TYPE marc-werks,
6 xchar TYPE marc-xchar,
7 END OF ty_data .
8
9 DATA:gt_data TYPE TABLE OF ty_data,
10 gv_matnr TYPE mara-matnr.
11
12 *ALV相关变量
13 DATA:gs_alv TYPE REF TO cl_gui_alv_grid, "ALV类
14 gs_con TYPE REF TO cl_gui_custom_container, "容器类
15 g_dock TYPE REF TO cl_gui_docking_container,
16 gt_fieldcat TYPE lvc_t_fcat, "列格式
17 gs_fieldcat TYPE lvc_s_fcat, "列格式-结构
18 gs_stable TYPE lvc_s_stbl, "光标
19 gs_layout TYPE lvc_s_layo, "输出格式
20 gt_output TYPE STANDARD TABLE OF sflight,
21 ok_code TYPE sy-ucomm.
22
23 END-OF-SELECTION.
24 CALL SCREEN '9000' .
25
26 MODULE status_9000 OUTPUT.
27
28 SET PF-STATUS 'STATUS_9000'.
29 SET TITLEBAR 'TEXT01'.
30
31 ENDMODULE.
32
33 MODULE init OUTPUT.
34
35 IF gs_alv IS INITIAL.
36 PERFORM frm_create_alv.
37 "设置布局
38 PERFORM frm_set_layout.
39 "设置字段目录
40 PERFORM frm_set_fieldcat.
41 "ALV展示
42 PERFORM frm_alv_out.
43 ELSE.
44 PERFORM frm_refresh_alv.
45 ENDIF.
46
47 ENDMODULE.
48
49 MODULE user_command_9000 INPUT.
50 CALL METHOD gs_alv->check_changed_data."更改数据
51 DATA(lv_code) = ok_code.
52 CLEAR ok_code.
53 CASE lv_code.
54 WHEN '&F03' OR '&F12' OR '&F15'.
55 LEAVE TO SCREEN 0.
56 WHEN 'OK'.
57 PERFORM frm_select.
58 WHEN OTHERS.
59 ENDCASE.
60 ENDMODULE.
61
62 FORM frm_select .
63
64 IF gv_matnr IS NOT INITIAL .
65
66 SELECT *
67 INTO CORRESPONDING FIELDS OF TABLE @gt_data
68 FROM marc
69 WHERE matnr = @gv_matnr .
70
71 ELSE .
72
73 SELECT *
74 INTO CORRESPONDING FIELDS OF TABLE @gt_data
75 FROM marc .
76
77 ENDIF .
78
79 ENDFORM .
80
81 FORM frm_set_fieldcat.
82 DATA: lv_name TYPE lvc_s_fcat-fieldname,
83 lv_scrtext TYPE lvc_s_fcat-scrtext_l.
84
85 REFRESH:gt_fieldcat.
86 PERFORM frm_build_fieldcat USING :
87 'MATNR' '' '' 'X' 'MARC' 'MATNR' '' '物料编码' ,
88 'WERKS' '' '' 'X' 'MARC' 'WERKS' '' '工厂' ,
89 'XCHAR' '' '' 'X' 'MARC' 'XCHAR' '' '批次' .
90
91 ENDFORM.
92
93 FORM frm_build_fieldcat USING pv_fieldname
94 pv_edit
95 pv_no_out
96 pv_no_zero
97 pv_ref_table
98 pv_ref_field
99 pv_f4
100 pv_reptext.
101
102 CLEAR gs_fieldcat.
103 gs_fieldcat-fieldname = pv_fieldname.
104 gs_fieldcat-edit = pv_edit.
105 gs_fieldcat-no_out = pv_no_out.
106 gs_fieldcat-no_zero = pv_no_zero.
107 gs_fieldcat-ref_table = pv_ref_table.
108 gs_fieldcat-ref_field = pv_ref_field.
109 gs_fieldcat-f4availabl = pv_f4.
110 gs_fieldcat-coltext = pv_reptext.
111 gs_fieldcat-reptext = pv_reptext.
112 gs_fieldcat-scrtext_l = pv_reptext.
113 gs_fieldcat-scrtext_m = pv_reptext.
114 gs_fieldcat-scrtext_s = pv_reptext.
115
116 APPEND gs_fieldcat TO gt_fieldcat.
117
118 ENDFORM.
119
120 FORM frm_set_layout .
121
122 gs_layout-zebra = 'X'.
123 gs_layout-cwidth_opt = 'X'.
124
125 ENDFORM.
126
127 FORM frm_refresh_alv.
128
129 CALL METHOD gs_alv->set_frontend_layout
130 EXPORTING
131 is_layout = gs_layout.
132
133 gs_stable-row = 'X'.
134 gs_stable-col = 'X'.
135
136 CALL METHOD gs_alv->refresh_table_display
137 EXPORTING
138 is_stable = gs_stable.
139
140 ENDFORM.
141
142 FORM frm_alv_out.
143
144 DATA:gt_exclude TYPE ui_functions,
145 ls_exclude TYPE ui_func,
146 lv_save,
147 ls_variant TYPE disvariant.
148 lv_save = 'A'.
149 ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row .
150 APPEND ls_exclude TO gt_exclude.
151 ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row .
152 APPEND ls_exclude TO gt_exclude.
153 ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row .
154 APPEND ls_exclude TO gt_exclude.
155 ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row .
156 APPEND ls_exclude TO gt_exclude.
157 CALL METHOD gs_alv->set_table_for_first_display
158 EXPORTING
159 * i_buffer_active =
160 * i_bypassing_buffer =
161 * i_consistency_check =
162 * i_structure_name =
163 is_variant = ls_variant
164 i_save = lv_save
165 * i_default = 'X'
166 is_layout = gs_layout
167 * is_print =
168 * it_special_groups =
169 it_toolbar_excluding = gt_exclude
170 * it_hyperlink =
171 * it_alv_graphics =
172 * it_except_qinfo =
173 * ir_salv_adapter =
174 CHANGING
175 it_outtab = gt_data
176 it_fieldcatalog = gt_fieldcat
177 * it_sort =
178 * it_filter =
179 EXCEPTIONS
180 invalid_parameter_combination = 1
181 program_error = 2
182 too_many_lines = 3
183 OTHERS = 4.
184
185 ENDFORM.
186
187 FORM frm_create_alv.
188
189 "后台运行,没有GUI,会有错误。
190 "判断是否后台运行
191 IF cl_gui_alv_grid=>offline( ) IS INITIAL.
192
193 "前台运行
194 "创建容器
195 CREATE OBJECT gs_con
196 EXPORTING
197 container_name = 'GC_CON'. "customer control控件的名称
198
199 "将ALV植入到容器中
200 CREATE OBJECT gs_alv
201 EXPORTING
202 i_parent = gs_con.
203 ELSE .
204
205 "后台运行
206 CREATE OBJECT gs_alv EXPORTING i_parent = g_dock.
207
208 ENDIF .
209
210 ENDFORM .