其他分享
首页 > 其他分享> > 2021.08.26 【ABAP随笔】- OO ALV开发模版 (震惊,输出一个OO ALV只需要几行代码,瞎扯)

2021.08.26 【ABAP随笔】- OO ALV开发模版 (震惊,输出一个OO ALV只需要几行代码,瞎扯)

作者:互联网

OO ALV 模版

部分代码参考了SAP孙亮(公众号:ABAPer-LL)

一 创建ALV前的所需操作

1. 取数据

这里我们随便取数据

1 SELECT * FROM sflight INTO TABLE @DATA(gt_sflight)
2   UP TO 20 ROWS.

2. 创建屏幕

注意,我们这里使用的是行列200/255 最大值

 

同时设置容器CONTAINER自动调节 最少行列为10/10,这样屏幕就会根据你的电脑屏幕大小来自动调节了

 

 

 

 

 创建了OK_CODE

 

3. 添加逻辑流

在逻辑流中打开PBO,PAI的注释,分别创建2个module,同时创建STATUS,TITLE(可选),

 

 

 status 仅仅需要这3个按钮即可

 

 

 

 

 

二 使用ALV 类直接显示

 输入以下代码,然后直接点击执行程序

 

 1 REPORT z_tab_test03.
 2 DATA ok_code TYPE sy-ucomm.
 3 ​
 4 SELECT * FROM sflight INTO TABLE @DATA(gt_sflight)
 5   UP TO 20 ROWS.
 6 ​
 7 DATA(cl_oo_alv) = NEW zcl_tab_oo_alv( ).
 8 ​
 9 CALL METHOD cl_oo_alv->create_oo_alv
10   EXPORTING
11 *   iv_repid          = SY-CPROG
12 *   iv_screen         = '9000'
13 *   iv_default_ex     = 'X'
14 *   is_layout         =
15 *   it_fieldcat       =
16 *   it_exclude        =
17 *   iv_split_number   =
18 *   iv_split_container          =
19     iv_container_name = 'CONTAINER'
20 *   iv_variant_handle = '1'
21 *   i_f4_form         =
22 *   i_toolbar_form    =
23 *   i_user_command_form         =
24 *   i_hotspot_form    =
25 *   i_datachanged_form          =
26 *   i_datachanged_finished_form =
27 *   i_before_ucomm_form         =
28 *   i_double_click_form         =
29 *   i_menu_button_form          =
30   CHANGING
31     it_data           = gt_sflight.
32 ​
33 CALL SCREEN 9000.
34 *&---------------------------------------------------------------------*
35 *& Module STATUS_9000 OUTPUT
36 *&---------------------------------------------------------------------*
37 *&
38 *&---------------------------------------------------------------------*
39 MODULE status_9000 OUTPUT.
40   SET PF-STATUS 'STATUS'.
41   SET TITLEBAR 'TITLE'.
42 ENDMODULE.
43 *&---------------------------------------------------------------------*
44 *&      Module  USER_COMMAND_9000  INPUT
45 *&---------------------------------------------------------------------*
46 *       text
47 *----------------------------------------------------------------------*
48 MODULE user_command_9000 INPUT.
49   CASE ok_code.
50     WHEN 'EXIT' OR 'BACK'.
51       LEAVE TO SCREEN 0.
52     WHEN  'CANC'.
53       LEAVE PROGRAM.
54     WHEN OTHERS.
55   ENDCASE.
56   CLEAR ok_code.
57 ENDMODULE.

我们就可以看到一个ALV画面了

下面介绍ZCL_TAB_OO_ALV代码- 复制可用

小伙伴们可以直接SE24,创建一个类,然后点击基于源代码创建,然后COPY代码即可

 

对于方法ZCL_TAB_OO_ALV=>SPLIT_CONTAINER , 可以直接静态调用,将容器切割后,返回多个容器,然后将返回的容器分别调用cl_oo_alv->create_oo_alv方法即可实现多个ALV显示

 

 简单的显示多个ALV代码如下:

 1 REPORT z_tab_test03.
 2 DATA ok_code TYPE sy-ucomm.
 3 ​
 4 SELECT * FROM sflight INTO TABLE @DATA(gt_sflight)
 5   UP TO 20 ROWS.
 6 CHECK sy-subrc EQ 0.
 7 SELECT * FROM scarr INTO TABLE @DATA(gt_scarr)
 8   FOR ALL ENTRIES IN @gt_sflight
 9   WHERE carrid = @gt_sflight-carrid.
10 ​
11 ​
12 CALL METHOD zcl_tab_oo_alv=>split_container
13   EXPORTING
14     iv_container_name = 'CONTAINER'
15     i_row             = 1
16     i_col             = 2
17   IMPORTING
18     et_container_t    = DATA(lt_container_t).
19 ​
20 CHECK lt_container_t IS NOT INITIAL.
21 ​
22 DATA(cl_oo_alv1) = NEW zcl_tab_oo_alv( ).
23 DATA(cl_oo_alv2) = NEW zcl_tab_oo_alv( ).
24 ​
25 ​
26 READ TABLE lt_container_t INTO DATA(ls_container) INDEX 1.
27 IF sy-subrc EQ 0.
28   CALL METHOD cl_oo_alv1->create_oo_alv
29     EXPORTING
30       iv_split_number    = 1
31       iv_split_container = ls_container-container
32     CHANGING
33       it_data            = gt_sflight.
34 ENDIF.
35 ​
36 READ TABLE lt_container_t INTO ls_container INDEX 2.
37 IF sy-subrc EQ 0.
38   CALL METHOD cl_oo_alv1->create_oo_alv
39     EXPORTING
40       iv_split_number    = 2
41       iv_split_container = ls_container-container
42     CHANGING
43       it_data            = gt_scarr.
44 ENDIF.
45 ​
46 ​
47 CALL SCREEN 9000.

