sap 锁机制实现

通过对SAP锁机制的了解,相信大家都比较关心这锁机制是如何运用的,下面是周末研究的过程,现在记录下来方便大家,也方便自己了!
1) SE11 创建锁,锁对象名必须以EZ或者EY开始:
sap 锁机制实现_第1张图片
2)点击创建进入锁对象维护,并设置相关信息如下:
sap 锁机制实现_第2张图片

sap 锁机制实现_第3张图片

以上就基本设置完,下面通过编写程序测试,代码如下:

*&---------------------------------------------------------------------*
*& Report  ZTEST_LOCK
*&
*&---------------------------------------------------------------------*
*& CREATE BY   :  FLYING
*& CREATE DATE :  2009-11-14
*& DECRIPTIONS :  测试SAP的锁机制
*&---------------------------------------------------------------------*

REPORT  ztest_lock.

TABLES: sscrfields.
*----------------------------------------------------------------------*
*   define internal table
*   定义内表
*
*----------------------------------------------------------------------*
DATA: t_eban TYPE zteban OCCURS 0 WITH HEADER LINE,
w_eban LIKE t_eban.

*----------------------------------------------------------------------*
*  defin avirable
*  定义变量
*
*----------------------------------------------------------------------*
DATA: ok_code TYPE sy-ucomm,            "获得按钮功能码
save_ok TYPE sy-ucomm.                  "临时存储功能码

DATA: flag  TYPE i.                                  "用于标记处理模式是修改还是显示
*----------------------------------------------------------------------*
*  selection-screen
*  选择屏幕
*
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001.
PARAMETERS: p_banfn LIKE eban-banfn.
SELECTION-SCREEN END   OF BLOCK blk.

SELECTION-SCREEN FUNCTION KEY 1.      "添加屏幕按钮
SELECTION-SCREEN FUNCTION KEY 2.      "添加屏幕按钮

*---------------------------------------------------------------------*
*  initialization
*  初始化选择屏幕
*
*---------------------------------------------------------------------*
INITIALIZATION.
sscrfields-functxt_01 = '修改'.    "设置屏幕显示文本
sscrfields-functxt_02 = '显示'.
CLEAR flag.

*---------------------------------------------------------------------*
*  at selection-screen
*  处理选择屏幕的按钮
*
*---------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sy-ucomm.                    "选择屏幕按钮
WHEN 'FC01'.
flag = 1.
PERFORM frm_get_data.
WHEN 'FC02'.
flag = 0.
PERFORM frm_get_data.
ENDCASE.

*---------------------------------------------------------------------*
*  frm_get_data
*  根据选择条件取数据
*
*---------------------------------------------------------------------*
FORM frm_get_data.
SELECT banfn
bnfpo
matnr
ekgrp
INTO CORRESPONDING FIELDS OF TABLE t_eban
FROM eban
WHERE banfn = p_banfn.

IF t_eban[] IS INITIAL.
MESSAGE '没有可查询的数据' TYPE 'I'.
STOP.
ELSE.
IF flag = 1.
PERFORM frm_set_lock.
ENDIF.
CALL SCREEN 1001.
ENDIF.

ENDFORM.                    "frm_get_data
*---------------------------------------------------------------------*
*  frm_set_lock
*  设置锁
*
*--------------------------------------------------------------------*
FORM frm_set_lock.
CALL FUNCTION 'ENQUEUE_EZEBAN'
EXPORTING
mode_zteban = 'E'
mandt       = sy-mandt
banfn       = p_banfn.
IF sy-subrc <> 0.
STOP.
ENDIF.

ENDFORM.                    "frm_set_lock

*----------------------------------------------------------*
*  frm_delete_lock
*  删除锁
*
*----------------------------------------------------------*
FORM frm_delete_lock.
CALL FUNCTION 'DEQUEUE_EZEBAN'
EXPORTING
mode_zteban       = 'E'
mandt             = sy-mandt
banfn             = p_banfn
x_banfn           = ' '
.
ENDFORM.                    "frm_delete_lock




*&SPWIZARD: DECLARATION OF TABLECONTROL 'TAB1' ITSELF
CONTROLS: tab1 TYPE TABLEVIEW USING SCREEN 1001.

*&SPWIZARD: OUTPUT MODULE FOR TC 'TAB1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE tab1_change_tc_attr OUTPUT.
DESCRIBE TABLE t_eban LINES tab1-lines.
ENDMODULE.                    "TAB1_CHANGE_TC_ATTR OUTPUT

*&SPWIZARD: INPUT MODULE FOR TC 'TAB1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
MODULE tab1_modify INPUT.
MODIFY t_eban
INDEX tab1-current_line.
ENDMODULE.                    "TAB1_MODIFY INPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_1001 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
SET PF-STATUS 'STAT_1001'.
ENDMODULE.                 " STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_1001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
save_ok = ok_code.
CLEAR ok_code.

CASE save_ok.
WHEN 'BACK'.
perform frm_delete_lock.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
PERFORM frm_delete_lock.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.                 " USER_COMMAND_1001  INPUT
*&---------------------------------------------------------------------*
*&      Module  SET_READ_LINE  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE set_read_line OUTPUT.                       "设置表格的行项目不可编辑
IF flag = 0.
LOOP AT SCREEN.
IF screen-name = 'T_EBAN-BANFN'.
screen-input = '0'.        
ENDIF.
IF screen-name = 'T_EBAN-BNFPO'.
screen-input = '0'.
ENDIF.
IF screen-name = 'T_EBAN-MATNR'.
screen-input = '0'.
ENDIF.
IF screen-name = 'T_EBAN-EKGRP'.
screen-input = '0'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDIF.
ENDMODULE.                 " SET_READ_LINE  OUTPUT

测试效果如下所示:
sap 锁机制实现_第4张图片

sap 锁机制实现_第5张图片



sap 锁机制实现_第6张图片

你可能感兴趣的:(function,Module,command,delete,SAP,output)