Периодически возникает потребность вывести несколько таблиц на одном экране
Все это можно сделать в одном контейнере, при этом обновлять таблицы можно как вместе так и отдельно. Также у каждой таблицы будет своя панель кнопок и заголовок.
Создадим небольшой пример. В верхнюю таблицу выводим материал и по двойному щелчку информация по нему отображается в нижнем окне.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
CLASS lcl_alv_table DEFINITION. PUBLIC SECTION. CLASS-DATA gtd_table_1 TYPE gty_t_table_1. CLASS-DATA gtd_table_2 TYPE gty_t_table_2. CLASS-DATA gtd_table_all TYPE gty_t_table_all. CLASS-METHODS refresh. METHODS: constructor, display CHANGING ctd_table_1 TYPE gty_t_table_1 ctd_table_2 TYPE gty_t_table_2 . PRIVATE SECTION. CLASS-DATA: lo_grid1 TYPE REF TO cl_gui_alv_grid " объект верхнего ALV , lo_grid2 TYPE REF TO cl_gui_alv_grid " объект нижнего ALV , lo_custom_container TYPE REF TO cl_gui_custom_container" общий контейнер , lo_splitter TYPE REF TO cl_gui_splitter_container " Разделитель , lo_container_1 TYPE REF TO cl_gui_container " Верхний контейнер , lo_container_2 TYPE REF TO cl_gui_container " Нижний контейнер. CONSTANTS lcs_stable TYPE lvc_s_stbl VALUE 'XX'. METHODS: excl_func IMPORTING iv_func TYPE ui_func RETURNING VALUE(rv_exclude) TYPE ui_func, set_toolbar CHANGING ctd_toolbar TYPE ui_functions, create_grid_1 CHANGING ctd_table_1 TYPE gty_t_table_1, create_grid_2 CHANGING ctd_table_2 TYPE gty_t_table_2, handle_double_click "двойной клик FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column. ENDCLASS. CLASS lcl_alv_table IMPLEMENTATION. METHOD constructor. DATA: lv_container TYPE scrfname VALUE 'CONTAINER'. "имя контейнера на экране 0100 * Создаем общий контейнер IF lo_custom_container IS INITIAL. CREATE OBJECT lo_custom_container EXPORTING container_name = lv_container. * горизонтально делим контейнер на верхнюю и нижнюю части CREATE OBJECT lo_splitter EXPORTING parent = lo_custom_container rows = 2 columns = 1. * Возвращаем верхний контейнер CALL METHOD lo_splitter->get_container EXPORTING row = 1 column = 1 RECEIVING container = lo_container_1. * Возвращаем нижний контейнер CALL METHOD lo_splitter->get_container EXPORTING row = 2 column = 1 RECEIVING container = lo_container_2. * Выставляем высоту верхнего контейнера в строках CALL METHOD lo_splitter->set_row_height EXPORTING id = 1 height = 45. ENDIF. display( CHANGING ctd_table_1 = gtd_table_1 ctd_table_2 = gtd_table_2 ). ENDMETHOD. METHOD display. IF lo_grid1 IS INITIAL . create_grid_1( CHANGING ctd_table_1 = ctd_table_1 ). " Если верхний ALV еще не создан, создаём ELSE. lo_grid1->refresh_table_display( ). " Иначе обновим отображение ENDIF. IF lo_grid2 IS INITIAL . " Если нижний ALV еще не создан, создаём create_grid_2( CHANGING ctd_table_2 = ctd_table_2 ). ELSE. lo_grid2->refresh_table_display( ). " Иначе обновим отображение ENDIF. ENDMETHOD. METHOD create_grid_1. DATA lt_fieldcat TYPE lvc_t_fcat. DATA ltd_toolbar TYPE ui_functions. DATA ls_layout TYPE lvc_s_layo. * Создаём объект грида CREATE OBJECT lo_grid1 EXPORTING i_parent = lo_container_1 EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. SET HANDLER handle_double_click FOR lo_grid1. "Для наглядности создаем каталог полей так, а не на основе структуры словаря APPEND INITIAL LINE TO lt_fieldcat ASSIGNING FIELD-SYMBOL(ls_fieldcat>). ls_fieldcat>-col_pos = '1' . ls_fieldcat>-fieldname = 'STATUS' . ls_fieldcat>-scrtext_l = 'Статус упаковки' . ls_fieldcat>-scrtext_s = 'Статус упаковки' . ls_fieldcat>-scrtext_m = 'Статус упаковки' . ls_fieldcat>-outputlen = 5. APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '2' . ls_fieldcat>-fieldname = 'MATNR' . ls_fieldcat>-scrtext_l = 'Материал' . ls_fieldcat>-scrtext_s = 'Материал' . ls_fieldcat>-scrtext_m = 'Материал' . ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '3' . ls_fieldcat>-fieldname = 'MAKTX' . ls_fieldcat>-scrtext_l = 'Краткий текст' . ls_fieldcat>-scrtext_s = 'Краткий текст' . ls_fieldcat>-scrtext_m = 'Краткий текст' . ls_fieldcat>-outputlen = 40. . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '4' . ls_fieldcat>-fieldname = 'LABST' . ls_fieldcat>-scrtext_l = 'Складской запас' . ls_fieldcat>-scrtext_s = 'Складской запас' . ls_fieldcat>-scrtext_m = 'Складской запас' . ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '5' . ls_fieldcat>-fieldname = 'MEINS' . ls_fieldcat>-scrtext_l = 'ЕИ' . ls_fieldcat>-scrtext_s = 'ЕИ' . ls_fieldcat>-scrtext_m = 'ЕИ' . ls_fieldcat>-domname = 'MEINS'. ls_fieldcat>-convexit = 'CUNIT'. ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '6' . ls_fieldcat>-fieldname = 'VEMNG' . ls_fieldcat>-scrtext_l = 'Упак. кол-во' . ls_fieldcat>-scrtext_s = 'Упак. кол-во' . ls_fieldcat>-scrtext_m = 'Упак. кол-во' . ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '7' . ls_fieldcat>-fieldname = 'no_puck_col' . ls_fieldcat>-scrtext_l = 'НеУпак. кол-во' . ls_fieldcat>-scrtext_s = 'НеУпак. кол-во' . ls_fieldcat>-scrtext_m = 'НеУпак. кол-во' . ls_fieldcat>-key = '' . set_toolbar( CHANGING ctd_toolbar = ltd_toolbar ). *... ALV-Control: Поле STATUS делаем светофором ls_layout-excp_fname = 'STATUS'. ls_layout-excp_rolln = space. ls_layout-excp_conds = space. ls_layout-excp_led = space. * Вывод таблицы CALL METHOD lo_grid1->set_table_for_first_display EXPORTING is_layout = ls_layout * is_print = ls_print * is_variant = ls_variant * i_default = lc_default * i_save = lc_save it_toolbar_excluding = ltd_toolbar CHANGING it_fieldcatalog = lt_fieldcat[] it_outtab = ctd_table_1. * it_sort = lt_sort. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * Перехват событий CALL METHOD lo_grid1->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. "---инициализация класса обработки событий в гриде CALL METHOD lo_grid1->set_ready_for_input EXPORTING i_ready_for_input = 1. ENDMETHOD. METHOD create_grid_2. DATA lt_fieldcat TYPE lvc_t_fcat. DATA ltd_toolbar TYPE ui_functions. * Создаём объект грида CREATE OBJECT lo_grid2 EXPORTING i_parent = lo_container_2 EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. "Для наглядности создаем каталог полей так, а не на основе структуры словаря APPEND INITIAL LINE TO lt_fieldcat ASSIGNING FIELD-SYMBOL(ls_fieldcat>). ls_fieldcat>-col_pos = '1' . ls_fieldcat>-fieldname = 'EXIDV' . ls_fieldcat>-scrtext_l = 'ЕО' . ls_fieldcat>-scrtext_s = 'ЕО' . ls_fieldcat>-scrtext_m = 'ЕО' . ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '2' . ls_fieldcat>-fieldname = 'EXIDV2' .. ls_fieldcat>-scrtext_l = 'Штрих-код' . ls_fieldcat>-scrtext_s = 'Штрих-код' . ls_fieldcat>-scrtext_m = 'Штрих-код' . ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '3' . ls_fieldcat>-fieldname = 'VEMNG' . ls_fieldcat>-scrtext_l = 'Упак. кол-во' . ls_fieldcat>-scrtext_s = 'Упак. кол-во' . ls_fieldcat>-scrtext_m = 'Упак. кол-во' . ls_fieldcat>-key = '' . APPEND INITIAL LINE TO lt_fieldcat ASSIGNING . ls_fieldcat>-col_pos = '4' . ls_fieldcat>-fieldname = 'ALTME' . ls_fieldcat>-scrtext_l = 'ЕИ' . ls_fieldcat>-scrtext_s = 'ЕИ' . ls_fieldcat>-scrtext_m = 'ЕИ' . ls_fieldcat>-domname = 'MEINS'. ls_fieldcat>-convexit = 'CUNIT'. ls_fieldcat>-key = '' . set_toolbar( CHANGING ctd_toolbar = ltd_toolbar ). * Вывод таблицы CALL METHOD lo_grid2->set_table_for_first_display EXPORTING * is_layout = ls_layout_grid2 * is_print = ls_print * is_variant = ls_variant * i_default = lc_default * i_save = lc_save it_toolbar_excluding = ltd_toolbar CHANGING it_fieldcatalog = lt_fieldcat[] it_outtab = ctd_table_2. * it_sort = lt_sort. IF sy-subrc NE 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. * Перехват событий CALL METHOD lo_grid2->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. "---инициализация класса обработки событий в гриде CALL METHOD lo_grid2->set_ready_for_input EXPORTING i_ready_for_input = 1. ENDMETHOD. METHOD set_toolbar. APPEND: excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_undo ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_print ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_cut ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_copy ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_refresh ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_paste ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_paste_new_row ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_mb_sum ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_graph ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_insert_row ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_copy_row ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_delete_row ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_append_row ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_loc_insert_row ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_info ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_views ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_check ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_detail ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_find_more ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_send ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_fc_view_excel ) TO ctd_toolbar, excl_func( iv_func = cl_gui_alv_grid=>mc_mb_export ) TO ctd_toolbar. ENDMETHOD. METHOD handle_double_click. "По двойному клику выбираем данные из таблицы gtd_table_all "Помещаем их в таблицу gtd_table_2 " И выводим DATA ls_layout_grid2 TYPE lvc_s_layo. READ TABLE gtd_table_1[] ASSIGNING FIELD-SYMBOL() INDEX e_row. CHECK sy-subrc IS INITIAL. CLEAR gtd_table_2[]. LOOP AT gtd_table_all ASSIGNING FIELD-SYMBOL() WHERE matnr = -matnr. APPEND INITIAL LINE TO gtd_table_2[] ASSIGNING FIELD-SYMBOL(). MOVE-CORRESPONDING TO . ENDLOOP. TRY. "Заголовок для второй таблицы ls_layout_grid2-grid_title = |{ gtd_table_2[ 1 ]-matnr } { gtd_table_2[ 1 ]-maktx }|. CATCH cx_root. ENDTRY. lo_grid2->set_frontend_layout( is_layout = ls_layout_grid2 ). lo_grid2->refresh_table_display( is_stable = lcs_stable ). ENDMETHOD. METHOD refresh. DATA ls_layout_grid2 TYPE lvc_s_layo. lo_grid1->refresh_table_display( is_stable = lcs_stable ). lo_grid2->set_frontend_layout( is_layout = ls_layout_grid2 ). lo_grid2->refresh_table_display( is_stable = lcs_stable ). ENDMETHOD. METHOD excl_func. rv_exclude = iv_func. ENDMETHOD. ENDCLASS. |
Пример хороший, но не доделанный.
Операторы отсутствуют.
Вызовов методов нет.
Программа не работоспособна.
Как полная программа это и не задумывалось. Кусочек с alv частью для образца