81578 Ejemplo de Un Table Control Program Ado Mediante Alv
-
Upload
alex-valencia -
Category
Documents
-
view
228 -
download
0
Transcript of 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
1/22
Victor Voilevitch
1. Display table .
This tiny program just displays the T001 table using grid control and all its defaultfeatures.
Used object: cl_gui_alv_grid
2. Display table .
Like previous but added print events handling for printing the table contents using grid"Print" button.
Print events:
o print_top_of_list
o print_top_of_page
o print_end_of_page
o
print_end_of_list
Used object:
o cl_gui_alv_grid
o cl_gui_splitter_container
o cl_gui_container
3. Display table and show details.
Like previous but added double click event handling. After double clicking on a table line
detailed information for the line is displayed in another grid.
Events:
o print events (see above)
o double_click
Used object:
o cl_gui_alv_grid
o cl_gui_splitter_container
o cl_gui_container
o cl_gui_dialogbox_container
4. Display table and show details.
Like previous but added my own button to the grid toolbar. The function is the same as fordouble click.
Events:
o print events (see above)
o double_clicko toolbar
o user_command
http://ttp//www.geocities.com/victorav15/sapr3/http://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv1.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv2.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv3.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv4.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv1.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv2.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv3.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv4.htmhttp://ttp//www.geocities.com/victorav15/sapr3/ -
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
2/22
Used object:
o cl_gui_alv_grid
o cl_gui_splitter_container
o cl_gui_container
o cl_gui_dialogbox_container
o cl_alv_event_toolbar_set (in event handler)
5. Display table and show details.
Like previous but changed context menu for the column #2 - added my own function codeand disabled all standard functional codes. Context menus for other columns remainunchanged. The function is the same as for double click or additional button.
Events:
o
print events (see above)o double_click
o toolbar
o user_command
o context_menu_request
Used object:
o cl_gui_alv_grid
o cl_gui_splitter_container
o cl_gui_container
o cl_gui_dialogbox_container
o cl_alv_event_toolbar_set (in event handler)o cl_ctmenu (in event handler)
http://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv5.htmhttp://www.sap4.com/sap/ejemplos/alvgrid/zvvooa_alv5.htm -
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
3/22
REPORT1
program z.
*---------------------------------------------------------------------** Constants **---------------------------------------------------------------------**---------------------------------------------------------------------** Types **---------------------------------------------------------------------**---------------------------------------------------------------------** 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 grid type ref to cl_gui_alv_grid.methods fill_grid.endclass.*---------------------------------------------------------------------**---------------------------------------------------------------------** Implementations **---------------------------------------------------------------------**---------------------------------------------------------------------*class screen_init implementation.method init_screen.data screen type ref to screen_init.create object screen.endmethod.
method constructor.create object grid exporting i_parent = cl_gui_container=>screen0.call method me->fill_grid.endmethod.method fill_grid.select * from t001 into table it_t001.call method grid->set_table_for_first_displayexporting i_structure_name = 'T001'changing it_outtab = it_t001.endmethod.endclass.*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Program execution **---------------------------------------------------------------------*
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
4/22
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.*----------------------------------------------------------------------*
Screen 100 is empty:
PROCESS BEFORE OUTPUT.MODULE status_0100.
PROCESS AFTER INPUT.MODULE cancel AT EXIT-COMMAND.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
5/22
REPORT2
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_pageof cl_gui_alv_grid,handle_end_of_page for event print_end_of_pageof cl_gui_alv_grid,handle_top_of_list for event print_top_of_listof cl_gui_alv_grid,handle_end_of_list for event print_end_of_listof cl_gui_alv_grid.private section.data: pagenum type i.endclass.*---------------------------------------------------------------------*
*---------------------------------------------------------------------** Implementations *
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
6/22
*---------------------------------------------------------------------**---------------------------------------------------------------------*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 splitterexporting parent = cl_gui_container=>screen0rows = 1columns = 1.
call method splitter->set_borderexporting border = cl_gui_cfw=>false.call method splitter->set_column_modeexporting 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 eventgs_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_displayexporting i_structure_name = 'T001'is_print = gs_printis_layout = gs_layoutchanging 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.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
7/22
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.*----------------------------------------------------------------------*
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
8/22
REPORT3
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 listsplitter 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 windowgrid2 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_clickof cl_gui_alv_gridimporting e_row e_column,handle_close for event closeof cl_gui_dialogbox_containerimporting sender,* methods for print events.
handle_top_of_page for event print_top_of_pageof cl_gui_alv_grid,
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
9/22
handle_end_of_page for event print_end_of_pageof cl_gui_alv_grid,handle_top_of_list for event print_top_of_listof cl_gui_alv_grid,handle_end_of_list for event print_end_of_listof 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 splitterexporting parent = cl_gui_container=>screen0rows = 1columns = 1.
call method splitter->set_borderexporting border = cl_gui_cfw=>false.call method splitter->set_column_modeexporting 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 eventgs_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_titleseparated 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
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
10/22
* when the user switches to another screen, it is* destroyed by lifetime mangagement of cfwcreate object dialogboxexportingtop = 50left = 150
lifetime = cntl_lifetime_dynprocaption = gs_layout2-grid_titlewidth = 800height = 200.create object grid2exporting 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_displayexporting i_structure_name = 'T001K'is_print = gs_print2is_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_displayexporting i_structure_name = 'T001'is_print = gs_printis_layout = gs_layoutchanging 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_t001kwhere bukrs = wa_t001-bukrs.call method this_screen->show_detailsexporting 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
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
11/22
* 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.*----------------------------------------------------------------------*
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
12/22
REPORT4
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,get_selected changing p_rows type lvc_t_row.private section.data: "---- main listsplitter 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 windowgrid2 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_clickof cl_gui_alv_gridimporting e_row e_column,handle_close for event closeof cl_gui_dialogbox_containerimporting sender,
* methods for additional button on toolbar.* add own button to toolbar.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
13/22
handle_toolbar for event toolbar of cl_gui_alv_gridimporting e_object e_interactive,* handle user command when user press additional button.handle_user_command for event user_commandof cl_gui_alv_gridimporting e_ucomm,
* methods for print events.handle_top_of_page for event print_top_of_pageof cl_gui_alv_grid,handle_end_of_page for event print_end_of_pageof cl_gui_alv_grid,handle_top_of_list for event print_top_of_listof cl_gui_alv_grid,handle_end_of_list for event print_end_of_listof 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 splitterexporting parent = cl_gui_container=>screen0rows = 1columns = 1.call method splitter->set_borderexporting border = cl_gui_cfw=>false.call method splitter->set_column_modeexporting 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 eventgs_print-reservelns = 2.
call method me->fill_grid.create object e_handler.set handler e_handler->handle_toolbar for grid.set handler e_handler->handle_user_command for grid.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.* call method 'set_toolbar_interactive' to raise event toolbar.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
14/22
call method grid->set_toolbar_interactive.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 eventgs_print-reservelns = 2.* create dialogbox container as dynpro-instance* when the user switches to another screen, it is* destroyed by lifetime mangagement of cfwcreate object dialogboxexportingtop = 50left = 150
lifetime = cntl_lifetime_dynprocaption = gs_layout2-grid_titlewidth = 800height = 200.create object grid2exporting 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_displayexporting i_structure_name = 'T001K'is_print = gs_print2is_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_displayexporting i_structure_name = 'T001'is_print = gs_printis_layout = gs_layoutchanging it_outtab = it_t001.endmethod.*-------------------------------*method get_selected.call method grid->get_selected_rowsimporting et_index_rows = p_rows.endmethod.endclass.*---------------------------------------------------------------------*
class lcl_event_receiver implementation.* event handler methods for toolbar event.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
15/22
*-------------------------------*method handle_toolbar.data: ls_toolbar type stb_button.*....................................................................* e_object of event toolbar is of type ref to cl_alv_event_toolbar_set.* this class has got one attribute, namely mt_toolbar, which
* is a table of type ttb_button. one line of this table is* defined by the structure stb_button (see data declaration above).* a remark to the flag e_interactive:* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* 'e_interactive' is set, if this event is raised due to* the call of 'set_toolbar_interactive' by the user.* you can distinguish this way if the event was raised* by yourself or by alv* (e.g. in method 'refresh_table_display').* an application of this feature is still unknown... :-)
* append a separator to normal toolbarclear ls_toolbar.move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.* append an icon to show booking tableclear ls_toolbar.move 'PLANTS' to ls_toolbar-function.move '@A8@' to ls_toolbar-icon. "ICON_PLANTmove 'show plants list' to ls_toolbar-quickinfo.move 'Plants for the Company' to ls_toolbar-text.move ' ' to ls_toolbar-disabled.append ls_toolbar to e_object->mt_toolbar.endmethod.* event handler methods for user_command event.*-------------------------------*method handle_user_command.
data: wa_t001 like line of it_t001,wa_t001k like line of it_t001k,lt_rows type lvc_t_row,ls_selected_line type lvc_s_row.case e_ucomm.when 'PLANTS'.call method this_screen->get_selected changing p_rows = lt_rows.call method cl_gui_cfw=>flush.loop at lt_rows into ls_selected_line.read table it_t001 index ls_selected_line-index into wa_t001.select * from t001k into table it_t001kwhere bukrs = wa_t001-bukrs.call method this_screen->show_details
exporting p_bukrs = wa_t001-bukrs.endloop.endcase.endmethod.* 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_t001kwhere bukrs = wa_t001-bukrs.call method this_screen->show_details
exporting p_bukrs = wa_t001-bukrs.endmethod.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
16/22
*-------------------------------*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.*----------------------------------------------------------------------*
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
17/22
REPORT5
program z.
* The context menu for the 2nd column does the same* as "Plants List" button* Context menus for other columns remain unchanged.*---------------------------------------------------------------------*
* 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,get_selected changing p_rows type lvc_t_row,get_current_cell exporting p_col type i.private section.data: "---- main listsplitter 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_clickof cl_gui_alv_grid
importing e_row e_column,handle_close for event close
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
18/22
of cl_gui_dialogbox_containerimporting sender,* methods for additional button on toolbar.* add own button to toolbar.handle_toolbar for event toolbar of cl_gui_alv_gridimporting e_object e_interactive,
* handle user command when user press additional button.handle_user_command for event user_commandof cl_gui_alv_gridimporting e_ucomm,* method for context menu.handle_context_menu for event context_menu_requestof cl_gui_alv_gridimporting e_object,* methods for print events.handle_top_of_page for event print_top_of_pageof cl_gui_alv_grid,handle_end_of_page for event print_end_of_pageof cl_gui_alv_grid,
handle_top_of_list for event print_top_of_listof cl_gui_alv_grid,handle_end_of_list for event print_end_of_listof 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 splitterexporting parent = cl_gui_container=>screen0rows = 1columns = 1.call method splitter->set_borderexporting border = cl_gui_cfw=>false.call method splitter->set_column_modeexporting 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 eventgs_print-reservelns = 2.
call method me->fill_grid.create object e_handler.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
19/22
set handler e_handler->handle_toolbar for grid.set handler e_handler->handle_user_command for grid.set handler e_handler->handle_context_menu for grid.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.* call method 'set_toolbar_interactive' to raise event toolbar.call method grid->set_toolbar_interactive.endmethod.*-------------------------------*method show_details.data grid_title type lvc_title.concatenate 'Plants for' p_bukrs into grid_titleseparated 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 eventgs_print-reservelns = 2.* create dialogbox container as dynpro-instance* when the user switches to another screen, it is* destroyed by lifetime mangagement of cfwcreate object dialogboxexportingtop = 50left = 150lifetime = cntl_lifetime_dynprocaption = gs_layout2-grid_titlewidth = 800height = 200.
create object grid2exporting 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_displayexporting i_structure_name = 'T001K'is_print = gs_print2is_layout = gs_layout2changing 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_displayexporting i_structure_name = 'T001'is_print = gs_printis_layout = gs_layout
changing it_outtab = it_t001.endmethod.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
20/22
*-------------------------------*method get_selected.call method grid->get_selected_rowsimporting et_index_rows = p_rows.endmethod.*-------------------------------*
method get_current_cell.call method grid->get_current_cell importing e_col = p_col.endmethod.endclass.*---------------------------------------------------------------------*class lcl_event_receiver implementation.* event handler methods for toolbar event.*-------------------------------*method handle_toolbar.data: ls_toolbar type stb_button.*....................................................................* e_object of event toolbar is of type ref to cl_alv_event_toolbar_set.* this class has got one attribute, namely mt_toolbar, which
* is a table of type ttb_button. one line of this table is* defined by the structure stb_button (see data declaration above).* a remark to the flag e_interactive:* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* 'e_interactive' is set, if this event is raised due to* the call of 'set_toolbar_interactive' by the user.* you can distinguish this way if the event was raised* by yourself or by alv* (e.g. in method 'refresh_table_display').* an application of this feature is still unknown... :-)
* append a separator to normal toolbarclear ls_toolbar.move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.* append an icon to show booking tableclear ls_toolbar.move 'PLANTS' to ls_toolbar-function.move '@A8@' to ls_toolbar-icon. "ICON_PLANTmove 'show plants list' to ls_toolbar-quickinfo.move 'Plants for the Company' to ls_toolbar-text.move ' ' to ls_toolbar-disabled.append ls_toolbar to e_object->mt_toolbar.endmethod.* event handler methods for user_command event.*-------------------------------*method handle_user_command.
data: wa_t001 like line of it_t001,wa_t001k like line of it_t001k,lt_rows type lvc_t_row,ls_selected_line type lvc_s_row.case e_ucomm.when 'PLANTS' "from additional buttonor 'MPLANTS'. "from context menucall method this_screen->get_selected changing p_rows = lt_rows.call method cl_gui_cfw=>flush.loop at lt_rows into ls_selected_line.read table it_t001 index ls_selected_line-index into wa_t001.select * from t001k into table it_t001kwhere bukrs = wa_t001-bukrs.
call method this_screen->show_detailsexporting p_bukrs = wa_t001-bukrs.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
21/22
endloop.endcase.endmethod.* event handler methods for context_menu_request event.*-------------------------------*method handle_context_menu.
data: lt_std_fcodes type ui_functions,lt_std_fc_get type ui_funcattr,std_fc type uiattentry,lt_own_fcodes type ui_functions,li_sel_col type i. "selected column*....................................................................* e_object of event context_menu_request is of type ref to cl_ctmenu.
* query which column was selected.call method this_screen->get_current_cellimporting p_col = li_sel_col.call method cl_gui_cfw=>flush.check sy-subrc = 0.
* change menu only for 2nd column
check li_sel_col = 2.* add new function code
append 'MPLANTS' to lt_own_fcodes.call method e_object->add_function exportingfcode = 'MPLANTS'text = 'Display Plants'.
* build table for standard functionscall method e_object->get_functionsimporting fcodes = lt_std_fc_get.loop at lt_std_fc_get into std_fc.append std_fc-fcode to lt_std_fcodes.endloop.
* disable all standard functions and show new function
call method: e_object->disable_functionsexporting fcodes = lt_std_fcodes,e_object->enable_functionsexporting fcodes = lt_own_fcodes,cl_gui_cfw=>flush.endmethod.* 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_detailsexporting 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.
-
8/2/2019 81578 Ejemplo de Un Table Control Program Ado Mediante Alv
22/22
*------------------------------------------------------------* 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.*----------------------------------------------------------------------*