ABAP程序锁定
除了數據庫有鎖定外,ABAP程序本身也有鎖定。
?
SAP提供了兩個函數來解決程序運行時的同步鎖定問題:ENQUEUE_ES_PROG和DEQUEUE_ES_PROG。
CALL?FUNCTION?'ENQUEUE_ES_PROG'
* EXPORTING
*?? MODE_TRDIR?????????? = 'E'
*?? NAME???????????????? =
*?? X_NAME?????????????? = ' '
*?? _SCOPE?????????????? = '2'
*?? _WAIT??????????????? = ' '
*?? _COLLECT???????????? = ' '
* EXCEPTIONS
*?? FOREIGN_LOCK???????? = 1
*?? SYSTEM_FAILURE?????? = 2
*?? OTHERS?????????????? = 3
????????? .
Prevents the parallel execution of a program.可防止程序的并行執行。
?
Description
This function creates a lock in a program that should not be processed more than once, simultaneously.該加鎖函數會在程序里創建一把鎖阻止同一時間只有一個運行。
?
The lock remains in place until either the DEQUEUE_ES_PROG function module
is called or the transaction is completed (with an implicit DEQUEUE_ALL call).
Parameters該鎖會保持直到DEQUEUE_ES_PROG函數調用,或者事務(程序)執行完畢(執行完畢后會隱式調用DEQUEUE_ALL)才會釋放
EXPORTING輸出參數
NAME?Program name to lock需上鎖的程序名
_SCOPE?Controls how the lock is passed to the update program:鎖的傳播特性??
Value Meaning
1?The lock is not passed to the update program. The lock
is removed when the transaction ends.
2?(default) The lock is passed to the update program. The update
program is responsible for removing the lock.
3?The lock is passed to the update program. The lock must
be removed in both the interactive(交互) program and in the
update program.
CALL?FUNCTION?'DEQUEUE_ES_PROG'
* EXPORTING
*?? MODE_TRDIR?????? = 'E'
*?? NAME???????????? =
*?? X_NAME?????????? = ' '
*?? _SCOPE?????????? = '3'
*?? _SYNCHRON??????? = ' '
*?? _COLLECT???????? = ' '
????????? .
該函數釋放由ENQUEUE_ES_PROG.設置的程序鎖
?
使用時需要注意下列問題:
1、??ENQUEUE_ES_PROG函數只是嘗試去鎖定,如果鎖已經被其他程序獲取,并不會阻塞,要在調用后通過sy-subrc來判斷是否獲取成功。可以在循環里通過? WAIT? UP TO xx SECONDS.??語句來等待鎖被獲取到
2、??ABAP工作臺開發程序時,不能同時編輯同一個程序,第一個打開程序的用戶會上程序鎖,程序鎖可以使用SM12來查看當前的程序鎖,如現在編輯z_jzj_program_lock程序時:
總結
- 上一篇: ABAP 程序运行锁
- 下一篇: 按实际价格重估在版本 0, 财政年度 2