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

ALV Grid List Viewer: Display table and show details



 
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: 1636

PostPosted: Sat Sep 15, 2007 8:40 pm    Post subject: ALV Grid List Viewer: Display table and show details Reply with quote

Display table and added double click event handling. After double clicking on a table line detailed information for the line is displayed in another grid.
Events:
print events
double_click
Used object:

  • cl_gui_alv_grid
  • cl_gui_splitter_container
  • cl_gui_container
  • cl_gui_dialogbox_container

Code:
program z.

*---------------------------------------------------------------------*
*       Constants                                                     *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
*       Types                                                         *
*---------------------------------------------------------------------*
class lcl_event_receiver definition deferred.
class cl_gui_cfw definition load.
*---------------------------------------------------------------------*
*       Data                                                          *
*---------------------------------------------------------------------*
data: it_t001  type table of t001,
      it_t001k type table of t001k.
*---------------------------------------------------------------------*
*       Classes                                                       *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
*       Definitions                                                   *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
class screen_init definition create private.
  public section.
    class-methods  init_screen returning value(this)
                               type ref to screen_init.
    methods:       constructor,
                   show_details importing value(p_bukrs)
                                type t001-bukrs.
  private section.
    data:          "---- main list
                   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,
                   "---- detail list in an amodal window
                   grid2     type ref to cl_gui_alv_grid,
                   gs_print2 type lvc_s_prnt,
                   gs_layout2 type lvc_s_layo,
                   dialogbox type ref to cl_gui_dialogbox_container,
                   e_handler type ref to lcl_event_receiver.
    methods        fill_grid.
endclass.
*---------------------------------------------------------------------*
class lcl_event_receiver definition.
  public section.
* methods for double click.
    methods: handle_double_click for event double_click
                                 of cl_gui_alv_grid
                                 importing e_row e_column,
             handle_close for event close
                                 of cl_gui_dialogbox_container
                                 importing sender,
* methods for print events.
             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.
*---------------------------------------------------------------------*

*---------------------------------------------------------------------*
*       Data                                                          *
*---------------------------------------------------------------------*
data this_screen type ref to screen_init.

*---------------------------------------------------------------------*
*       Implementations                                               *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
class screen_init implementation.
*-------------------------------*
  method init_screen.
    data screen type ref to screen_init.
    create object screen.
    this = screen.
  endmethod.
*-------------------------------*
  method constructor.
    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_double_click for grid.
    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 show_details.
    data grid_title type lvc_title.
    concatenate 'Plants for' p_bukrs into grid_title
                  separated by space.
* create dialogbox to show detail list (if not already existent)
    if dialogbox is initial.
      gs_layout2-grid_title = grid_title.
* reserve two lines for the print_end_of_page event
      gs_print-reservelns = 2.
* create dialogbox container as dynpro-instance
* when the user switches to another screen, it is
* destroyed by lifetime mangagement of cfw
      create object dialogbox
          exporting
            top = 50
            left = 150
            lifetime = cntl_lifetime_dynpro
            caption = gs_layout2-grid_title
            width = 800
            height = 200.
      create object grid2
          exporting i_parent = dialogbox.
* register abap oo event 'close'. it is not necessary to register this
* event at the frontend (this is done during creation).
      set handler e_handler->handle_close for dialogbox.
      call method grid2->set_table_for_first_display
           exporting i_structure_name = 'T001K'
                     is_print         = gs_print2
                     is_layout        = gs_layout2
           changing  it_outtab        = it_t001k.
      call method cl_gui_control=>set_focus exporting control = grid2.
    else.
      call method:
        dialogbox->set_caption exporting caption = grid_title,
        dialogbox->set_visible exporting visible = 'x',
        grid2->set_gridtitle exporting i_gridtitle = grid_title,
        grid2->refresh_table_display.
    endif.
  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 dbl-click event.
*-------------------------------*
  method handle_double_click.
    data: wa_t001  like line of it_t001,
          wa_t001k like line of it_t001k.
    read table it_t001 index e_row-index into wa_t001.
    select * from t001k into table it_t001k
           where bukrs = wa_t001-bukrs.
    call method this_screen->show_details
                exporting p_bukrs = wa_t001-bukrs.
  endmethod.
*-------------------------------*
  method handle_close.
* set dialogbox invisible
* (the dialogbox is destroyed outomatically when the user
* switches to another dynpro).
    call method sender->set_visible exporting visible = space.
* in this example closing the dialogbox leads
* to make it invisible. it is also conceivable to destroy it
* and recreate it if the user doubleclicks a line again.
* displaying a great amount of data has a greater impact on performance.
  endmethod.

*------------------------------------------------------------
* 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'.
  this_screen = 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.