使用SALV实现的弹窗效果:
弹窗触发条件可以是按钮,或者通过双击等等
实现弹窗以及添加功能按钮过程:
data: go_funlst type ref to cl_salv_functions_list.
data: go_layout type ref to cl_salv_layout.
data: lv_name_no type sy-uname.
data:lv_date_end type sy-datum.
data: lo_cols type ref to cl_salv_columns.
*...Process individual columns
data: lo_column type ref to cl_salv_column.
data: cxroot type ref to cx_root,
excmsg type c.
data: lv_row type i.
clear:go_salv_table,go_funlst.
check gt_print_info[] is not initial.
cl_salv_table=>factory(
exporting
list_display = if_salv_c_bool_sap=>false " ALV Displayed in List Mode
importing
r_salv_table = go_salv_table
changing
t_table = gt_print_info[] ).
*...取得全部列的对象
lo_cols = go_salv_table->get_columns( ).
* 设置自动优化列宽度
lo_cols->set_optimize( 'X' ).
go_funlst = go_salv_table->get_functions( ).
go_funlst->set_all( 'X' ). "重新设置列名称
go_layout = go_salv_table->get_layout( ).
*隐藏字段属性
lo_column ?= lo_cols->get_column( 'SEL' ). "隐藏不想展示的字段
lo_column->set_visible( cl_salv_column_table=>false ).
lo_column ?= lo_cols->get_column( 'ROWS' ).
lo_column->set_visible( cl_salv_column_table=>false ).
if sy-langu eq '1'.
go_salv_table->get_columns( )->get_column( 'ROW' )->set_long_text( '行' ). "设置弹窗ALV的字段名
go_salv_table->get_columns( )->get_column( 'QTY_PNT' )->set_long_text( '打印份数' ).
go_salv_table->get_columns( )->get_column( 'MEINS_P' )->set_long_text( '单位' ).
else.
go_salv_table->get_columns( )->get_column( 'ROW' )->set_long_text( 'Row' ).
go_salv_table->get_columns( )->get_column( 'QTY_PNT' )->set_long_text( 'Print_qty' ).
go_salv_table->get_columns( )->get_column( 'MEINS_P' )->set_long_text( 'Unit' ).
endif.
if go_salv_table is bound."设置窗口大小与位置-
go_salv_table->set_screen_popup( start_column = 30 end_column = 100 start_line = 5 end_line = 20 ).
"单击/双击 事件注册调用
go_events = go_salv_table->get_event( ).
create object o_events.
set handler lcl_event_handler=>handle_double_click for go_events.
set handler o_events->on_user_command for go_events. "注册按钮事件
"设置自定义 PF STATUS
go_salv_table->set_screen_status(
pfstatus = 'SALV_STANDARD' "GUI 状态
report = 'ZHY_MM_F_GRMAT_QRCODE_TAG'
set_functions = go_salv_table->c_functions_all ).
"设置选择模式
go_selections = go_salv_table->get_selections( ).
go_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).
go_salv_table->display( ). "展示
go_salv_table->refresh( ).
endif.
准备工作:
1、复制一个标准的GUI状态到程序中
2、创建一个INCLUDE程序,实现双击、功能按钮等(ps:SALV的双击触发功能,是我通过注册事件实现的)
*----------------------------------------------------------------------*
* CLASS lcl_salv_buddy DEFINITION
*----------------------------------------------------------------------*
class lcl_salv_buddy definition inheriting from cl_salv_controller create private final.
public section.
*----------------------------------------------------------------------*
* GET_CONTROL_RTTI - Returns runtime type information for the control that is behind a SALV object.
*----------------------------------------------------------------------*
class-methods: get_control_rtti importing i_salv type ref to cl_salv_model_base
exporting e_adapter_type type salv_de_adapter_type
e_control_rtti type ref to cl_abap_typedescr,
*----------------------------------------------------------------------*
* GET_CONTROL - Returns the control that is behind the SALV object.
* MUST be called after the DISPLAY method of the SALV object, so that its control gets created.
* See method GET_CONTROL_RTTI above for a correspondence between what you supply in paramter I_SALV and what you get back in parameter R_CONTROL.
*----------------------------------------------------------------------*
get_control importing i_salv type ref to cl_salv_model_base
returning value(r_control) type ref to object,
*----------------------------------------------------------------------*
* SET_EDITABLE - Enables OR disables editing on a CL_SALV_TABLE object.
*----------------------------------------------------------------------*
set_editable importing value(i_fieldname) type csequence optional
i_salv_table type ref to cl_salv_table
value(i_editable) type abap_bool default abap_true
value(i_refresh) type abap_bool default abap_true.
private section.
*----------------------------------------------------------------------*
* GET_CONTROL_INTERNAL - It is the guts of method GET_CONTROL. It does all the heavy work and method GET_CONTROL gets all the credits
*----------------------------------------------------------------------*
class-methods: get_control_internal importing i_salv type ref to cl_salv_model_base
exporting e_adapter_type type salv_de_adapter_type
e_control type ref to object.
endclass. "lcl_salv_buddy DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_salv_buddy IMPLEMENTATION
*----------------------------------------------------------------------*
class lcl_salv_buddy implementation.
method get_control_internal.
data: lo_controller type ref to cl_salv_controller_model,
lo_adapter type ref to cl_salv_adapter,
lo_fullscreen_adapter type ref to cl_salv_fullscreen_adapter,
lo_grid_adapter type ref to cl_salv_grid_adapter,
lo_table_display_adapter type ref to if_salv_table_display_adapter,
lo_tree_adapter_base type ref to cl_salv_tree_adapter_base.
check e_adapter_type is requested or
e_control is requested.
if e_adapter_type is requested.
clear e_adapter_type.
endif.
if e_control is requested.
clear e_control.
endif.
lo_controller = i_salv->r_controller.
check lo_controller is bound.
lo_adapter = lo_controller->r_adapter.
check lo_adapter is bound.
if e_adapter_type is requested.
e_adapter_type = lo_adapter->type.
endif.
check e_control is requested.
case lo_adapter->type.
when lo_adapter->if_salv_adapter~c_adapter_type_fullscreen.
lo_fullscreen_adapter ?= lo_adapter.
e_control = lo_fullscreen_adapter->get_grid( ).
when lo_adapter->if_salv_adapter~c_adapter_type_grid.
lo_grid_adapter ?= lo_adapter.
e_control = lo_grid_adapter->get_grid( ).
when lo_adapter->if_salv_adapter~c_adapter_type_hierseq.
when lo_adapter->if_salv_adapter~c_adapter_type_list.
lo_table_display_adapter ?= lo_adapter.
e_control = lo_table_display_adapter->r_table.
when lo_adapter->if_salv_adapter~c_adapter_type_tree.
lo_tree_adapter_base ?= lo_adapter.
e_control = lo_tree_adapter_base->r_tree.
when lo_adapter->if_salv_adapter~c_adapter_type_append.
endcase.
endmethod. "get_control_internal
method get_control_rtti.
data: lv_adapter_type type salv_de_adapter_type,
lo_control type ref to object.
check e_adapter_type is requested or
e_control_rtti is requested.
if e_adapter_type is requested.
clear e_adapter_type.
endif.
if e_control_rtti is requested.
clear e_control_rtti.
endif.
get_control_internal( exporting i_salv = i_salv importing e_adapter_type = lv_adapter_type e_control = lo_control ).
if e_adapter_type is requested.
e_adapter_type = lv_adapter_type.
endif.
if e_control_rtti is requested.
e_control_rtti = cl_abap_typedescr=>describe_by_object_ref( lo_control ).
endif.
endmethod. "get_control_rtti
method get_control.
check r_control is requested.
get_control_internal( exporting i_salv = i_salv importing e_control = r_control ).
endmethod. "get_control
method set_editable.
constants: lc_stable type lvc_s_stbl value 'XX'.
data: lo_grid type ref to cl_gui_alv_grid,
lt_fieldcat type lvc_t_fcat,
ls_layout type lvc_s_layo.
field-symbols: <fs_fieldcat> like line of lt_fieldcat.
lo_grid ?= get_control( i_salv_table ).
check lo_grid is bound.
if i_fieldname is supplied and
i_fieldname is not initial.
lo_grid->get_frontend_fieldcatalog( importing et_fieldcatalog = lt_fieldcat ).
read table lt_fieldcat assigning <fs_fieldcat> with key fieldname = i_fieldname.
check sy-subrc = 0.
<fs_fieldcat>-edit = i_editable.
lo_grid->set_frontend_fieldcatalog( lt_fieldcat ).
else.
lo_grid->get_frontend_layout( importing es_layout = ls_layout ).
ls_layout-edit = i_editable.
lo_grid->set_frontend_layout( exporting is_layout = ls_layout ).
endif.
check i_refresh = abap_true.
i_salv_table->refresh( lc_stable ).
endmethod. "set_editable
endclass.
data: gv_editable type abap_bool,
go_salv_table type ref to cl_salv_table,
go_selections type ref to cl_salv_selections,
go_events type ref to cl_salv_events_table,
go_grid type ref to cl_gui_alv_grid.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler definition.
public section.
class-methods: handle_double_click for event double_click of cl_salv_events_table
importing row column.
methods:
on_user_command for event added_function of cl_salv_events
importing e_salv_function.
endclass. "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler implementation.
method handle_double_click.
if gv_editable = abap_false.
gv_editable = abap_true.
else.
gv_editable = abap_false.
endif.
lcl_salv_buddy=>set_editable( i_fieldname = 'MENGE_P' i_salv_table = go_salv_table i_editable = gv_editable ).
lcl_salv_buddy=>set_editable( i_fieldname = 'MEINS_P' i_salv_table = go_salv_table i_editable = gv_editable ).
lcl_salv_buddy=>set_editable( i_fieldname = 'QTY_PNT' i_salv_table = go_salv_table i_editable = gv_editable ).
endmethod. "handle_double_click
method on_user_command.
perform add_print_info using e_salv_function. "实现按钮事件
endmethod."on_user_command
endclass. "lcl_event_handler IMPLEMENTATION
data: o_events type ref to lcl_event_handler.
实现按钮事件的PERFORM,可以用来参考下:
form add_print_info using p_function_code.
data: lo_selections type ref to cl_salv_selections,
lt_cells type salv_t_cell,
lt_rows type salv_t_row,
ls_cell type salv_s_cell.
data lv_row type i.
data lt_print_info like table of gt_print_info.
data ls_print_info like gt_print_info.
"获取对象
lo_selections = go_salv_table->get_selections( ).
clear:lt_print_info.
case p_function_code.
when '&INS'.
lt_rows = lo_selections->get_selected_rows( ). "获取选中的行
if lt_rows is initial.
“实现你的功能
else.
“实现你的功能
endif.
when '&DEL'.
"选择的行(多单元格)
lt_rows = lo_selections->get_selected_rows( ).
if lt_rows is initial.
"实现你的功能
else.
“实现你的功能
endif.
when 'PRINT'.
perform prm_print_new.
when others.
endcase.
go_salv_table->refresh( )."刷新
endform.