关于小量数据的维护,通常的做法是用sm30来实现。但是SM30一般项目会限制使用,而且很多功能,不是那么好实现的。
比如我手工要创建简易的交易数据,有基本业务,流水号,甚至权限和加锁等控制。对于SM30来说就不那么容易实现。
那么一般程序呢?要写创建,修改,删除,显示。四套功能的程序。对于一个大的功能,一般会这么写,还好说点。 一个小功能,也要写那么多内容,想想就不是很爽。
接上篇文章,我当时设计的这个界面,就是为了实现小功能的。 创建,修改,删除和显示。
修改和删除,例子程序中没有,copy后,自己想想怎么玩更通用呢?
report zsdr001 line-count 50 line-size 132
no standard page heading message-id 00.
*———————————————————————*
type-pools: slis.
*———————————————————————
*CS_WHERE_USED_MAT
*GET_WEEK_INFO_BASED_ON_DATE
*———————————————————————-*
* TABLES
*———————————————————————-*
tables: pbim,pbed,ztsdr001,tvkov,kna1,lfa1.
*———————————————————————-*
* Constants Declaration
*———————————————————————-*
data: ok_code like sy-ucomm.
*———————————————————————-*
* INNERE TABLE
*———————————————————————-*
data: it_ztsdr001 like ztsdr001 occurs 0 with header line.
data: wa_ztsdr001 like ztsdr001.
data: l_error type i.
data: l_message(255) type c.
*&———————————————————————*
*& DATA
*&———————————————————————*
data: g_custom_container1 type ref to cl_gui_custom_container.
data: g_container1 type scrfname value ‘ALV_GRID_0100_CONT’.
data: grid1 type ref to cl_gui_alv_grid.
* Field catalog table
data gt_fieldcat type lvc_t_fcat.
data: wa_fieldcat type lvc_s_fcat.
data gt_fieldcat1 type lvc_t_fcat.
data: gs_layout type lvc_s_layo.
data: lt_exclude type ui_functions.
data p_gt_fieldcat type lvc_t_fcat.
data: p_gs_layout type lvc_s_layo.
data: p_num like bseg-dmbtr.
*DATA: gt_fcat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
data: gt_fcat type slis_t_fieldcat_alv.
data: i_fieldcat type slis_fieldcat_alv.
data it_sort type slis_t_sortinfo_alv with header line.
data: it_events type slis_t_event,
wa_events like line of it_events.
*———————————————————————–
* Local class to dbclick
*CLASS lcl_application_dbclick DEFINITION DEFERRED.
* Local class to handle semantic checks
class lcl_event_receiver definition deferred.
*
*DATA: g_dbclick TYPE REF TO lcl_application_dbclick.
data: g_event_receiver type ref to lcl_event_receiver.
*———————————————————————
data: text(50).
************************************************************************
** LOCAL CLASSES: Definition
************************************************************************
**======================================================================
** class lcl_application_dbclick: local class to handle own dbclick.
**è?o?′¥·¢double_click
*CLASS lcl_application_dbclick DEFINITION.
* PUBLIC SECTION.
* METHODS on_double_click
* FOR EVENT double_click OF cl_gui_alv_grid
* IMPORTING E_ROW
* E_COLUMN
* ES_ROW_NO.
*endclass.
*———————————————————————–
* LOCAL CLASS Definition
*———————————————————————–
* Define event handler to handle event DATA_CHANGED
*———————————————————————–
class lcl_event_receiver definition.
public section.
methods handle_dbclick
for event double_click of cl_gui_alv_grid
importing e_row
e_column
es_row_no.
endclass. “lcl_event_receiver DEFINITION
*读历史记录,更新显示
class lcl_event_receiver implementation.
method handle_dbclick.
p_num = es_row_no-row_id.
read table it_ztsdr001 into wa_ztsdr001 index p_num.
if sy-subrc = 0.
move-corresponding wa_ztsdr001 to ztsdr001.
endif.
call method cl_gui_cfw=>set_new_ok_code
exporting
new_code = ‘ZREFRESH’.
* DATA: L_CODE TYPE I.
* CALL METHOD CL_GUI_CFW=>DISPATCH
* IMPORTING
* RETURN_CODE = L_CODE.
* CALL METHOD grid1->DISPATCH
* EXPORTING
* CARGO = sy-ucomm
* EVENTID = EVT_DBLCLICK_ROW_COL
* IS_SHELLEVENT = ‘X’
** IS_SYSTEMDISPATCH =
* EXCEPTIONS
* CNTL_ERROR = 1
* others = 2
* .
endmethod. “handle_dbclick
endclass. “lcl_event_receiver IMPLEMENTATION
*CLASS lcl_application_dbclick IMPLEMENTATION.
*endclass.
data: event_receiver type ref to lcl_event_receiver.
*&———————————————————————*
*& DATA
*&———————————————————————*
*
**———————————————————————-
**
** Selection Screen
**———————————————————————-
**
*SELECTION-SCREEN BEGIN OF BLOCK BK1 WITH FRAME TITLE T1.
*SELECT-OPTIONS: s_werks for pbim-werks NO INTERVALS
* NO-EXTENSION obligatory default ‘3030’.
*select-OPTIONS: s_matnr for pbim-matnr.
*select-options: s_DISMM for marc-dismm.
*select-options: s_MATKL for mara-matkl.
*select-options: s_PERXX for pbed-perxx NO-EXTENSION OBLIGATORY.
**parameters: p_dbzs type i default ’10’ obligatory. “对比周数
*parameters: p_check as checkbox.
*SELECTION-SCREEN END OF BLOCK BK1.
************************************************************************
* INITIALIZATION
************************************************************************
* Event which occurs before the selection screen is shown to the user
* It happens only once and is ignored in background processing
initialization.
************************************************************************
* AT SELECTION-SCREEN
************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
* PERFORM sub_find USING p_file.
*
*AT SELECTION-SCREEN.
* PERFORM sub_check.
************************************************************************
* Processing *
************************************************************************
*———————————————————————-*
* Event Occurs After The Selection Screen Has Been Processed
*———————————————————————-*
start-of-selection.
*———————————————————————-*
* The Last Of The Events Called By The Runtime Environment To Occur
*———————————————————————-*
call screen 100.
end-of-selection.
*&———————————————————————*
*& Module STATUS_0100 OUTPUT
*&———————————————————————*
* text
*———————————————————————-*
module status_0100 output.
set pf-status ‘SCREEN100’.
set titlebar ‘SCREEN100’.
loop at screen.
if screen-name(8) = ‘ZTSDR001’.
if ztsdr001-vbeln ”.
screen-input = 0.
modify screen.
clear screen.
endif.
endif.
endloop.
*从历史表里查找,该用户今天创建的所有记录。
select * into table it_ztsdr001
from ztsdr001
where cuname = sy-uname
and cdatum = sy-datum.
endmodule. ” STATUS_0100 OUTPUT
*&———————————————————————*
*& Module USER_COMMAND_0100 INPUT
*&———————————————————————*
* text
*———————————————————————-*
module user_command_0100 input.
case ok_code.
when ‘ZREFRESH’.
ztsdr001 = wa_ztsdr001.
when ‘NEW’.
clear ztsdr001.
when ‘SAVE’.
clear ok_code.
*—-生成凭证(无报错,才能执行,凭证生成!)
if l_error = 0 and ztsdr001-vbeln = ”.
*创建前加锁
* perform frm_enqueue.
perform generate_doc.
* perform frm_dequeue.
endif.
* when ‘MESSAGE’.
* perform frm_message.
when ‘BACK’.
clear ok_code.
clear ztsdr001.
clear wa_ztsdr001.
leave to screen 0.
when ‘EXIT’.
clear ok_code.
clear ztsdr001.
clear wa_ztsdr001.
leave to screen 0.
when ‘LEAVE’.
clear ok_code.
clear ztsdr001.
clear wa_ztsdr001.
leave program.
* when others.
* call method cl_gui_cfw=>get_current_event_object
* receiving
* event_object = return.
* call method cl_gui_cfw=>dispatch.
endcase.
clear ok_code.
endmodule. ” USER_COMMAND_0100 INPUT
*&———————————————————————*
*& Module data_output OUTPUT
*&———————————————————————*
* text
*———————————————————————-*
module data_output output.
refresh gt_fieldcat.
clear gt_fieldcat.
gs_layout-zebra = ‘X’.
gs_layout-cwidth_opt = ‘X’.
perform init_fcat_100.
if g_custom_container1 is initial.
create object g_custom_container1
exporting
container_name = g_container1.
create object grid1
exporting
i_parent = g_custom_container1.
endif.
call method grid1->set_table_for_first_display
exporting
it_toolbar_excluding = lt_exclude
* I_STRUCTURE_NAME = ‘ztsdr001’
is_layout = gs_layout
changing
it_fieldcatalog = gt_fieldcat[]
it_outtab = it_ztsdr001[].
call method grid1->refresh_table_display.
*创建双击事件,显示历史记录
create object: g_event_receiver.
set handler g_event_receiver->handle_dbclick for all instances.
endmodule. ” data_output OUTPUT
*&———————————————————————*
*& Form INIT_FCAT_100
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
form init_fcat_100 .
refresh gt_fcat[].
data: l_repid like sy-repid.
l_repid = sy-repid.
call function ‘REUSE_ALV_FIELDCATALOG_MERGE’
exporting
i_program_name = sy-repid
i_internal_tabname = ‘IT_ZTSDR001’
i_inclname = sy-repid
i_client_never_display = ‘X’
changing
ct_fieldcat = gt_fcat[]
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
if sy-subrc 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
loop at gt_fcat into i_fieldcat.
wa_fieldcat-fieldname = i_fieldcat-fieldname.
wa_fieldcat-scrtext_l = i_fieldcat-seltext_l.
wa_fieldcat-scrtext_m = i_fieldcat-seltext_m.
wa_fieldcat-scrtext_s = i_fieldcat-seltext_s.
wa_fieldcat-key = i_fieldcat-key.
wa_fieldcat-outputlen = i_fieldcat-outputlen.
wa_fieldcat-lzero = i_fieldcat-lzero.
wa_fieldcat-no_sign = i_fieldcat-no_sign.
wa_fieldcat-no_zero = i_fieldcat-no_zero.
* MOVE-CORRESPONDING i_fieldcat to wa_fieldcat.
append wa_fieldcat to gt_fieldcat.
clear wa_fieldcat.
endloop.
* delete gt_fieldcat where fieldname = ‘MANDT’.
* delete gt_fieldcat where fieldname = ‘WAERS’.
* delete gt_fieldcat where fieldname = ‘MEINS’.
* delete gt_fieldcat where fieldname = ‘SEL’.
endform. ” INIT_FCAT_100
*&———————————————————————*
*& Module FILL_FIELD INPUT
*&———————————————————————*
* text
*———————————————————————-*
module fill_field input.
*检查前,错误标记先清0.
l_error = 0.
ztsdr001-cuname = sy-uname.
ztsdr001-cdatum = sy-datum.
ztsdr001-cuzeit = sy-uzeit.
*销售组织不存在,请检查
if ztsdr001-vkorg = ”.
message s398(00) with ‘销售组织不能为空!’.
l_error = 1.
exit.
endif.
endmodule. ” FILL_FIELD INPUT
*&———————————————————————*
*& Form fetch_info
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* p1 text
* p1 text
** <– p2 text
**———————————————————————-
**
*form frm_enqueue .
* call function ‘ENQUEUE_EZSDTB_FLJTHZ_2’
* exporting
* mode_zsdtb_fljthz_2 = ‘E’
* mandt = sy-mandt
* vkorg = ztsdr001-vkorg
* vtweg = ztsdr001-vtweg
* spart = ztsdr001-spart
* prctr = ztsdr001-prctr
* fllx = ztsdr001-fllx
* vkbur = ztsdr001-vkbur
* kunnr = ztsdr001-kunnr
* x_vkorg = ‘ ‘
* x_vtweg = ‘ ‘
* x_spart = ‘ ‘
* x_prctr = ‘ ‘
* x_fllx = ‘ ‘
* x_vkbur = ‘ ‘
* x_kunnr = ‘ ‘
* _scope = ‘2’
* _wait = ‘ ‘
* _collect = ‘ ‘
* exceptions
* foreign_lock = 1
* system_failure = 2
* others = 3.
* if sy-subrc 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* endif.
*
*endform. ” frm_ENQUEUE
**&———————————————————————
**
**& Form frm_DEQUEUE
**&———————————————————————
**
** text
**———————————————————————-
**
** –> p1 text
** <– p2 text
**———————————————————————-
**
*form frm_dequeue .
* call function ‘DEQUEUE_EZSDTB_FLJTHZ_2’
* exporting
* mode_zsdtb_fljthz_2 = ‘E’
* mandt = sy-mandt
* vkorg = ztsdr001-vkorg
* vtweg = ztsdr001-vtweg
* spart = ztsdr001-spart
* prctr = ztsdr001-prctr
* fllx = ztsdr001-fllx
* vkbur = ztsdr001-vkbur
* kunnr = ztsdr001-kunnr
* x_vkorg = ‘ ‘
* x_vtweg = ‘ ‘
* x_spart = ‘ ‘
* x_prctr = ‘ ‘
* x_fllx = ‘ ‘
* x_vkbur = ‘ ‘
* x_kunnr = ‘ ‘
* _scope = ‘3’
* _synchron = ‘ ‘
* _collect = ‘ ‘.
* wait up to 3 seconds.
*endform. ” frm_DEQUEUE
你好