program z. *---------------------------------------------------------------------* * Constants * *---------------------------------------------------------------------* *---------------------------------------------------------------------* * Types * *---------------------------------------------------------------------* class lcl_event_receiver definition deferred. class cl_gui_cfw definition load. *---------------------------------------------------------------------* * Data * *---------------------------------------------------------------------* * It is important: this internal table MUST be declared as global * data (not in the fill_grid method), otherwise * some cl_gui_alv_grid buttons will not work. * ...I don't know why... data it_t001 type table of t001. *---------------------------------------------------------------------* * Classes * *---------------------------------------------------------------------* *---------------------------------------------------------------------* * Definitions * *---------------------------------------------------------------------* *---------------------------------------------------------------------* class screen_init definition create private. public section. class-methods init_screen. methods constructor. private section. data: splitter type ref to cl_gui_splitter_container, grid type ref to cl_gui_alv_grid, gs_print type lvc_s_prnt, gs_layout type lvc_s_layo, e_handler type ref to lcl_event_receiver. methods fill_grid. endclass. *---------------------------------------------------------------------* class lcl_event_receiver definition. public section. * methods for print events. methods: handle_top_of_page for event print_top_of_page of cl_gui_alv_grid, handle_end_of_page for event print_end_of_page of cl_gui_alv_grid, handle_top_of_list for event print_top_of_list of cl_gui_alv_grid, handle_end_of_list for event print_end_of_list of cl_gui_alv_grid. private section. data: pagenum type i. endclass. *---------------------------------------------------------------------* *---------------------------------------------------------------------* * Implementations * *---------------------------------------------------------------------* *---------------------------------------------------------------------* class screen_init implementation. method init_screen. data screen type ref to screen_init. create object screen. endmethod. method constructor. * It is important: grid MUST have container as parent, * not the cl_gui_container=>screen0 * otherwise after pressing "Print" button * grid will not hide and printer options window * will be invisible behind the grid. * ...I don't know why... data container type ref to cl_gui_container. create object splitter exporting parent = cl_gui_container=>screen0 rows = 1 columns = 1. call method splitter->set_border exporting border = cl_gui_cfw=>false. call method splitter->set_column_mode exporting mode = splitter->mode_absolute. container = splitter->get_container( row = 1 column = 1 ). create object grid exporting i_parent = container. gs_layout-grid_title = 'Companies table T001.'. * reserve two lines for the print_end_of_page event gs_print-reservelns = 2. call method me->fill_grid. create object e_handler. set handler e_handler->handle_top_of_list for grid. set handler e_handler->handle_top_of_page for grid. set handler e_handler->handle_end_of_list for grid. set handler e_handler->handle_end_of_page for grid. endmethod. method fill_grid. select * from t001 into table it_t001. call method grid->set_table_for_first_display exporting i_structure_name = 'T001' is_print = gs_print is_layout = gs_layout changing it_outtab = it_t001. endmethod. endclass. *---------------------------------------------------------------------* class lcl_event_receiver implementation. * event handler methods for print events. use write to provide output. method handle_top_of_page. add 1 to pagenum. write: / 'event: print_top_of_page #', pagenum, ' program:', sy-cprog. call method cl_gui_cfw=>flush. endmethod. method handle_end_of_page. write: / 'event: print_end_of_page #', pagenum, ' program:', sy-cprog. call method cl_gui_cfw=>flush. endmethod. method handle_top_of_list. write: / 'event: print_top_of_list, program:', sy-cprog. call method cl_gui_cfw=>flush. endmethod. method handle_end_of_list. write: / 'event: print_end_of_list, program:', sy-cprog. call method cl_gui_cfw=>flush. endmethod. endclass. *---------------------------------------------------------------------* *---------------------------------------------------------------------* * Program execution * *---------------------------------------------------------------------* load-of-program. call screen 100. *---------------------------------------------------------------------* * Dialog Modules PBO * *---------------------------------------------------------------------* module status_0100 output. set pf-status 'SCREEN_100'. set titlebar 'TIT_100'. call method screen_init=>init_screen. endmodule. *---------------------------------------------------------------------* * Dialog Modules PAI * *---------------------------------------------------------------------* module cancel input. leave program. endmodule. *----------------------------------------------------------------------*