ALV Master-Detail
Простой пример Master-detail отчёта, при выборе в Master ALV обновляются данные в Detail ALV. Использование интерфейса if_alv_rm_grid_friend обусловлено необходимостью доступа к защищённому методу set_delay_change_selection. Альтернативным вариантом будет сделать свой класс от грида и в его конструкторе вызвать данный метод.
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 |
CLASS lcl_app DEFINITION FINAL. PUBLIC SECTION. INTERFACES: if_alv_rm_grid_friend. METHODS: run, handle_change_selection FOR EVENT delayed_changed_sel_callback OF cl_gui_alv_grid. DATA: mt_flights TYPE STANDARD TABLE OF sflight, mt_sbooks TYPE STANDARD TABLE OF sbook, mt_sbooks_all LIKE mt_sbooks. PRIVATE SECTION. DATA: mo_master_alv TYPE REF TO cl_gui_alv_grid, mo_detail_alv TYPE REF TO cl_gui_alv_grid, mo_split_cont TYPE REF TO cl_gui_splitter_container, mo_master_cnt TYPE REF TO cl_gui_container, mo_detail_cnt TYPE REF TO cl_gui_container. METHODS: create_controls, read_data. ENDCLASS. CLASS lcl_app IMPLEMENTATION. METHOD run. read_data( ). create_controls( ). WRITE space. ENDMETHOD. METHOD handle_change_selection. CLEAR mt_sbooks. mo_master_alv->get_selected_rows( IMPORTING et_row_no = DATA(lt_rows) ). DELETE lt_rows WHERE row_id <= 0. LOOP AT lt_rows ASSIGNING FIELD-SYMBOL(<ls_rows>). READ TABLE mt_flights INDEX <ls_rows>-row_id ASSIGNING FIELD-SYMBOL(<ls_flight>). CHECK sy-subrc = 0. LOOP AT mt_sbooks_all ASSIGNING FIELD-SYMBOL(<ls_sbook>) WHERE carrid = <ls_flight>-carrid AND connid = <ls_flight>-connid AND fldate = <ls_flight>-fldate. INSERT <ls_sbook> INTO TABLE mt_sbooks. ENDLOOP. ENDLOOP. mo_detail_alv->refresh_table_display( EXPORTING is_stable = VALUE #( row = abap_true col = abap_true ) i_soft_refresh = abap_true EXCEPTIONS OTHERS = 0 ). ENDMETHOD. METHOD read_data. SELECT * FROM sflight INTO TABLE @mt_flights. SELECT * FROM sbook INTO TABLE @mt_sbooks_all. ENDMETHOD. METHOD create_controls. CREATE OBJECT mo_split_cont EXPORTING parent = cl_gui_container=>default_screen no_autodef_progid_dynnr = abap_true rows = 2 columns = 1 EXCEPTIONS OTHERS = 1. CHECK mo_split_cont IS BOUND. mo_split_cont->set_row_mode( EXPORTING mode = cl_gui_splitter_container=>mode_absolute EXCEPTIONS OTHERS = 0 ). mo_master_cnt = mo_split_cont->get_container( EXPORTING row = 1 column = 1 ). mo_detail_cnt = mo_split_cont->get_container( EXPORTING row = 2 column = 1 ). mo_master_alv = NEW cl_gui_alv_grid( i_parent = mo_master_cnt ). mo_master_alv->set_delay_change_selection( 1 ). mo_master_alv->register_delayed_event( i_event_id = cl_gui_alv_grid=>mc_evt_delayed_change_select ). mo_master_alv->set_table_for_first_display( EXPORTING i_structure_name = 'SFLIGHT' is_layout = VALUE #( sel_mode = 'A' ) CHANGING it_outtab = mt_flights ). SET HANDLER me->handle_change_selection FOR mo_master_alv. mo_detail_alv = NEW cl_gui_alv_grid( i_parent = mo_detail_cnt ). mo_detail_alv->set_table_for_first_display( EXPORTING i_structure_name = 'SBOOK' CHANGING it_outtab = mt_sbooks ). ENDMETHOD. ENDCLASS. START-OF-SELECTION. NEW lcl_app( )->run( ). |