При необходимости добавить информацию перед таблицей cl_gui_alv_grid, может возникнуть вопрос как это сделать, т.к. Непосредственно сам класс, нам это не позволяет. В общем случае алгоритм точно такой же как и при выводе нескольких ALV в одном контейнере. Только вместо одной из таблиц мы будем выводить текст.
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 |
CLASS lcl_alv_table DEFINITION. PUBLIC SECTION. CLASS-METHODS refresh. METHODS: constructor IMPORTING itd_table_1 TYPE expo_mara_t OPTIONAL . PRIVATE SECTION. CLASS-DATA: lo_grid1 TYPE REF TO cl_gui_alv_grid, " объект верхнего ALV lo_custom_container TYPE REF TO cl_gui_custom_container. " общий контейнер DATA:oref_splitter TYPE REF TO cl_gui_splitter_container, container1 TYPE REF TO cl_gui_container, container2 TYPE REF TO cl_gui_container, oref_doc TYPE REF TO cl_dd_document, oref_html TYPE REF TO cl_gui_html_viewer. CLASS-DATA: gtd_table_alv TYPE expo_mara_t. "Таблица для отображения в АЛВ CONSTANTS lcs_stable TYPE lvc_s_stbl VALUE 'XX'. METHODS: display IMPORTING itd_table_1 TYPE expo_mara_t, set_toolbar CHANGING ctd_toolbar TYPE ui_functions, create_grid_1 IMPORTING itd_table_1 TYPE expo_mara_t, get_fiedcat IMPORTING it_qals TYPE expo_mara_t EXPORTING et_fieldcat TYPE lvc_t_fcat, handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column, handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive, handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm, top_of_page FOR EVENT top_of_page OF cl_gui_alv_grid IMPORTING e_dyndoc_id table_index, print_top_of_page FOR EVENT print_top_of_page OF cl_gui_alv_grid IMPORTING table_index . ENDCLASS. CLASS lcl_alv_table IMPLEMENTATION. METHOD constructor. DATA: lv_container TYPE scrfname VALUE 'CONTAINER'. "имя контейнера на экране 0100 gtd_table_alv = itd_table_1. display( EXPORTING itd_table_1 = gtd_table_alv ). ENDMETHOD. METHOD display. IF lo_grid1 IS INITIAL . create_grid_1( EXPORTING itd_table_1 = itd_table_1 ). " Если ALV еще не создан, создаём ELSE. lo_grid1->refresh_table_display( ). " Иначе обновим отображение ENDIF. ENDMETHOD. METHOD get_fiedcat. DATA lt_fieldcat TYPE lvc_t_fcat. CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'MARA' CHANGING ct_fieldcat = lt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. et_fieldcat = lt_fieldcat. ENDMETHOD. METHOD create_grid_1. DATA lt_fieldcat TYPE lvc_t_fcat. " fieldcatalog - table. DATA ltd_toolbar TYPE ui_functions. DATA ls_layout TYPE lvc_s_layo. " layout FIELD-SYMBOLS: TYPE STANDARD TABLE, TYPE any. DATA : ls_variant TYPE disvariant. IF lo_custom_container IS INITIAL. CREATE OBJECT lo_custom_container EXPORTING container_name = 'CONTAINER' repid = sy-cprog dynnr = '0100' EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 OTHERS = 6. IF sy-subrc 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CREATE OBJECT oref_splitter EXPORTING parent = lo_custom_container rows = 2 columns = 1 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 OTHERS = 3. IF sy-subrc 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL METHOD oref_splitter->get_container EXPORTING row = 1 column = 1 RECEIVING container = container1. CALL METHOD oref_splitter->set_row_height EXPORTING id = 1 height = 11 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 OTHERS = 3. IF sy-subrc 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CALL METHOD oref_splitter->get_container EXPORTING row = 2 column = 1 RECEIVING container = container2. CREATE OBJECT oref_doc EXPORTING style = 'ALV_GRID'. CREATE OBJECT lo_grid1 EXPORTING i_parent = container2 EXCEPTIONS error_cntl_create = 1 error_cntl_init = 2 error_cntl_link = 3 error_dp_create = 4 OTHERS = 5. IF sy-subrc 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDIF. SET HANDLER handle_double_click FOR lo_grid1. SET HANDLER handle_toolbar FOR lo_grid1. SET HANDLER handle_user_command FOR lo_grid1. SET HANDLER top_of_page FOR lo_grid1. SET HANDLER print_top_of_page FOR lo_grid1. get_fiedcat( EXPORTING it_qals = itd_table_1 IMPORTING et_fieldcat = lt_fieldcat ). set_toolbar( CHANGING ctd_toolbar = ltd_toolbar ). ls_variant-report = sy-repid. ls_layout-sel_mode = 'A'. * Вывод таблицы CALL METHOD lo_grid1->set_table_for_first_display EXPORTING is_layout = ls_layout is_variant = ls_variant i_save = 'A' it_toolbar_excluding = ltd_toolbar CHANGING it_fieldcatalog = lt_fieldcat[] it_outtab = gtd_table_alv. * 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. CALL METHOD oref_doc->initialize_document. CALL METHOD lo_grid1->list_processing_events EXPORTING i_event_name = 'TOP_OF_PAGE' i_dyndoc_id = oref_doc. ENDMETHOD. METHOD set_toolbar. ENDMETHOD. METHOD handle_double_click. ENDMETHOD. METHOD handle_user_command. ENDMETHOD. METHOD handle_toolbar. ENDMETHOD. METHOD refresh. lo_grid1->refresh_table_display( is_stable = lcs_stable ). ENDMETHOD. METHOD top_of_page. DATA: lv_text TYPE sdydo_text_element, lv_background_id TYPE sdydo_key VALUE 'ALV_BACKGROUND'. DATA lt_text_tab TYPE TABLE OF sdydo_text_element. CALL METHOD oref_doc->add_text EXPORTING text = 'Заголовок' sap_color = cl_dd_document=>list_positive sap_fontsize = cl_dd_document=>large. oref_doc->new_line( ). lv_text = 'Line1'. APPEND lv_text TO lt_text_tab. lv_text = 'Line2'. APPEND lv_text TO lt_text_tab. CALL METHOD oref_doc->add_text EXPORTING fix_lines = 'X' text_table = lt_text_tab. CREATE OBJECT oref_html EXPORTING parent = container1 EXCEPTIONS cntl_error = 1 cntl_install_error = 2 dp_install_error = 3 dp_error = 4 OTHERS = 5. IF sy-subrc 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. oref_doc->html_control = oref_html. CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET' EXPORTING document = oref_doc bottom = space. CALL METHOD oref_doc->merge_document. CALL METHOD oref_doc->set_document_background EXPORTING picture_id = lv_background_id. CALL METHOD oref_doc->display_document EXPORTING reuse_control = 'X' parent = container1 EXCEPTIONS html_display_error = 1 OTHERS = 2. IF sy-subrc 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDMETHOD. "create_top_of_page METHOD print_top_of_page. ENDMETHOD. ENDCLASS. |