用途
这是个简单的小工具,用于维护自建表。传统建完自建表,可能建一个SM30用于维护,SM30每张自建表都需要创建一次,如果字段有改变每次还需要调整,SM30的筛选排序这些没有alv方便,一次只能粘贴一页数据。
自开发个alv维护,有需要维护的自建表,配置把tcode和表名关联一下就好了,复制数据可以批量粘贴,也就不需要做批导功能了。
目前只有增删改查和传输的功能,如果有复杂需求,可以改一下,建个配置表关联事件,在新的事件程序里写处理代码就好了。
点进去选一下程序、表和class,tcode不要选了。
创建对象即可。
也可以自己复制代码粘贴进去,那要自己建表和status。
或者代码copy一下按自己需求改改也很快
使用
新建两个TCODE,一个用于维护TCODE和自建表的对应关系,一个用于维护自建表。
代码
*&---------------------------------------------------------------------*
*& REPORT Ztable
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ztable.
tables:sscrfields.
*&---------------------------------------------------------------------*
* TYPES
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* CONSTANTS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* GLOBAL DATA
*&---------------------------------------------------------------------*
* ALV变量
class lcl_event_receiver definition deferred.
data:
gv_container type ref to cl_gui_docking_container, "容器类
go_event_receiver type ref to lcl_event_receiver,
go_alvgrid type ref to cl_gui_alv_grid.
class lcl_event_receiver definition. "定义类 捕捉各种事件
public section.
methods data_changed_finished
for event data_changed_finished of cl_gui_alv_grid
importing e_modified
et_good_cells
sender.
endclass. "LCL_EVENT_RECEIVER DEFINITION
class lcl_event_receiver implementation. "实现类 处理事件
method data_changed_finished.
perform frm_alv_data_changed_finished using e_modified et_good_cells sender.
endmethod.
endclass. "LCL_EVENT_RECEIVER IMPLEMENTATION
data:
gt_fieldcat type lvc_t_fcat,
gt_excluding type ui_functions,
gs_layout type lvc_s_layo,
gs_styl type lvc_s_styl,
gt_styl type lvc_t_styl,
gt_events type slis_t_event with header line,
gt_event_exit type slis_t_event_exit with header line,
gs_grid_settings type lvc_s_glay.
data:
ct_fieldcat type lvc_t_fcat, "内表结构
go_alv_ref type ref to data,
gv_no_config, "没有配置tcode和表对应关系
gv_direct. "直接调用
field-symbols <gt_alv> type standard table.
data:
gt_ztfi025i like table of ztfi025i with header line.
*&---------------------------------------------------------------------*
* GLOBAL MACROS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* SELECTION-SCREEN
*&---------------------------------------------------------------------*
selection-screen function key 1.
selection-screen begin of block b1 with frame title gv_tit01.
parameters:
p_tab type dd02l-tabname.
selection-screen end of block b1.
class lcl_data definition final.
public section.
class-data t_where_clauses type rsds_twhere.
class-methods sel_pai.
protected section.
private section.
class-methods db_sel_call.
endclass.
class lcl_data implementation.
method sel_pai.
case sy-ucomm.
when 'FC01'.
db_sel_call( ).
endcase.
endmethod.
method db_sel_call.
data: lv_selection_id type rsdynsel-selid,
lt_tables_tab type standard table of rsdstabs,
ls_tables_tab type rsdstabs.
data: lt_fields_tab type standard table of rsdsfields.
ls_tables_tab-prim_tab = p_tab. "数据库表名
append ls_tables_tab to lt_tables_tab.
call function 'FREE_SELECTIONS_INIT'
exporting
kind = 'T'
importing
selection_id = lv_selection_id
tables
tables_tab = lt_tables_tab
exceptions
fields_incomplete = 1
fields_no_join = 2
field_not_found = 3
no_tables = 4
table_not_found = 5
expression_not_supported = 6
incorrect_expression = 7
illegal_kind = 8
area_not_found = 9
inconsistent_area = 10
kind_f_no_fields_left = 11
kind_f_no_fields = 12
too_many_fields = 13
dup_field = 14
field_no_type = 15
field_ill_type = 16
dup_event_field = 17
node_not_in_ldb = 18
area_no_field = 19
others = 20.
if sy-subrc eq 0.
call function 'FREE_SELECTIONS_DIALOG'
exporting
selection_id = lv_selection_id
title = '选择'(134)
frame_text = '查询条件'(135)
as_window = 'X' "不显示成窗口
importing
where_clauses = t_where_clauses "返回选择条件
tables
fields_tab = lt_fields_tab "选择画面中选中字段
exceptions
internal_error = 1
no_action = 2
selid_not_found = 3
illegal_status = 4
others = 5.
if sy-subrc eq 0.
endif.
endif.
endmethod.
endclass.
*&---------------------------------------------------------------------*
* EVENTS BEFORE MAIN PROGRAM
*&---------------------------------------------------------------------*
initialization.
perform frm_initialization.
at selection-screen output.
perform frm_sel_pbo.
at selection-screen on value-request for p_tab.
perform frm_sel_f4.
at selection-screen on p_tab.
perform frm_sel_field_p_tab.
at selection-screen.
lcl_data=>sel_pai( ).
*&---------------------------------------------------------------------*
* MAIN PROGRAM *
*----------------------------------------------------------------------*
start-of-selection.
perform frm_data_fetch.
perform frm_data_output.
*&---------------------------------------------------------------------*
*& FORM FRM_INITIALIZATION
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& --> P1 TEXT
*& <-- P2 TEXT
*&--------------------------------