include
data grid1 type ref to cl_gui_alv_grid.
data: es_row_no type lvc_s_roid,
ls_row_id type lvc_s_row,
ls_col_id type lvc_s_col,
ls_row type i,
ls_value type c,
ls_col type i,
ls_row_no type lvc_s_roid.
types: row_table type table of lvc_s_roid.
data t_rows type row_table.
data: begin of wa_rows,
row_id type int4,
sub_row_id type int4,
end of wa_rows.
data: t_index type int4.
data: t_size type int4.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler definition .
public section .
methods:
**Hot spot Handler
handle_hotspot_click for event hotspot_click of cl_gui_alv_grid
importing e_row_id e_column_id es_row_no,
**Double Click Handler
handle_double_click for event double_click of cl_gui_alv_grid
importing e_row e_column es_row_no,
** Toolbar handler.
handle_toolbar
for event toolbar of cl_gui_alv_grid
importing e_object e_interactive,
* button press
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm,
* data changed
handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed,
*data changed finished
handle_data_changed_finished
for event data_changed of cl_gui_alv_grid.
endclass. "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler implementation.
*Handle Hotspot Click
method handle_hotspot_click .
perform mouse_click
using e_row_id
e_column_id.
call method grid1->get_current_cell
importing
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.
call method grid1->refresh_table_display.
call method grid1->set_current_cell_via_id
exporting
is_column_id = e_column_id
is_row_no = es_row_no.
endmethod. "lcl_event_handler
*Handle Double Click
method handle_double_click.
perform double_click
using e_row
e_column.
call method grid1->get_current_cell
importing
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.
call method grid1->refresh_table_display.
call method grid1->set_current_cell_via_id
exporting
is_column_id = ls_col_id
is_row_no = es_row_no.
endmethod. "handle_double_click
method handle_toolbar.
data: ls_toolbar type stb_button.
* append a separator to normal toolbar
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
* append an icon for your function
clear ls_toolbar.
move 'FUNC' to ls_toolbar-function.
move icon_railway to ls_toolbar-icon.
move 'Your Function' to ls_toolbar-quickinfo.
move 'Your user function' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
* Select All Rows
move 'SELE' to ls_toolbar-function.
move icon_select_all to ls_toolbar-icon.
move 'Select all' to ls_toolbar-quickinfo.
move 'Select entire Grid' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
* Deselect all Rows.
move 'DSEL' to ls_toolbar-function.
move icon_deselect_all to ls_toolbar-icon.
move 'Deselect all' to ls_toolbar-quickinfo.
move 'Deselect entire Grid' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "handle_toolbar
method handle_user_command.
break-point 1.
case e_ucomm.
when 'FUNC'. "Your button
* Perform what you need to do.
when 'SELE'.
perform select_all_rows.
when 'DSEL'.
perform deselect_all_rows.
when others.
endcase.
endmethod. "handle_user_command
method handle_data_changed.
perform data_changed using er_data_changed.
endmethod. "data_changed
method handle_data_changed_finished.
perform data_changed_finished.
endmethod. "data_changed_finished
endclass. "lcl_event_handler IMPLEMENTATION
* Define any structure
types: begin of s_elements,
vbeln type vapma-vbeln,
posnr type vapma-posnr,
matnr type vapma-matnr,
kunnr type vapma-kunnr,
werks type vapma-werks,
vkorg type vapma-vkorg,
vkbur type vapma-vkbur,
status type c,
end of s_elements.
* end of your structure
data:wa_elements type s_elements.
data: ord_nr type vapma-vbeln,
mat_nr type vapma-matnr,
cus_nr type vapma-kunnr.
data lr_rtti_struc type ref to cl_abap_structdescr .
data:
zog like line of lr_rtti_struc->components .
data:
zogt like table of zog,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat ,
dy_line type ref to data,
dy_table type ref to data.
data: dref type ref to data.
field-symbols:
data grid_container1 type ref to cl_gui_custom_container .
data grid_container2 type ref to cl_gui_custom_container.
data: g_handler type ref to lcl_event_handler. "handler
data: ok_code type sy-ucomm.
data: struct_grid_lset type lvc_s_layo.
start-of-selection.
*build the field catalog for dynamic table
* First get your data structure into a field symbol
create data dref type s_elements.
assign dref->* to
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data(
* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog
zogt[] = lr_rtti_struc->components.
loop at zogt into zog.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
if wa_it_fldcat-fieldname = 'VBELN'.
wa_it_fldcat-hotspot = 'X'.
endif.
append wa_it_fldcat to it_fldcat.
endloop.
*
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.
* Now using the field catalog created above we can
* build a dynamic table
* and populate it
* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = dy_table.
assign dy_table->* to
create data dy_line like line of
assign dy_line->* to
* Now fill our table with data
select vbeln posnr matnr kunnr werks vkorg vkbur
up to 200 rows
from vapma
into corresponding fields of table
* Call the screen to display the grid
call screen 200.
*&---------------------------------------------------------------------*
*& Form select_all_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form select_all_rows.
describe table
t_index = 1.
while t_index le t_size.
clear wa_rows.
wa_rows-row_id = t_index.
append wa_rows to t_rows.
t_index = t_index + 1.
endwhile.
call method grid1->set_selected_rows
exporting
it_row_no = t_rows.
endform. "select_all_rows
*&---------------------------------------------------------------------*
*& Form deselect_all_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form deselect_all_rows.
describe table
t_index = 1.
refresh t_rows.
clear wa_rows.
wa_rows-row_id = t_index.
append wa_rows to t_rows.
call method grid1->set_selected_rows
exporting
it_row_no = t_rows.
endform. "deselect_all_rows
*&---------------------------------------------------------------------*
*& Form double_click
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_ROW text
* -->E_COLUMN text
*----------------------------------------------------------------------*
form double_click
using e_row type lvc_s_row
e_column type lvc_s_col.
read table
case e_column-fieldname.
when 'MATNR'.
mat_nr = wa_elements-matnr.
set parameter id 'MAT' field mat_nr.
call transaction 'MM03' and skip first screen.
when 'KUNNR'.
cus_nr = wa_elements-kunnr.
set parameter id 'KUN' field cus_nr.
call transaction 'XD03' and skip first screen.
when others.
endcase.
wa_elements-status = 'V'.
modify
endform. "double_click
*&---------------------------------------------------------------------*
*& Form mouse_click
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_ROW text
* -->E_COLUMN_ID text
*----------------------------------------------------------------------*
form mouse_click
using e_row type lvc_s_row
e_column_id type lvc_s_col.
read table
ord_nr = wa_elements-vbeln.
set parameter id 'AUN' field ord_nr.
call transaction 'VA03' and skip first screen.
wa_elements-status = 'V'.
modify
endform. "mouse_click
*&---------------------------------------------------------------------*
*& Form data_changed
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->ER_DATA_CHANGED text
*----------------------------------------------------------------------*
form data_changed
using er_data_changed.
break-point 1.
endform. "data_changed
*&---------------------------------------------------------------------*
*& Form data_changed_finished
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form data_changed_finished.
break-point 1.
endform. "data_changed_finished
*&---------------------------------------------------------------------*
*& Form instantiate_grid
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->GRID_CONTAINER text
* -->CLASS_OBJECT text
* -->CONTAINER_NAME text
*----------------------------------------------------------------------*
form instantiate_grid
using grid_container type ref to cl_gui_custom_container
class_object type ref to cl_gui_alv_grid
container_name type scrfname.
data: lt_exclude type ui_functions,
ls_exclude type ui_func.
create object grid_container
exporting
container_name = container_name.
create object class_object
exporting
i_parent = grid_container.
struct_grid_lset-sel_mode = 'D'.
ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
append ls_exclude to lt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_check.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
*APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.
*APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_sort.
*APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_delete_filter.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_excl_all.
APPEND ls_exclude TO lt_exclude.
*
* struct_grid_lset-edit = 'X'.
create object g_handler.
set handler g_handler->handle_double_click for class_object.
set handler g_handler->handle_hotspot_click for class_object.
set handler g_handler->handle_toolbar for class_object.
set handler g_handler->handle_user_command for class_object.
set handler g_handler->handle_data_changed for class_object.
set handler g_handler->handle_data_changed_finished for class_object.
call method class_object->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
call method class_object->set_table_for_first_display
exporting
is_layout = struct_grid_lset
it_toolbar_excluding = lt_exclude
changing
it_outtab =
it_fieldcatalog = it_fldcat.
endform. "instantiate_grid
* PBO module
module status_0200 output.
if grid_container1 is initial.
perform instantiate_grid
using grid_container1
grid1
'ALV_CONTAINER'.
endif.
* SET PF-STATUS '001'.
* SET TITLEBAR '000'.
endmodule. "status_0100 OUTPUT
* PAI module
module user_command_0200 input.
case sy-ucomm.
when 'BACK'.
leave program.
when 'EXIT'.
leave program.
when 'RETURN'.
leave program.
when others.
endcase.
endmodule. "user_command_0100 INPUT
No comments:
Post a Comment