oo alv 无屏幕
作者:互联网
1.定义
TYPES: it_fieldcat TYPE slis_t_fieldcat_alv.
CLASS lcl_event DEFINITION.
PUBLIC SECTION.
METHODS:
on_refresh_alv FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function,
on_user_commands FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function,
on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.
DATA: g_okcode LIKE sy-ucomm,
ok_code LIKE sy-ucomm.
DATA l_text TYPE char20.
DATA l_input1 TYPE char20.
DATA: gc_table TYPE REF TO cl_salv_table,
gc_events TYPE REF TO cl_salv_events_table,
gc_columns TYPE REF TO cl_salv_columns_table,
gc_column TYPE REF TO cl_salv_column_table,
gc_selection TYPE REF TO cl_salv_selections,
gc_layout TYPE REF TO cl_salv_layout,
gc_display TYPE REF TO cl_salv_display_settings,
gc_functions TYPE REF TO cl_salv_functions_list,
g_key TYPE salv_s_layout_key,
event_handler TYPE REF TO lcl_event,
it_fieldcat TYPE slis_t_fieldcat_alv,
color TYPE lvc_s_colo,
lt_lines LIKE TABLE OF tline WITH HEADER LINE,
lw_lines LIKE tline,
lv_tdname LIKE thead-tdname.
DATA: lt_rows TYPE salv_t_row,
l_rows TYPE i,
l_rowcount TYPE i,
l_r TYPE char5,
l_s TYPE char5,
l_fcount TYPE i,
l_f TYPE char5,
l_scount TYPE i,
l_info TYPE string,
l_fnm1 TYPE rs38l_fnam,
l_fnm2 TYPE rs38l_fnam.
2.alv方法调用及dialog实施
FORM frm_alv_output .
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = gc_table
CHANGING
t_table = gt_alvdsp.
CATCH cx_salv_msg .
ENDTRY.
"执行事件
gc_events = gc_table->get_event( ). "选择事件
CREATE OBJECT event_handler.
SET HANDLER event_handler->on_refresh_alv FOR gc_events.
SET HANDLER event_handler->on_user_commands FOR gc_events.
SET HANDLER event_handler->on_double_click FOR gc_events.
gc_selection = gc_table->get_selections( ).
gc_selection->set_selection_mode( 3 ). "可以以行、列的方式进行选择
gc_columns = gc_table->get_columns( ).
gc_columns->set_optimize( 'X' ).
TRY.
gc_columns = gc_table->get_columns( ).
gc_column ?= gc_columns->get_column( 'ZSEQN' ).
gc_column->set_short_text( '序号' ).
gc_column->set_medium_text( '序号' ).
gc_column->set_long_text( '序号' ).
CATCH cx_salv_not_found.
ENDTRY.
TRY.
gc_columns = gc_table->get_columns( ).
gc_column ?= gc_columns->get_column( 'ZDYBZ' ).
gc_column->set_short_text( '打印次数' ).
gc_column->set_medium_text( '打印次数' ).
gc_column->set_long_text( '打印次数' ).
CATCH cx_salv_not_found.
ENDTRY.
gc_display = gc_table->get_display_settings( ).
gc_display->set_striped_pattern( cl_salv_display_settings=>true ).
TRY.
CALL METHOD gc_table->set_screen_status
EXPORTING
report = sy-repid
pfstatus = 'STANDARD_FULLSCREEN'
set_functions = gc_table->c_functions_all.
ENDTRY.
gc_layout = gc_table->get_layout( ). "输出ALV的布局
g_key-report = sy-repid.
gc_layout->set_key( g_key ). "选择布局
gc_layout->set_save_restriction( cl_salv_layout=>restrict_none ). "保存布局
gc_layout->set_default( 'X' ).
* gc_functions = gc_table->get_functions( ).
* gc_functions->set_default( 'X' ).
gc_table->display( ).
ENDFORM.
CLASS lcl_event IMPLEMENTATION.
METHOD on_double_click.
DATA:lr_selections TYPE REF TO cl_salv_selections,
lt_cells TYPE salv_t_cell,
ls_cells TYPE salv_s_cell.
lr_selections = gc_table->get_selections( ).
lt_cells = lr_selections->get_selected_cells( ).
READ TABLE lt_cells INTO ls_cells INDEX 1.
READ TABLE gt_alvdsp INTO gw_alvdsp INDEX ls_cells-row.
CASE ls_cells-columnname.
WHEN 'TKNUM' . "运单双击
SET PARAMETER ID 'TNR' FIELD gw_alvdsp-tknum.
CALL TRANSACTION 'VT03N' AND SKIP FIRST SCREEN.
ENDCASE.
ENDMETHOD.
METHOD on_refresh_alv.
DATA: lc_cols TYPE REF TO cl_salv_columns_table,
lw_stbl TYPE lvc_s_stbl.
lc_cols = gc_table->get_columns( ).
lc_cols->set_optimize( abap_true ).
lw_stbl-row = cns_x.
lw_stbl-col = cns_x.
gc_table->refresh( s_stable = lw_stbl ).
ENDMETHOD.
METHOD on_user_commands.
DATA: lt_rows TYPE salv_t_row.
DATA: lt_cols TYPE salv_t_column.
DATA: ls_cols TYPE lvc_fname.
DATA: lc_selections TYPE REF TO cl_salv_selections.
DATA: ls_rows TYPE i.
DATA: lo_grid TYPE REF TO cl_gui_alv_grid,
lo_full_adap TYPE REF TO cl_salv_fullscreen_adapter.
DATA: ls_layout TYPE lvc_s_layo.
DATA: gc_grid TYPE REF TO cl_gui_alv_grid.
DATA: gw_stable TYPE lvc_s_stbl.
CASE e_salv_function.
WHEN 'RFS'.
* PERFORM frm_get_data.
me->on_refresh_alv( ).
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
ENDCLASS.
标签:oo,set,cl,gc,alv,table,屏幕,TYPE,salv 来源: https://blog.csdn.net/weixin_44193137/article/details/110492953