SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Grid ALV List Viewer: Display table with Print event



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Sep 15, 2007 8:36 pm    Post subject: Grid ALV List Viewer: Display table with Print event Reply with quote

Display table and added print events handling for printing the table contents using grid "Print" button.
Print events:
  • print_top_of_list
  • print_top_of_page
  • print_end_of_page
  • print_end_of_list

Used object:
  • cl_gui_alv_grid
  • cl_gui_splitter_container
  • cl_gui_container

Code:
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.
*----------------------------------------------------------------------*
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.