英文:
What is SAP Table lock object for and how to use it?
问题
在SAP ABAP中,一旦我们为特定表格从SE11
创建了锁定对象,是否可以在表格中创建条目?如果可以,那么锁定对象中有什么特殊之处?
我已经尝试在SE11
中创建了一个锁定对象,然后在SE37
中执行了一个锁定对象。我的问题是,一旦锁定对象被创建,我们就不应该能够添加条目,但是在这里我能够在我的表格中添加条目。锁定对象中有什么特殊之处?
英文:
Once we created a lock object for the particular table in SAP ABAP from SE11
, is it possible to create entries in the table? If yes then what is the special thing in lock object?
I have tried creating a lock object in SE11
and after that in SE37
I have executed a lock object. My question is once lock object is created then we should not able to add entries but here I am able to add entries in my table. What is the special thing in lock object?
答案1
得分: 1
锁定对象用于在程序中提供逻辑锁定功能。比如,如果两个用户不应同时编辑同一份文档,那么我们可以实现锁定对象来限制一个用户在另一个用户已经打开该文档进行编辑时无法打开它。
当在ABAP字典中定义锁定对象时,会创建两个函数模块ENQUEUE_obj_name
和DEQUEUE_obj_name
。它们可以随后在ABAP程序中分别用于锁定和解锁对象。
在锁定对象本身的“Tables”标签中,我们定义了要为其获取锁定的主要表。在“Lock parameters”标签中,我们定义了在请求期间传递给函数模块的参数,这些参数对应于充当锁定条件的表字段。
假设我们创建了一个名为EZDOC_BILLING的锁定对象,用于 Billing Document 头表 VBRK。默认情况下,锁定参数会自动填充表 MANDT 和 VBELN 的关键字段。
在锁定对象激活后,将生成函数模块ENQUEUE_EZDOC_BILLING
和DEQUEUE_EZDOC_BILLING
。
要在代码中实现它,我们使用文档号码调用锁定函数模块以设置锁定。一旦成功完成,我们可以继续进行操作,比如更改文档,而锁定确保在此期间没有其他用户可以编辑相同的文档。完成后,我们应该通过调用解锁函数模块来释放锁定。
一般来说,在编码中可能如下所示:
...
PERFORM set_lock USING l_vbeln CHANGING l_retcode.
IF l_retcode = 0.
PERFORM change_doc_billing ...
ENDIF.
PERFORM release_lock USING l_vbeln.
...
FORM set_lock USING i_vbeln CHANGING c_retcode.
CALL FUNCTION 'ENQUEUE_EZDOC_BILLING'
EXPORTING
mode_vbrk = 'E'
mandt = sy-mandt
vbeln = i_vbeln
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
c_retcode = sy-subrc.
ENDFORM.
FORM release_lock USING i_vbeln.
CALL FUNCTION 'DEQUEUE_EZDOC_BILLING'
EXPORTING
mode_vbrk = 'E'
mandt = sy-mandt
vbeln = i_vbeln
x_vbeln = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.
ENDFORM.
英文:
Lock objects are used to provide logical locking functionality in programs. Say, if two users should not edit the same document simultaneously, then we can implement lock objects to restrict one user from opening the document in case another user alredy opened it for editing.
When lock object is defined in ABAP Dictionary, two function modules ENQUEUE_obj_name
and DEQUEUE_obj_name
are created. They can be afterwards called in ABAP programs to respectively lock and unlocks the objects.
In lock object itself in Tables
tab we define the primary table which we want the lock for. In Lock parameters
tab we define the parameters which are passed to the function module during requests to set or release the lock and which correspond to table fields acting as a lock criteria condition.
Let's say we create a lock EZDOC_BILLING for a Billing Document header table VBRK. As lock parameters by default key fields of the table MANDT and VBELN are automatically populated.
Upon lock object activation function modules ENQUEUE_EZDOC_BILLING
and DEQUEUE_EZDOC_BILLING
are generated.
To implement it in the code we call the enqueue FM with a document number for which lock should be set. Once it's successfully done we can proceed with our operations like changing the document and the locking ensures that no other user can edit the same document in this time. Once we're done we should relese the lock by calling the dequeue FM.
In general it can look like this in the coding:
...
PERFORM set_lock USING l_vbeln CHANGING l_retcode.
IF l_retcode = 0.
PERFORM change_doc_billing ...
ENDIF.
PERFORM release_lock USING l_vbeln.
...
FORM set_lock USING i_vbeln CHANGING c_retcode.
CALL FUNCTION 'ENQUEUE_EZDOC_BILLING'
EXPORTING
mode_vbrk = 'E'
mandt = sy-mandt
vbeln = i_vbeln
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
c_retcode = sy-subrc.
ENDFORM.
FORM release_lock USING i_vbeln.
CALL FUNCTION 'DEQUEUE_EZDOC_BILLING'
EXPORTING
mode_vbrk = 'E'
mandt = sy-mandt
vbeln = i_vbeln
x_vbeln = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.
ENDFORM.
答案2
得分: 0
锁定机制在数据库/内核级别不起作用。因此,您需要在报告/函数/类中手动检查锁定状态。SE16/SE16N 不会检查锁定状态。此外,您可以创建一个用于修改表格而不进行锁定检查的报告。
英文:
Lock mechanism doesn't work on DB/Kernel level. So you need to manually check the lock status in your report/function/class. The SE16/SE16N doesn't check lock status. Also you can create report a report for modifying table without the lock check.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论