三 ZCL_TAB_OO_ALV代码如下

  1 CLASS zcl_tab_oo_alv DEFINITION
  2   PUBLIC
  3   CREATE PUBLIC .
  4 
  5 *&=====================================================================*
  6 *& Create date:  2021.08.26
  7 *& Created by:   Tab-Zhu (微信公众号:Tab_JXZHU)
  8 *&---------------------------------------------------------------------*
  9   PUBLIC SECTION.
 10 
 11     TYPES:
 12       BEGIN OF ty_splits,
 13         row       TYPE i,
 14         col       TYPE i,
 15         container TYPE REF TO cl_gui_container,
 16       END OF ty_splits .
 17     TYPES:
 18       ty_t_splits TYPE TABLE OF ty_splits .
 19 
 20     CONSTANTS gc_a TYPE c VALUE 'A' ##NO_TEXT.
 21     CONSTANTS gc_d TYPE c VALUE 'D' ##NO_TEXT.
 22     DATA cr_grid TYPE REF TO cl_gui_alv_grid .
 23     DATA cr_container TYPE REF TO cl_gui_custom_container .
 24     DATA split_n TYPE i .
 25     DATA m_repid TYPE progname .
 26     DATA m_f4_form TYPE string .                                         "
 27     DATA m_toolbar_form TYPE string .
 28     DATA m_hotspot_form TYPE string .
 29     DATA m_user_command_form TYPE string .
 30     DATA m_datachanged_form TYPE string .
 31     DATA m_datachanged_finished_form TYPE string .
 32     DATA m_before_ucomm_form TYPE string .
 33     DATA m_double_click_form TYPE string .
 34     DATA m_menu_button_form TYPE string .
 35 
 36     METHODS create_oo_alv
 37       IMPORTING
 38         VALUE(iv_repid)              TYPE progname DEFAULT sy-cprog
 39         VALUE(iv_screen)             TYPE sy-dynnr DEFAULT '9000'               "默认屏幕号码
 40         VALUE(iv_default_ex)         TYPE char1 DEFAULT 'X'           "使用默认的按钮组
 41         VALUE(is_layout)             TYPE lvc_s_layo OPTIONAL
 42         VALUE(it_fieldcat)           TYPE lvc_t_fcat OPTIONAL
 43         VALUE(it_exclude)            TYPE ui_functions OPTIONAL              "需要排除的按钮
 44         VALUE(iv_split_number)       TYPE i OPTIONAL         "分割容器号码
 45         VALUE(iv_split_container)    TYPE REF TO cl_gui_container OPTIONAL            "分割容器号码有值时,请传入容器类,必填
 46         VALUE(iv_container_name)     TYPE char30 OPTIONAL       "当分割容器号没有值时,必填
 47         VALUE(iv_variant_handle)     TYPE disvariant-handle DEFAULT '1'
 48         !i_f4_form                   TYPE string OPTIONAL
 49         !i_toolbar_form              TYPE string OPTIONAL
 50         !i_user_command_form         TYPE string OPTIONAL
 51         !i_hotspot_form              TYPE string OPTIONAL
 52         !i_datachanged_form          TYPE string OPTIONAL
 53         !i_datachanged_finished_form TYPE string OPTIONAL
 54         !i_before_ucomm_form         TYPE string OPTIONAL
 55         !i_double_click_form         TYPE string OPTIONAL
 56         !i_menu_button_form          TYPE string OPTIONAL
 57       CHANGING
 58         !it_data                     TYPE STANDARD TABLE .
 59     "分割 容器
 60     CLASS-METHODS split_container
 61       IMPORTING
 62         !iv_container_name TYPE char30
 63         !i_row             TYPE i
 64         !i_col             TYPE i
 65       EXPORTING
 66         !et_container_t    TYPE ty_t_splits .
 67     "设置默认排除按钮-OO ALV
 68     CLASS-METHODS default_exclude_func
 69       EXPORTING
 70         VALUE(it_exclude) TYPE ui_functions .
 71     "得到默认字段属性-根据内表
 72     CLASS-METHODS get_default_fieldcat
 73       CHANGING
 74         !it_data           TYPE STANDARD TABLE
 75       RETURNING
 76         VALUE(rt_fieldcat) TYPE lvc_t_fcat
 77       EXCEPTIONS
 78         error_in_get_fieldcat .
 79     "得到默认的Layout
 80     CLASS-METHODS get_default_layout
 81       RETURNING
 82         VALUE(es_layout) TYPE lvc_s_layo .
 83     "设置按钮
 84     METHODS handle_toolbar
 85       FOR EVENT toolbar OF cl_gui_alv_grid
 86       IMPORTING
 87         !e_object
 88         !e_interactive .
 89     "设置F4帮助
 90     METHODS handle_f4
 91       FOR EVENT onf4 OF cl_gui_alv_grid
 92       IMPORTING
 93         !e_fieldname
 94         !e_fieldvalue
 95         !es_row_no
 96         !er_event_data
 97         !et_bad_cells
 98         !e_display .
 99     "设置热点单击
