0

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • Lock objects are meant to be used in ABAP programs. `SE37` doesn't work for many function modules, which is the case for function modules for lock requests. Your question is more about understanding the concept, Stack Overflow is quite restrictive concerning [the way the questions can be asked](https://stackoverflow.com/help/dont-ask) here. – Sandra Rossi May 25 '23 at 12:07
  • Have a look at [The SAP Lock Concept](https://help.sap.com/docs/SAP_NETWEAVER_731_BW_ABAP/cfae740a0a21455dbe6e510c2d86e36a/417af4c5a79e11d1950f0000e82de14a.html) – peterulb May 25 '23 at 20:59

2 Answers2

1

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.
AlexSchell
  • 953
  • 1
  • 1
  • 18
0

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.

mkysoft
  • 5,392
  • 1
  • 21
  • 30