Chinaunix首页 | 论坛 | 博客
  • 博客访问: 119449
  • 博文数量: 60
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-25 18:14
个人简介

ABAP 小店http://ymhtea.taobao.com

文章分类

全部博文(60)

分类: WINDOWS

2014-03-29 18:24:42

原文地址:ABAP 加锁与解锁 作者:连老

具體操作步驟:

1. 使用TCODE: SE11,選擇最後一項[加鎖物件],輸入物件名稱(注意一定要以字母‘E’開頭,這是SAP內部規定的,如EZTESTING)

2. 輸入名稱後,按新增,進入界面後輸入要加鎖的Table名,及加鎖類型(E:專用,累計;S:共享;X:專用,不累計)。保存後,系統會自動產生兩個函數: ENQUEUE_EZTESTING(加鎖)和 DEQUEUE_EZTESTING(解鎖)。

3.然後在更改記錄前調用加鎖函數對記錄進行鎖定,在修改完成或退出修改後一定要對記錄進行解鎖。


 具體加鎖及解鎖的使用可參考以下代碼:(Table:ZTESTING,key: fieldKey)

加鎖:
form lock_record using p_key.
data: it_seqg3 type seqg3 occurs 01 with header line.
data: gname like seqg3-gname, garg like seqg3-garg.
data: begin of %ZTESTING,
mandt type ZTESTING-mandt,
fieldkey type ZTESTING-fieldkey,
end of %ZTESTING.

call 'C_ENQ_WILDCARD' id 'HEX0' field %ZTESTING.

move sy-mandt to: %ZTESTING-mandt.

if not p_key is initial.
move p_key to: %ZTESTING-fieldkey.
endif.

gname = 'ZTESTING'.
garg = %ZTESTING.

call function 'ENQUEUE_READ'
exporting
gclient = sy-mandt
gname = gname
garg = garg
tables
enq = it_seqg3.

if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

if it_seqg3 is not initial.
data:cmessage(100) type c.
concatenate p_key '正由' it_seqg3-guname '處理!' into cmessage.
condense cmessage.
message cmessage type 'E'.

else.

call function 'ENQUEUE_EZTESTING'
exporting
mode_ztesting = 'E'
mandt = sy-mandt
zfieldkey = p_key
x_zfieldkey = ' '
_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.

endif.
endform.

解鎖:
form unlock_record using p_key.
call function 'DEQUEUE_EZTESTING'
exporting
mode_ztesting = 'E'
mandt = sy-mandt
zfieldkey = p_key
x_zfieldkey = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.

endform.

阅读(1240) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~