100     METHODS handle_hotspot
101       FOR EVENT hotspot_click OF cl_gui_alv_grid
102       IMPORTING
103         !e_row_id
104         !e_column_id
105         !es_row_no .
106     METHODS handle_user_command
107       FOR EVENT user_command OF cl_gui_alv_grid
108       IMPORTING
109         !e_ucomm .
110     METHODS handle_datachanged
111       FOR EVENT data_changed OF cl_gui_alv_grid
112       IMPORTING
113         !er_data_changed
114         !e_onf4
115         !e_onf4_before
116         !e_onf4_after
117         !e_ucomm .
118     METHODS handle_datachanged_finished
119       FOR EVENT data_changed_finished OF cl_gui_alv_grid
120       IMPORTING
121         !e_modified
122         !et_good_cells .
123     METHODS handle_before_ucomm
124       FOR EVENT before_user_command OF cl_gui_alv_grid
125       IMPORTING
126         !e_ucomm .
127     METHODS handle_double_click
128       FOR EVENT double_click OF cl_gui_alv_grid
129       IMPORTING
130         !e_row
131         !e_column
132         !es_row_no .
133     METHODS handle_menu_button
134       FOR EVENT menu_button OF cl_gui_alv_grid
135       IMPORTING
136         !e_object
137         !e_ucomm .
138   PROTECTED SECTION.
139   PRIVATE SECTION.
140 ENDCLASS.
141 
142 
143 
144 CLASS ZCL_TAB_OO_ALV IMPLEMENTATION.
145 
146 
147 * <SIGNATURE>---------------------------------------------------------------------------------------+
148 * | Instance Public Method ZCL_TAB_OO_ALV->CREATE_OO_ALV
149 * +-------------------------------------------------------------------------------------------------+
150 * | [--->] IV_REPID                       TYPE        PROGNAME (default =SY-CPROG)
151 * | [--->] IV_SCREEN                      TYPE        SY-DYNNR (default ='9000')
152 * | [--->] IV_DEFAULT_EX                  TYPE        CHAR1 (default ='X')
153 * | [--->] IS_LAYOUT                      TYPE        LVC_S_LAYO(optional)
154 * | [--->] IT_FIELDCAT                    TYPE        LVC_T_FCAT(optional)
155 * | [--->] IT_EXCLUDE                     TYPE        UI_FUNCTIONS(optional)
156 * | [--->] IV_SPLIT_NUMBER                TYPE        I(optional)
157 * | [--->] IV_SPLIT_CONTAINER             TYPE REF TO CL_GUI_CONTAINER(optional)
158 * | [--->] IV_CONTAINER_NAME              TYPE        CHAR30(optional)
159 * | [--->] IV_VARIANT_HANDLE              TYPE        DISVARIANT-HANDLE (default ='1')
160 * | [--->] I_F4_FORM                      TYPE        STRING(optional)
161 * | [--->] I_TOOLBAR_FORM                 TYPE        STRING(optional)
162 * | [--->] I_USER_COMMAND_FORM            TYPE        STRING(optional)
163 * | [--->] I_HOTSPOT_FORM                 TYPE        STRING(optional)
164 * | [--->] I_DATACHANGED_FORM             TYPE        STRING(optional)
165 * | [--->] I_DATACHANGED_FINISHED_FORM    TYPE        STRING(optional)
166 * | [--->] I_BEFORE_UCOMM_FORM            TYPE        STRING(optional)
167 * | [--->] I_DOUBLE_CLICK_FORM            TYPE        STRING(optional)
168 * | [--->] I_MENU_BUTTON_FORM             TYPE        STRING(optional)
169 * | [<-->] IT_DATA                        TYPE        STANDARD TABLE
170 * +--------------------------------------------------------------------------------------</SIGNATURE>
171   METHOD create_oo_alv.
172 
173     DATA lt_filedcat TYPE lvc_t_fcat.
174     DATA ls_layout TYPE lvc_s_layo.
175     "iv_split_number
176     "判断是否是分割容器
177     IF iv_split_number IS INITIAL.
178       CREATE OBJECT cr_container
179         EXPORTING
180           container_name = iv_container_name. "屏幕上用户自定义控件名
181 * create alv
182       CREATE OBJECT cr_grid
183         EXPORTING
184           i_parent = cr_container.
185     ELSE.
186       "分割容器
187       CREATE OBJECT cr_grid
188         EXPORTING
189           i_parent = iv_split_container.
190     ENDIF.
191 
192     CHECK cr_grid IS NOT INITIAL.
193 
194     DATA lt_exclude TYPE ui_functions.
195     IF iv_default_ex = 'X'.
196       "使用默认排除按钮
197       CALL METHOD me->default_exclude_func
198         IMPORTING
199           it_exclude = lt_exclude.
200     ENDIF.
201     "手动排除按钮
202     IF it_exclude[] IS NOT INITIAL.
203       APPEND LINES OF it_exclude TO lt_exclude.
204       SORT lt_exclude.
205       DELETE ADJACENT DUPLICATES FROM lt_exclude.
206     ENDIF.
207     "布局
208     IF is_layout IS NOT INITIAL.
209       ls_layout = is_layout.
210     ELSE.
211       ls_layout = me->get_default_layout( ).
212     ENDIF.
213     "字段目录
214     IF it_fieldcat[] IS NOT INITIAL.
215       lt_filedcat = it_fieldcat.
216     ELSE.
217       CALL METHOD me->get_default_fieldcat
218         CHANGING
219           it_data               = it_data
220         RECEIVING
221           rt_fieldcat           = lt_filedcat
222         EXCEPTIONS
223           error_in_get_fieldcat = 1
224           OTHERS                = 2.
225       IF sy-subrc NE 0.
226         MESSAGE e368(00) WITH 'Failed to get fiedlcat' ''.
227       ENDIF.
228     ENDIF.
229 
230     "变式布局
231     DATA:ls_disvariant TYPE disvariant.
232     ls_disvariant-report = sy-repid.
233     ls_disvariant-handle = iv_variant_handle.
234     ls_disvariant-username = sy-uname.
235 
236 *    CALL METHOD
237     CALL METHOD cr_grid->set_table_for_first_display
238       EXPORTING
239         is_variant           = ls_disvariant
240         i_default            = abap_on
241         i_save               = gc_a
242         is_layout            = ls_layout
243         it_toolbar_excluding = lt_exclude
244       CHANGING
245         it_outtab            = it_data
246         it_fieldcatalog      = lt_filedcat.
247 *SET EVENT
248     DEFINE d_set_handler.
249       IF &1 IS SUPPLIED.
250         &2 = &1.
251         SET HANDLER me->&3 FOR cr_grid.
252       ENDIF.
253     END-OF-DEFINITION.
254 
255     m_repid = iv_repid.
256 
257     "绑定事件
258     d_set_handler:
259       i_f4_form                     m_f4_form                     handle_f4,
260       i_toolbar_form                m_toolbar_form                handle_toolbar,
261       i_user_command_form           m_user_command_form           handle_user_command,
262       i_hotspot_form                m_hotspot_form                handle_hotspot,
263       i_datachanged_form            m_datachanged_form            handle_datachanged,
264       i_datachanged_finished_form   m_datachanged_finished_form   handle_datachanged_finished,
265       i_before_ucomm_form           m_before_ucomm_form           handle_before_ucomm,
266       i_double_click_form           m_double_click_form           handle_double_click,
267       i_menu_button_form            m_menu_button_form            handle_menu_button.
268 
269 *    SET HANDLER me->handle_toolbar       FOR cr_grid.
270 *    SET HANDLER me->handle_datachanged_finished  FOR cr_grid.
271 *    SET HANDLER me->handle_datachanged FOR cr_grid.
272 *    SET HANDLER me->handle_user_command  FOR cr_grid.
273 *    SET HANDLER me->handle_hotspot FOR cr_grid .
274 
275     CALL METHOD cr_grid->set_toolbar_interactive.
276 * register enter event
277     CALL METHOD cr_grid->register_edit_event
278       EXPORTING
279         i_event_id = cl_gui_alv_grid=>mc_evt_enter
280       EXCEPTIONS
281         error      = 1
282         OTHERS     = 2.
283     IF sy-subrc NE 0.
284       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1
285       sy-msgv2 sy-msgv3 sy-msgv4.
286     ENDIF.
287 
288     CALL METHOD cr_grid->register_edit_event     "register modify event
289       EXPORTING
290         i_event_id = cl_gui_alv_grid=>mc_evt_modified
291       EXCEPTIONS
292         error      = 1
293         OTHERS     = 2.
294     IF sy-subrc NE 0.
295       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1
296       sy-msgv2 sy-msgv3 sy-msgv4.
297     ENDIF.
298 
299   ENDMETHOD.
300 
301 
302 * <SIGNATURE>---------------------------------------------------------------------------------------+
303 * | Static Public Method ZCL_TAB_OO_ALV=>DEFAULT_EXCLUDE_FUNC
304 * +-------------------------------------------------------------------------------------------------+
305 * | [<---] IT_EXCLUDE                     TYPE        UI_FUNCTIONS
306 * +--------------------------------------------------------------------------------------</SIGNATURE>
307   METHOD default_exclude_func.
308     DATA: ls_exclude TYPE ui_func.
309     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy .
310     APPEND ls_exclude TO it_exclude.
311     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row .
312     APPEND ls_exclude TO it_exclude.
313     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
314     APPEND ls_exclude TO it_exclude.
315     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
316     APPEND ls_exclude TO it_exclude.
317     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
318     APPEND ls_exclude TO it_exclude.
319     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
320     APPEND ls_exclude TO it_exclude.
321     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
322     APPEND ls_exclude TO it_exclude.
323     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
324     APPEND ls_exclude TO it_exclude.
325     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
326     APPEND ls_exclude TO it_exclude.
327     ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
328     APPEND ls_exclude TO it_exclude.
329     ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
330     APPEND ls_exclude TO it_exclude.
331     ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
332     APPEND ls_exclude TO it_exclude.
333 *  ls_exclude = cl_gui_alv_grid=>mc_fc_view_excel.
334 *  append ls_exclude to it_exclude.
335     ls_exclude = cl_gui_alv_grid=>mc_fc_view_lotus .
336     APPEND ls_exclude TO it_exclude.
337 *    LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_MB_EXPORT .
338 *    APPEND LS_EXCLUDE TO IT_EXCLUDE.
339     ls_exclude = cl_gui_alv_grid=>mc_fc_sum .
340     APPEND ls_exclude TO it_exclude.
341     ls_exclude = cl_gui_alv_grid=>mc_fc_average .
342     APPEND ls_exclude TO it_exclude.
343 *  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_MB_SUBTOT .
344 *  APPEND LS_EXCLUDE TO it_exclude.
345     ls_exclude = cl_gui_alv_grid=>mc_fc_check.
346     APPEND ls_exclude TO it_exclude.
347     ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
348     APPEND ls_exclude TO it_exclude.
349 
350 *  ls_exclude = '&LOAD'.
351 *  append ls_exclude to it_exclude.
352 *  LS_EXCLUDE = '&COL0'.
353 *  APPEND LS_EXCLUDE TO it_exclude.
354 *  LS_EXCLUDE = '&SAVE '.
355 *  APPEND LS_EXCLUDE TO it_exclude.
356 *  LS_EXCLUDE = '&MAINTAIN '.
357 *  APPEND LS_EXCLUDE TO IT_EXCLUDE.
358     ls_exclude = cl_gui_alv_grid=>mc_fc_detail.
359     APPEND ls_exclude TO it_exclude.
360     ls_exclude = cl_gui_alv_grid=>mc_fc_print .
361     APPEND ls_exclude TO it_exclude.
362     ls_exclude = '&INFO'.
363     APPEND ls_exclude TO it_exclude.
364     ls_exclude = '&GRAPH'.
365     APPEND ls_exclude TO it_exclude.
366   ENDMETHOD.
367 
368 
369 * <SIGNATURE>---------------------------------------------------------------------------------------+
370 * | Static Public Method ZCL_TAB_OO_ALV=>GET_DEFAULT_FIELDCAT
371 * +-------------------------------------------------------------------------------------------------+
372 * | [<-->] IT_DATA                        TYPE        STANDARD TABLE
373 * | [<-()] RT_FIELDCAT                    TYPE        LVC_T_FCAT
374 * | [EXC!] ERROR_IN_GET_FIELDCAT
375 * +--------------------------------------------------------------------------------------</SIGNATURE>
376   METHOD get_default_fieldcat.
377     DATA: salv_table TYPE REF TO cl_salv_table.
378     TRY.
379         cl_salv_table=>factory( IMPORTING
380                                   r_salv_table   = salv_table
381                                 CHANGING
382                                   t_table        = it_data[] ).
383         rt_fieldcat = cl_salv_controller_metadata=>get_lvc_fieldcatalog(
384             r_columns      = salv_table->get_columns( ) " ALV Filter
385             r_aggregations = salv_table->get_aggregations( ) " ALV Aggregations
386     ).
387       CATCH cx_root INTO DATA(lx_root).
388         DATA(lv_text) = lx_root->get_text( ).
389         RAISE error_in_get_fieldcat.
390     ENDTRY.
391 
392     "当你的内表字段不是参考数据库结构/表创建的时候,F4搜索帮助有图标但是无效
393     "有2种处理方法
394     "1. F4AVAILABL = abap_false
395     "2. 加上:REF_TABLE ,REF_FIELD
396 
397 
398   ENDMETHOD.
399 
400 
401 * <SIGNATURE>---------------------------------------------------------------------------------------+
402 * | Static Public Method ZCL_TAB_OO_ALV=>GET_DEFAULT_LAYOUT
403 * +-------------------------------------------------------------------------------------------------+
404 * | [<-()] ES_LAYOUT                      TYPE        LVC_S_LAYO
405 * +--------------------------------------------------------------------------------------</SIGNATURE>
406   METHOD get_default_layout.
407     es_layout-sel_mode    = gc_d ."
408     es_layout-zebra = abap_on. "
409     es_layout-cwidth_opt = abap_on. "
410   ENDMETHOD.
411 
412 
413 * <SIGNATURE>---------------------------------------------------------------------------------------+
414 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_BEFORE_UCOMM
415 * +-------------------------------------------------------------------------------------------------+
416 * | [--->] E_UCOMM                        LIKE
417 * +--------------------------------------------------------------------------------------</SIGNATURE>
418   METHOD handle_before_ucomm.
419     PERFORM (m_before_ucomm_form) IN PROGRAM (m_repid) IF FOUND
420       USING e_ucomm.
421 *FORM 示例
422 *FORM handle_before_ucomm USING e_ucomm TYPE sy-ucomm.
423 *ENDFORM.                    "handle_before_ucomm
424   ENDMETHOD.
425 
426 
427 * <SIGNATURE>---------------------------------------------------------------------------------------+
428 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_DATACHANGED
429 * +-------------------------------------------------------------------------------------------------+
430 * | [--->] ER_DATA_CHANGED                LIKE
431 * | [--->] E_ONF4                         LIKE
432 * | [--->] E_ONF4_BEFORE                  LIKE
433 * | [--->] E_ONF4_AFTER                   LIKE
434 * | [--->] E_UCOMM                        LIKE
435 * +--------------------------------------------------------------------------------------</SIGNATURE>
436   METHOD handle_datachanged.
437     PERFORM (m_datachanged_form) IN PROGRAM (m_repid) IF FOUND
438           USING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.
439 *FORM 示例
440 *FORM handle_datachanged_cpmx USING  er_data_changed TYPE REF TO cl_alv_changed_data_protocol
441 *                                    e_onf4 TYPE char01
442 *                                    e_onf4_before TYPE char01
443 *                                    e_onf4_after TYPE char01
444 *                                    e_ucomm TYPE sy-ucomm.
445 *  FIELD-SYMBOLS: <ls_cell> TYPE lvc_s_modi.
446 *  DATA: ls_cpmx TYPE ty_cpmx,
447 *        lt_mod_cells TYPE lvc_t_modi WITH HEADER LINE.
448 *
449 *  CLEAR: g_error.
450 *
451 *  DEFINE add_protocol_entry.
452 *    g_error = 'X'.
453 *    call method er_data_changed->add_protocol_entry
454 *      exporting
455 *        i_msgid     = &1
456 *        i_msgty     = &2
457 *        i_msgno     = &3
458 *        i_msgv1     = &4
459 *        i_msgv2     = &5
460 *        i_msgv3     = &6
461 *        i_msgv4     = &7
462 *        i_fieldname = <ls_cell>-fieldname
463 *        i_row_id    = <ls_cell>-row_id
464 *        i_tabix     = <ls_cell>-tabix.
465 *  END-OF-DEFINITION.
466 *  DEFINE modify_cell.
467 *    call method er_data_changed->modify_cell
468 *      exporting
469 *        i_row_id    = <ls_cell>-row_id
470 *        i_tabix     = <ls_cell>-tabix
471 *        i_fieldname = &1
472 *        i_value     = &2.
473 *  END-OF-DEFINITION.
474 *
475 *  LOOP AT er_data_changed->mt_mod_cells ASSIGNING <ls_cell>.
476 *    CASE <ls_cell>-fieldname.
477 *      WHEN 'BUKRS'.  "公司代码描述
478 *        CLEAR gs_t001.
479 *        READ TABLE gt_t001 INTO gs_001 WITH KEY bukrs = <ls_cell>-value.
480 *        IF sy-subrc <> 0 AND <ls_cell>-value IS NOT INITIAL.
481 *          add_protocol_entry: '00' 'E' '001' '公司代码:' <ls_cell>-value '不存在' ''.
482 *        ENDIF.
483 *        modify_cell: 'BUTXT' gs_001-butxt.
484 *    ENDCASE.
485 *  ENDLOOP.
486   ENDMETHOD.
487 
488 
489 * <SIGNATURE>---------------------------------------------------------------------------------------+
490 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_DATACHANGED_FINISHED
491 * +-------------------------------------------------------------------------------------------------+
492 * | [--->] E_MODIFIED                     LIKE
493 * | [--->] ET_GOOD_CELLS                  LIKE
494 * +--------------------------------------------------------------------------------------</SIGNATURE>
495   METHOD handle_datachanged_finished.
496     PERFORM (m_datachanged_finished_form) IN PROGRAM (m_repid) IF FOUND
497   USING e_modified et_good_cells.
498 *FORM 示例
499 *FORM handle_datachanged_finished USING  e_modified TYPE char01
500 *                                        et_good_cells TYPE lvc_t_modi.
501 *ENDFORM.                    "HANDLE_DATACHANGED_FINISHED
502   ENDMETHOD.
503 
504 
505 * <SIGNATURE>---------------------------------------------------------------------------------------+
506 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_DOUBLE_CLICK
507 * +-------------------------------------------------------------------------------------------------+
508 * | [--->] E_ROW                          LIKE
509 * | [--->] E_COLUMN                       LIKE
510 * | [--->] ES_ROW_NO                      LIKE
511 * +--------------------------------------------------------------------------------------</SIGNATURE>
512   METHOD handle_double_click.
513     PERFORM (m_double_click_form) IN PROGRAM (m_repid) IF FOUND
514       USING e_row e_column es_row_no.
515 *FORM 示例
516 *FORM handle_double_click USING  e_row TYPE lvc_s_row
517 *                                e_column TYPE lvc_s_col
518 *                                es_row_no TYPE lvc_s_roid.
519 *ENDFORM.                    "handle_before_ucomm
520   ENDMETHOD.
521 
522 
523 * <SIGNATURE>---------------------------------------------------------------------------------------+
524 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_F4
525 * +-------------------------------------------------------------------------------------------------+
526 * | [--->] E_FIELDNAME                    LIKE
527 * | [--->] E_FIELDVALUE                   LIKE
528 * | [--->] ES_ROW_NO                      LIKE
529 * | [--->] ER_EVENT_DATA                  LIKE
530 * | [--->] ET_BAD_CELLS                   LIKE
531 * | [--->] E_DISPLAY                      LIKE
532 * +--------------------------------------------------------------------------------------</SIGNATURE>
533   METHOD handle_f4.
534     PERFORM (m_f4_form) IN PROGRAM (m_repid) IF FOUND
535     USING e_fieldname e_fieldvalue es_row_no er_event_data et_bad_cells e_display.
536 *FORM 示例
537 *FORM handle_f4  USING           e_fieldname TYPE lvc_fname
538 *                                e_fieldvalue TYPE lvc_value
539 *                                es_row_no TYPE lvc_s_roid
540 *                                er_event_data TYPE REF TO cl_alv_event_data
541 *                                et_bad_cells TYPE lvc_t_modi
542 *                                e_display TYPE char01.
543 *  DATA: ls_row TYPE lvc_s_row,
544 *        ls_col TYPE lvc_s_col,
545 *        ls_modi TYPE lvc_s_modi,
546 *        l_tabname TYPE tabname,
547 *        l_fieldtext TYPE fieldtext,
548 *        l_ref_table TYPE lvc_rtname,
549 *        l_ref_field TYPE lvc_rfname.
550 *  FIELD-SYMBOLS: <lt_modi> TYPE lvc_t_modi.
551 *
552 *  er_event_data->m_event_handled = 'X'.
553 *
554 *  CASE e_fieldname.
555 *    WHEN 'TABNAME'.
556 *      PERFORM f4_dd_table(rsaqddic) USING 'SAPLAQJD_CNTRL'
557 *                                          '0300'
558 *                                          'G_DYN_0300-TNAME'
559 *                                    CHANGING e_fieldvalue.  "搜索帮助代码,来于SQVI中“插入表”的搜索帮助
560 *    WHEN OTHERS.
561 *      EXIT.
562 *  ENDCASE.
563 *
564 *  ASSIGN er_event_data->m_data->* TO <lt_modi>.
565 *  ls_modi-row_id    = es_row_no-row_id."
566 *  ls_modi-fieldname = e_fieldname.
567 *  ls_modi-value     = e_fieldvalue.
568 *  APPEND ls_modi TO <lt_modi>.
569 *  IF e_fieldname = 'FIELDNAME'.
570 *    ls_modi-row_id    = es_row_no-row_id."
571 *    ls_modi-fieldname = 'SCRTEXT_L'.
572 *    ls_modi-value     = l_fieldtext.
573 *    APPEND ls_modi TO <lt_modi>.
574 *
575 *    ls_modi-row_id    = es_row_no-row_id."
576 *    ls_modi-fieldname = 'REF_TABLE'.
577 *    ls_modi-value     = l_ref_table.
578 *    APPEND ls_modi TO <lt_modi>.
579 *
580 *    ls_modi-row_id    = es_row_no-row_id."
581 *    ls_modi-fieldname = 'REF_FIELD'.
582 *    ls_modi-value     = l_ref_field.
583 *    APPEND ls_modi TO <lt_modi>.
584 *  ENDIF.
585 *
586 *ENDFORM.
587   ENDMETHOD.
588 
589 
590 * <SIGNATURE>---------------------------------------------------------------------------------------+
591 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_HOTSPOT
592 * +-------------------------------------------------------------------------------------------------+
593 * | [--->] E_ROW_ID                       LIKE
594 * | [--->] E_COLUMN_ID                    LIKE
595 * | [--->] ES_ROW_NO                      LIKE
596 * +--------------------------------------------------------------------------------------</SIGNATURE>
597   METHOD handle_hotspot.
598     PERFORM (m_hotspot_form) IN PROGRAM (m_repid) IF FOUND
599       USING e_row_id e_column_id es_row_no.
600 *FORM 示例
601 *FORM handle_hotspot  USING    p_row_id     TYPE lvc_s_row
602 *                              p_column_id  TYPE lvc_s_col
603 *                              p_row_no     TYPE lvc_s_roid.
604 *  CASE p_column_id-fieldname.
605 *    WHEN 'COUNT'.
606 *  ENDCASE.
607 *ENDFORM.
608   ENDMETHOD.                    "handle_hotspot
609 
610 
611 * <SIGNATURE>---------------------------------------------------------------------------------------+
612 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_MENU_BUTTON
613 * +-------------------------------------------------------------------------------------------------+
614 * | [--->] E_OBJECT                       LIKE
615 * | [--->] E_UCOMM                        LIKE
616 * +--------------------------------------------------------------------------------------</SIGNATURE>
617   METHOD handle_menu_button.
618     PERFORM (m_menu_button_form) IN PROGRAM (m_repid) IF FOUND USING e_object e_ucomm.
619 *FORM 示例
620 *FORM handle_menu_button  USING  e_object TYPE REF TO cl_ctmenu
621 *                                e_ucomm TYPE sy-ucomm.
622 *  CASE e_ucomm.
623 *    WHEN 'MENU'.
624 *      CALL METHOD e_object->add_function
625 *        EXPORTING
626 *          fcode = 'MENU1'
627 *          text  = '菜单1'.
628 *  ENDCASE.
629 *ENDFORM.                    "handle_menu_button
630   ENDMETHOD.
631 
632 
633 * <SIGNATURE>---------------------------------------------------------------------------------------+
634 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_TOOLBAR
635 * +-------------------------------------------------------------------------------------------------+
636 * | [--->] E_OBJECT                       LIKE
637 * | [--->] E_INTERACTIVE                  LIKE
638 * +--------------------------------------------------------------------------------------</SIGNATURE>
639   METHOD handle_toolbar.
640     PERFORM (m_toolbar_form) IN PROGRAM (m_repid) IF FOUND USING e_object e_interactive.
641 *FORM 示例
642 *FORM handle_toolbar USING   e_object TYPE REF TO cl_alv_event_toolbar_set
643 *                            e_interactive TYPE char1.
644 *  DATA: ls_toolbar TYPE stb_button.
645 *
646 *  ls_toolbar-function = 'IMPORT'.
647 *  ls_toolbar-icon = icon_import.
648 *  ls_toolbar-text = '导入表格字段'.
649 *  ls_toolbar-quickinfo = '导入表格字段'.
650 *  APPEND ls_toolbar TO e_object->mt_toolbar.
651 *  CLEAR: ls_toolbar.
652 *
653 *  ls_toolbar-function = 'ALL'.
654 *  ls_toolbar-text = '输出:全选'.
655 *  ls_toolbar-quickinfo = '全部输出'.
656 *  APPEND ls_toolbar TO e_object->mt_toolbar.
657 *  CLEAR: ls_toolbar.
658 *
659 *  ls_toolbar-function = 'NONE'.
660 *  ls_toolbar-text = '输出:取消全选'.
661 *  ls_toolbar-quickinfo = '全部不输出'.
662 *  APPEND ls_toolbar TO e_object->mt_toolbar.
663 *  CLEAR: ls_toolbar.
664 *ENDFORM.
665   ENDMETHOD.
666 
667 
668 * <SIGNATURE>---------------------------------------------------------------------------------------+
669 * | Instance Public Method ZCL_TAB_OO_ALV->HANDLE_USER_COMMAND
670 * +-------------------------------------------------------------------------------------------------+
671 * | [--->] E_UCOMM                        LIKE
672 * +--------------------------------------------------------------------------------------</SIGNATURE>
673   METHOD handle_user_command.
674     PERFORM (m_user_command_form) IN PROGRAM (m_repid) IF FOUND USING e_ucomm.
675 *FORM 示例
676 *FORM handle_user_command  USING    e_ucomm TYPE sy-ucomm.
677 *  DATA: ok_code TYPE sy-ucomm.
678 *  ok_code = e_ucomm.
679 *  CLEAR e_ucomm.
680 *
681 *  CASE ok_code.
682 *    WHEN 'IMPORT'.
683 *      go_alv->refresh_table_display( ).
684 *  ENDCASE.
685 *ENDFORM.
686   ENDMETHOD.
687 
688 
689 * <SIGNATURE>---------------------------------------------------------------------------------------+
690 * | Static Public Method ZCL_TAB_OO_ALV=>SPLIT_CONTAINER
691 * +-------------------------------------------------------------------------------------------------+
692 * | [--->] IV_CONTAINER_NAME              TYPE        CHAR30
693 * | [--->] I_ROW                          TYPE        I
694 * | [--->] I_COL                          TYPE        I
695 * | [<---] ET_CONTAINER_T                 TYPE        TY_T_SPLITS
696 * +--------------------------------------------------------------------------------------</SIGNATURE>
697   METHOD split_container.
698     DATA lv_row TYPE i.
699     DATA lv_col TYPE i.
700     DATA ls_splits TYPE ty_splits.
701     DATA(lo_cc) = NEW cl_gui_custom_container( container_name = iv_container_name ).
702     IF lo_cc IS BOUND.
703       DATA(lo_split) = NEW cl_gui_splitter_container( parent = lo_cc rows = i_row columns = i_col ).
704     ENDIF.
705 
706     lv_row = 1.
707     lv_col = 1.
708     DO.
709       DATA(lo_split_cc1) = lo_split->get_container( EXPORTING
710       row       = lv_row
711       column    = lv_col
712       ).
713       CHECK lo_split_cc1 IS BOUND.
714       ls_splits-row = lv_row.
715       ls_splits-col = lv_col.
716       ls_splits-container = lo_split_cc1.
717       APPEND ls_splits TO et_container_t.
718       CLEAR ls_splits.
719 
720       IF lv_col < i_col.
721         lv_col = lv_col + 1.
722       ELSE.
723         "lv_col = i_col
724         IF lv_row < i_row.
725           lv_row = lv_row + 1.
726         ELSE.
727           EXIT.
728         ENDIF.
729       ENDIF.
730       CLEAR lo_split_cc1.
731     ENDDO.
732 
733   ENDMETHOD.
734 ENDCLASS.

希望对大家的开发有帮助哈

标签:OO,26,form,alv,ls,ALV,exclude,TYPE,row
来源: https://www.cnblogs.com/jxzhu/p/15187670.html